Debian Codegraph @

prometheus/testutil/promlint/promlint_test.go

raw symbols SCIP
1 // Copyright 2020 The Prometheus Authors
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package promlint_testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/
15
16 import (
17 "errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/"
18 "fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/"
19 "reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/"
20 "stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/"
21 "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/"
22
23 dtoscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/ "github.com/prometheus/client_model/goscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/"
24
25 "github.com/prometheus/client_golang/prometheus/testutil/promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/"
26 )
27
28 type testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test# struct {
29 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name. string
30 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in. string
31 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems. []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#
32 }
33
34 func TestLintNoHelpTextscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestLintNoHelpText().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
35 const msg = "no help text"
36
37 tests := []testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
38 {
39 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "no help",
40 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
41 # TYPE go_goroutines gauge
42 go_goroutines 24
43 `,
44 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
45 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "go_goroutines",
46 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: msg,
47 }},
48 },
49 {
50 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "empty help",
51 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
52 # HELP go_goroutines
53 # TYPE go_goroutines gauge
54 go_goroutines 24
55 `,
56 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
57 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "go_goroutines",
58 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: msg,
59 }},
60 },
61 {
62 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "no help and empty help",
63 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
64 # HELP go_goroutines
65 # TYPE go_goroutines gauge
66 go_goroutines 24
67 # TYPE go_threads gauge
68 go_threads 10
69 `,
70 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{
71 {
72 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "go_goroutines",
73 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: msg,
74 },
75 {
76 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "go_threads",
77 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: msg,
78 },
79 },
80 },
81 {
82 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "OK",
83 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
84 # HELP go_goroutines Number of goroutines that currently exist.
85 # TYPE go_goroutines gauge
86 go_goroutines 24
87 `,
88 },
89 }
90 runTestsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/runTests().(t, tests)
91 }
92
93 func TestLintMetricUnitsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestLintMetricUnits().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
94 tests := []struct {
95 name string
96 in string
97 problems []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#
98 }{
99 // good cases.
100 {
101 name: "amperes",
102 in: `
103 # HELP x_amperes Test metric.
104 # TYPE x_amperes untyped
105 x_amperes 10
106 `,
107 },
108 {
109 name: "bytes",
110 in: `
111 # HELP x_bytes Test metric.
112 # TYPE x_bytes untyped
113 x_bytes 10
114 `,
115 },
116 {
117 name: "grams",
118 in: `
119 # HELP x_grams Test metric.
120 # TYPE x_grams untyped
121 x_grams 10
122 `,
123 },
124 {
125 name: "celsius",
126 in: `
127 # HELP x_celsius Test metric.
128 # TYPE x_celsius untyped
129 x_celsius 10
130 `,
131 },
132 {
133 name: "meters",
134 in: `
135 # HELP x_meters Test metric.
136 # TYPE x_meters untyped
137 x_meters 10
138 `,
139 },
140 {
141 name: "metres",
142 in: `
143 # HELP x_metres Test metric.
144 # TYPE x_metres untyped
145 x_metres 10
146 `,
147 },
148 {
149 name: "moles",
150 in: `
151 # HELP x_moles Test metric.
152 # TYPE x_moles untyped
153 x_moles 10
154 `,
155 },
156 {
157 name: "seconds",
158 in: `
159 # HELP x_seconds Test metric.
160 # TYPE x_seconds untyped
161 x_seconds 10
162 `,
163 },
164 {
165 name: "joules",
166 in: `
167 # HELP x_joules Test metric.
168 # TYPE x_joules untyped
169 x_joules 10
170 `,
171 },
172 {
173 name: "kelvin",
174 in: `
175 # HELP x_kelvin Test metric.
176 # TYPE x_kelvin untyped
177 x_kelvin 10
178 `,
179 },
180 // bad cases.
181 {
182 name: "milliamperes",
183 in: `
184 # HELP x_milliamperes Test metric.
185 # TYPE x_milliamperes untyped
186 x_milliamperes 10
187 `,
188 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
189 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_milliamperes",
190 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "amperes" instead of "milliamperes"`,
191 }},
192 },
193 {
194 name: "gigabytes",
195 in: `
196 # HELP x_gigabytes Test metric.
197 # TYPE x_gigabytes untyped
198 x_gigabytes 10
199 `,
200 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
201 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_gigabytes",
202 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "bytes" instead of "gigabytes"`,
203 }},
204 },
205 {
206 name: "kilograms",
207 in: `
208 # HELP x_kilograms Test metric.
209 # TYPE x_kilograms untyped
210 x_kilograms 10
211 `,
212 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
213 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_kilograms",
214 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "grams" instead of "kilograms"`,
215 }},
216 },
217 {
218 name: "nanocelsius",
219 in: `
220 # HELP x_nanocelsius Test metric.
221 # TYPE x_nanocelsius untyped
222 x_nanocelsius 10
223 `,
224 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
225 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_nanocelsius",
226 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "celsius" instead of "nanocelsius"`,
227 }},
228 },
229 {
230 name: "kilometers",
231 in: `
232 # HELP x_kilometers Test metric.
233 # TYPE x_kilometers untyped
234 x_kilometers 10
235 `,
236 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
237 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_kilometers",
238 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "meters" instead of "kilometers"`,
239 }},
240 },
241 {
242 name: "picometers",
243 in: `
244 # HELP x_picometers Test metric.
245 # TYPE x_picometers untyped
246 x_picometers 10
247 `,
248 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
249 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_picometers",
250 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "meters" instead of "picometers"`,
251 }},
252 },
253 {
254 name: "microseconds",
255 in: `
256 # HELP x_microseconds Test metric.
257 # TYPE x_microseconds untyped
258 x_microseconds 10
259 `,
260 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
261 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_microseconds",
262 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "seconds" instead of "microseconds"`,
263 }},
264 },
265 {
266 name: "minutes",
267 in: `
268 # HELP x_minutes Test metric.
269 # TYPE x_minutes untyped
270 x_minutes 10
271 `,
272 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
273 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_minutes",
274 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "seconds" instead of "minutes"`,
275 }},
276 },
277 {
278 name: "hours",
279 in: `
280 # HELP x_hours Test metric.
281 # TYPE x_hours untyped
282 x_hours 10
283 `,
284 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
285 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_hours",
286 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "seconds" instead of "hours"`,
287 }},
288 },
289 {
290 name: "days",
291 in: `
292 # HELP x_days Test metric.
293 # TYPE x_days untyped
294 x_days 10
295 `,
296 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
297 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_days",
298 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "seconds" instead of "days"`,
299 }},
300 },
301 {
302 name: "kelvins",
303 in: `
304 # HELP x_kelvins Test metric.
305 # TYPE x_kelvins untyped
306 x_kelvins 10
307 `,
308 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
309 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_kelvins",
310 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "kelvin" instead of "kelvins"`,
311 }},
312 },
313 {
314 name: "fahrenheit",
315 in: `
316 # HELP thermometers_fahrenheit Test metric.
317 # TYPE thermometers_fahrenheit untyped
318 thermometers_fahrenheit 10
319 `,
320 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
321 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "thermometers_fahrenheit",
322 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "celsius" instead of "fahrenheit"`,
323 }},
324 },
325 {
326 name: "rankine",
327 in: `
328 # HELP thermometers_rankine Test metric.
329 # TYPE thermometers_rankine untyped
330 thermometers_rankine 10
331 `,
332 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
333 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "thermometers_rankine",
334 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "celsius" instead of "rankine"`,
335 }},
336 },
337 {
338 name: "inches",
339 in: `
340 # HELP x_inches Test metric.
341 # TYPE x_inches untyped
342 x_inches 10
343 `,
344 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
345 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_inches",
346 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "meters" instead of "inches"`,
347 }},
348 },
349 {
350 name: "yards",
351 in: `
352 # HELP x_yards Test metric.
353 # TYPE x_yards untyped
354 x_yards 10
355 `,
356 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
357 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_yards",
358 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "meters" instead of "yards"`,
359 }},
360 },
361 {
362 name: "miles",
363 in: `
364 # HELP x_miles Test metric.
365 # TYPE x_miles untyped
366 x_miles 10
367 `,
368 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
369 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_miles",
370 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "meters" instead of "miles"`,
371 }},
372 },
373 {
374 name: "bits",
375 in: `
376 # HELP x_bits Test metric.
377 # TYPE x_bits untyped
378 x_bits 10
379 `,
380 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
381 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_bits",
382 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "bytes" instead of "bits"`,
383 }},
384 },
385 {
386 name: "calories",
387 in: `
388 # HELP x_calories Test metric.
389 # TYPE x_calories untyped
390 x_calories 10
391 `,
392 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
393 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_calories",
394 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "joules" instead of "calories"`,
395 }},
396 },
397 {
398 name: "pounds",
399 in: `
400 # HELP x_pounds Test metric.
401 # TYPE x_pounds untyped
402 x_pounds 10
403 `,
404 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
405 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_pounds",
406 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "grams" instead of "pounds"`,
407 }},
408 },
409 {
410 name: "ounces",
411 in: `
412 # HELP x_ounces Test metric.
413 # TYPE x_ounces untyped
414 x_ounces 10
415 `,
416 problems: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
417 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_ounces",
418 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `use base unit "grams" instead of "ounces"`,
419 }},
420 },
421 }
422
423 for _, tt := range tests {
424 t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(tt.name, func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
425 l := promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Newscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/New().(stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 strings/NewReader().(tt.in))
426
427 problems, err := l.Lintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Linter#Lint().()
428 if err != nil {
429 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("unexpected error: %v", err)
430 }
431
432 if want, got := tt.problems, problems; !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(want, got) {
433 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("unexpected problems:\n- want: %v\n- got: %v",
434 want, got)
435 }
436 })
437 }
438 }
439
440 func TestLintCounterscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestLintCounter().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
441 tests := []testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
442 {
443 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "counter without _total suffix",
444 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
445 # HELP x_bytes Test metric.
446 # TYPE x_bytes counter
447 x_bytes 10
448 `,
449 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
450 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_bytes",
451 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `counter metrics should have "_total" suffix`,
452 }},
453 },
454 {
455 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "gauge with _total suffix",
456 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
457 # HELP x_bytes_total Test metric.
458 # TYPE x_bytes_total gauge
459 x_bytes_total 10
460 `,
461 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
462 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_bytes_total",
463 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `non-counter metrics should not have "_total" suffix`,
464 }},
465 },
466 {
467 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "counter with _total suffix",
468 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
469 # HELP x_bytes_total Test metric.
470 # TYPE x_bytes_total counter
471 x_bytes_total 10
472 `,
473 },
474 {
475 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "gauge without _total suffix",
476 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
477 # HELP x_bytes Test metric.
478 # TYPE x_bytes gauge
479 x_bytes 10
480 `,
481 },
482 {
483 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "untyped with _total suffix",
484 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
485 # HELP x_bytes_total Test metric.
486 # TYPE x_bytes_total untyped
487 x_bytes_total 10
488 `,
489 },
490 {
491 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "untyped without _total suffix",
492 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
493 # HELP x_bytes Test metric.
494 # TYPE x_bytes untyped
495 x_bytes 10
496 `,
497 },
498 }
499
500 runTestsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/runTests().(t, tests)
501 }
502
503 func TestLintHistogramSummaryReservedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestLintHistogramSummaryReserved().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
504 tests := []testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
505 {
506 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "gauge with _bucket suffix",
507 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
508 # HELP x_bytes_bucket Test metric.
509 # TYPE x_bytes_bucket gauge
510 x_bytes_bucket 10
511 `,
512 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
513 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_bytes_bucket",
514 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `non-histogram metrics should not have "_bucket" suffix`,
515 }},
516 },
517 {
518 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "gauge with _count suffix",
519 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
520 # HELP x_bytes_count Test metric.
521 # TYPE x_bytes_count gauge
522 x_bytes_count 10
523 `,
524 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
525 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_bytes_count",
526 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `non-histogram and non-summary metrics should not have "_count" suffix`,
527 }},
528 },
529 {
530 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "gauge with _sum suffix",
531 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
532 # HELP x_bytes_sum Test metric.
533 # TYPE x_bytes_sum gauge
534 x_bytes_sum 10
535 `,
536 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
537 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_bytes_sum",
538 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `non-histogram and non-summary metrics should not have "_sum" suffix`,
539 }},
540 },
541 {
542 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "gauge with le label",
543 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
544 # HELP x_bytes Test metric.
545 # TYPE x_bytes gauge
546 x_bytes{le="1"} 10
547 `,
548 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
549 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_bytes",
550 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `non-histogram metrics should not have "le" label`,
551 }},
552 },
553 {
554 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "gauge with quantile label",
555 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
556 # HELP x_bytes Test metric.
557 # TYPE x_bytes gauge
558 x_bytes{quantile="1"} 10
559 `,
560 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
561 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "x_bytes",
562 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `non-summary metrics should not have "quantile" label`,
563 }},
564 },
565 {
566 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "histogram with quantile label",
567 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
568 # HELP tsdb_compaction_duration Duration of compaction runs.
569 # TYPE tsdb_compaction_duration histogram
570 tsdb_compaction_duration_bucket{le="0.005",quantile="0.01"} 0
571 tsdb_compaction_duration_bucket{le="0.01",quantile="0.01"} 0
572 tsdb_compaction_duration_bucket{le="0.025",quantile="0.01"} 0
573 tsdb_compaction_duration_bucket{le="0.05",quantile="0.01"} 0
574 tsdb_compaction_duration_bucket{le="0.1",quantile="0.01"} 0
575 tsdb_compaction_duration_bucket{le="0.25",quantile="0.01"} 0
576 tsdb_compaction_duration_bucket{le="0.5",quantile="0.01"} 57
577 tsdb_compaction_duration_bucket{le="1",quantile="0.01"} 68
578 tsdb_compaction_duration_bucket{le="2.5",quantile="0.01"} 69
579 tsdb_compaction_duration_bucket{le="5",quantile="0.01"} 69
580 tsdb_compaction_duration_bucket{le="10",quantile="0.01"} 69
581 tsdb_compaction_duration_bucket{le="+Inf",quantile="0.01"} 69
582 tsdb_compaction_duration_sum 28.740810936000006
583 tsdb_compaction_duration_count 69
584 `,
585 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
586 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "tsdb_compaction_duration",
587 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `non-summary metrics should not have "quantile" label`,
588 }},
589 },
590 {
591 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "summary with le label",
592 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
593 # HELP go_gc_duration_seconds A summary of the GC invocation durations.
594 # TYPE go_gc_duration_seconds summary
595 go_gc_duration_seconds{quantile="0",le="0.01"} 4.2365e-05
596 go_gc_duration_seconds{quantile="0.25",le="0.01"} 8.1492e-05
597 go_gc_duration_seconds{quantile="0.5",le="0.01"} 0.000100656
598 go_gc_duration_seconds{quantile="0.75",le="0.01"} 0.000113913
599 go_gc_duration_seconds{quantile="1",le="0.01"} 0.021754305
600 go_gc_duration_seconds_sum 1.769429004
601 go_gc_duration_seconds_count 5962
602 `,
603 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{{
604 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "go_gc_duration_seconds",
605 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `non-histogram metrics should not have "le" label`,
606 }},
607 },
608 {
609 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "histogram OK",
610 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
611 # HELP tsdb_compaction_duration Duration of compaction runs.
612 # TYPE tsdb_compaction_duration histogram
613 tsdb_compaction_duration_bucket{le="0.005"} 0
614 tsdb_compaction_duration_bucket{le="0.01"} 0
615 tsdb_compaction_duration_bucket{le="0.025"} 0
616 tsdb_compaction_duration_bucket{le="0.05"} 0
617 tsdb_compaction_duration_bucket{le="0.1"} 0
618 tsdb_compaction_duration_bucket{le="0.25"} 0
619 tsdb_compaction_duration_bucket{le="0.5"} 57
620 tsdb_compaction_duration_bucket{le="1"} 68
621 tsdb_compaction_duration_bucket{le="2.5"} 69
622 tsdb_compaction_duration_bucket{le="5"} 69
623 tsdb_compaction_duration_bucket{le="10"} 69
624 tsdb_compaction_duration_bucket{le="+Inf"} 69
625 tsdb_compaction_duration_sum 28.740810936000006
626 tsdb_compaction_duration_count 69
627 `,
628 },
629 {
630 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "summary OK",
631 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
632 # HELP go_gc_duration_seconds A summary of the GC invocation durations.
633 # TYPE go_gc_duration_seconds summary
634 go_gc_duration_seconds{quantile="0"} 4.2365e-05
635 go_gc_duration_seconds{quantile="0.25"} 8.1492e-05
636 go_gc_duration_seconds{quantile="0.5"} 0.000100656
637 go_gc_duration_seconds{quantile="0.75"} 0.000113913
638 go_gc_duration_seconds{quantile="1"} 0.021754305
639 go_gc_duration_seconds_sum 1.769429004
640 go_gc_duration_seconds_count 5962
641 `,
642 },
643 }
644 runTestsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/runTests().(t, tests)
645 }
646
647 func TestLintMetricTypeInNamescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestLintMetricTypeInName().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
648 genTest := func(n, t, err string, problems ...promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#) testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test# {
649 return testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
650 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("%s with _%s suffix", t, t),
651 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().(`
652 # HELP %s Test metric.
653 # TYPE %s %s
654 %s 10
655 `, n, n, t, n),
656 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: append(problems, promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{
657 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: n,
658 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().(`metric name should not include type '%s'`, err),
659 }),
660 }
661 }
662
663 twoProbTest := genTest("http_requests_counter", "counter", "counter", promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{
664 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "http_requests_counter",
665 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: `counter metrics should have "_total" suffix`,
666 })
667
668 tests := []testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
669 twoProbTest,
670 genTest("instance_memory_limit_bytes_gauge", "gauge", "gauge"),
671 genTest("request_duration_seconds_summary", "summary", "summary"),
672 genTest("request_duration_seconds_histogram", "histogram", "histogram"),
673 genTest("request_duration_seconds_HISTOGRAM", "histogram", "histogram"),
674
675 genTest("instance_memory_limit_gauge_bytes", "gauge", "gauge"),
676 }
677 runTestsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/runTests().(t, tests)
678 }
679
680 func TestLintReservedCharsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestLintReservedChars().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
681 tests := []testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
682 {
683 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "request_duration::_seconds",
684 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
685 # HELP request_duration::_seconds Test metric.
686 # TYPE request_duration::_seconds histogram
687 request_duration::_seconds 10
688 `,
689 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{
690 {
691 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "request_duration::_seconds",
692 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: "metric names should not contain ':'",
693 },
694 },
695 },
696 }
697 runTestsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/runTests().(t, tests)
698 }
699
700 func TestLintCamelCasescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestLintCamelCase().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
701 tests := []testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
702 {
703 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "requestDuration_seconds",
704 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
705 # HELP requestDuration_seconds Test metric.
706 # TYPE requestDuration_seconds histogram
707 requestDuration_seconds 10
708 `,
709 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{
710 {
711 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "requestDuration_seconds",
712 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: "metric names should be written in 'snake_case' not 'camelCase'",
713 },
714 },
715 },
716 {
717 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "request_duration_seconds",
718 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
719 # HELP request_duration_seconds Test metric.
720 # TYPE request_duration_seconds histogram
721 request_duration_seconds{httpService="foo"} 10
722 `,
723 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{
724 {
725 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "request_duration_seconds",
726 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: "label names should be written in 'snake_case' not 'camelCase'",
727 },
728 },
729 },
730 }
731 runTestsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/runTests().(t, tests)
732 }
733
734 func TestLintUnitAbbreviationsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestLintUnitAbbreviations().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
735 genTest := func(n string) testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test# {
736 return testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
737 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: n + " with abbreviated unit",
738 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().(`
739 # HELP %s Test metric.
740 # TYPE %s gauge
741 %s 10
742 `, n, n, n),
743 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{
744 {
745 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: n,
746 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: "metric names should not contain abbreviated units",
747 },
748 },
749 }
750 }
751 tests := []testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
752 genTest("instance_memory_limit_b"),
753 genTest("instance_memory_limit_kb"),
754 genTest("instance_memory_limit_mb"),
755 genTest("instance_memory_limit_MB"),
756 genTest("instance_memory_limit_gb"),
757 genTest("instance_memory_limit_tb"),
758 genTest("instance_memory_limit_pb"),
759
760 genTest("request_duration_s"),
761 genTest("request_duration_ms"),
762 genTest("request_duration_us"),
763 genTest("request_duration_ns"),
764 genTest("request_duration_sec"),
765 genTest("request_sec_duration"),
766 genTest("request_duration_m"),
767 genTest("request_duration_h"),
768 genTest("request_duration_d"),
769 }
770 runTestsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/runTests().(t, tests)
771 }
772
773 func runTestsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/runTests().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#, tests []testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#) {
774 t.Helperscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Helper().()
775 for _, tt := range tests {
776 t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(tt.namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name., func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
777 l := promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Newscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/New().(stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 strings/NewReader().(tt.inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.))
778
779 problems, err := l.Lintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Linter#Lint().()
780 if err != nil {
781 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("unexpected error: %v", err)
782 }
783
784 if want, got := tt.problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems., problems; !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(want, got) {
785 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("unexpected problems:\n- want: %v\n- got: %v",
786 want, got)
787 }
788 })
789 }
790 }
791
792 func TestCustomValidationsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestCustomValidations().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
793 lintAndVerify := func(l *promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Linterscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Linter#, cv testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#) {
794 problems, err := l.Lintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Linter#Lint().()
795 if err != nil {
796 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("unexpected error: %v", err)
797 }
798
799 if want, got := cv.problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems., problems; !reflectscip-go gomod github.com/golang/go/src go1.23.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.23.0 reflect/DeepEqual().(want, got) {
800 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("unexpected problems:\n- want: %v\n- got: %v",
801 want, got)
802 }
803 }
804
805 prob := []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{
806 {
807 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "mc_something_total",
808 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: "expected metric name to start with 'memcached_'",
809 },
810 }
811
812 cv := testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
813 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "metric without necessary prefix",
814 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
815 # HELP mc_something_total Test metric.
816 # TYPE mc_something_total counter
817 mc_something_total 10
818 `,
819 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: nil,
820 }
821
822 prefixValidation := func(mf *dtoscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/.MetricFamilyscip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/MetricFamily#) []error {
823 if !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.23.0 strings/HasPrefix().(mf.GetNamescip-go gomod github.com/prometheus/client_model v0.6.2 `github.com/prometheus/client_model/go`/MetricFamily#GetName().(), "memcached_") {
824 return []error{errorsscip-go gomod github.com/golang/go/src go1.23.0 errors/.Newscip-go gomod github.com/golang/go/src go1.23.0 errors/New().("expected metric name to start with 'memcached_'")}
825 }
826 return nil
827 }
828
829 t.Helperscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Helper().()
830 t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(cv.namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name., func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
831 // no problems
832 l1 := promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Newscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/New().(stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 strings/NewReader().(cv.inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.))
833 lintAndVerify(l1, cv)
834 })
835 t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(cv.namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name., func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
836 // prefix problems
837 l2 := promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Newscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/New().(stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.23.0 strings/NewReader().(cv.inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.))
838 l2.AddCustomValidationsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Linter#AddCustomValidations().(prefixValidation)
839 cv.problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems. = prob
840 lintAndVerify(l2, cv)
841 })
842 }
843
844 func TestLintDuplicateMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/TestLintDuplicateMetric().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
845 const msg = "metric not unique"
846
847 tests := []testscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#{
848 {
849 namescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#name.: "metric not unique",
850 inscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#in.: `
851 # HELP not_unique_total the helptext
852 # TYPE not_unique_total counter
853 not_unique_total{bar="abc", spam="xyz"} 1
854 not_unique_total{bar="abc", spam="xyz"} 2
855 `,
856 problemsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/test#problems.: []promlintscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/.Problemscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#{
857 {
858 Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Metric.: "not_unique_total",
859 Textscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint`/Problem#Text.: msg,
860 },
861 },
862 },
863 }
864
865 runTestsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/testutil/promlint_test`/runTests().(t, tests)
866 }