Commit c7c7509
testutil compareMetricFamilies: make less error-prone (prometheus#1424)
* testutil compareMetricFamilies: make less error-prone
The functions `GatherAndCompare`, `ScrapeAndCompare` and others that use
`compareMetricFamilies` under the hood can return no error if
`metricNames` includes none of the names found in the scraped/gathered
results. To avoid false Positves (an error being the negative case), we
can return an error if there is is at least one name in `metricNames`
that is not in the filtered results.
Fixes: prometheus#1351
Signed-off-by: leonnicolas <leonloechner@gmx.de>
* Add missing metricNames to error
In to see which metric names are missing, we can add them to the error
message.
Signed-off-by: leonnicolas <leonloechner@gmx.de>
* Apply suggestions from code review
- remove if nil check
- use two nested loops instead of map
- use new function `hasMetricByName` for readability
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: leonnicolas <60091705+leonnicolas@users.noreply.github.com>
* prometheus/testutil/testutil_test.go: compare complete error
Before we would only compare the error prefix in `TestScrapeAndCompare`.
Signed-off-by: leonnicolas <leonloechner@gmx.de>
---------
Signed-off-by: leonnicolas <leonloechner@gmx.de>
Signed-off-by: leonnicolas <60091705+leonnicolas@users.noreply.github.com>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>1 parent 36b9f46 commit c7c7509
2 files changed
+108
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
280 | 289 | | |
281 | 290 | | |
282 | 291 | | |
| |||
318 | 327 | | |
319 | 328 | | |
320 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
331 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
332 | 339 | | |
333 | 340 | | |
334 | 341 | | |
335 | 342 | | |
336 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
337 | 350 | | |
338 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
339 | 359 | | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
| 360 | + | |
344 | 361 | | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
| 362 | + | |
| 363 | + | |
349 | 364 | | |
350 | | - | |
351 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
352 | 371 | | |
353 | 372 | | |
354 | 373 | | |
| |||
358 | 377 | | |
359 | 378 | | |
360 | 379 | | |
361 | | - | |
362 | | - | |
363 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
364 | 388 | | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
| 389 | + | |
369 | 390 | | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
| 391 | + | |
| 392 | + | |
374 | 393 | | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
379 | 399 | | |
380 | | - | |
381 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
382 | 416 | | |
383 | | - | |
384 | 417 | | |
385 | | - | |
386 | | - | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
387 | 430 | | |
388 | 431 | | |
389 | 432 | | |
390 | 433 | | |
391 | 434 | | |
392 | 435 | | |
393 | | - | |
| 436 | + | |
394 | 437 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
400 | 443 | | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
408 | 452 | | |
409 | 453 | | |
410 | 454 | | |
| |||
0 commit comments