Commit 7f85956
* promhttp: add regression test for concurrent map writes (#1274)
Without the fix in #1318, instrumenting a metric vec partitioned only by
labels supplied via WithLabelFromCtx (i.e. with no "code" or "method"
label) would cause concurrent requests to share and mutate a single
'emptyLabels' map, producing 'fatal error: concurrent map writes' under
load. The fix made labels() allocate a fresh map per call but no
regression test was added at the time.
This adds a test that exercises both InstrumentHandlerCounter and
InstrumentHandlerDuration from many goroutines so the bug would be
caught either by the race detector or the runtime's concurrent-map-
writes detection.
Verified: the test fails (DATA RACE / concurrent map writes panic) when
the pre-#1318 labels() implementation is reintroduced, and passes on
current main with 'go test -race'.
Closes #1274
Signed-off-by: Pedram <pedram@arpdigital.io>
* Update prometheus/promhttp/instrument_server_test.go
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
Signed-off-by: Pedram Pd <eragon.pedy@gmail.com>
---------
Signed-off-by: Pedram <pedram@arpdigital.io>
Signed-off-by: Pedram Pd <eragon.pedy@gmail.com>
Co-authored-by: Pedram <pedram@arpdigital.io>
Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
1 parent 6dd4625 commit 7f85956
1 file changed
Lines changed: 55 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
523 | 524 | | |
524 | 525 | | |
525 | 526 | | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
526 | 581 | | |
527 | 582 | | |
528 | 583 | | |
| |||
0 commit comments