Skip to content

fix(prometheus): stabilize label maps in MetricVec.GetMetricWith#2024

Closed
immanuwell wants to merge 1 commit into
prometheus:mainfrom
immanuwell:fix-metricvec-getmetricwith-label-stability
Closed

fix(prometheus): stabilize label maps in MetricVec.GetMetricWith#2024
immanuwell wants to merge 1 commit into
prometheus:mainfrom
immanuwell:fix-metricvec-getmetricwith-label-stability

Conversation

@immanuwell

Copy link
Copy Markdown
Contributor

fixes #1951

cc @vesari

GetMetricWith(Labels) could hash one label set, then store another if the same map gets mutated while the metric is being created. that can bubble up as collected before with the same name and label values, kind of nasty.

This stabilizes the map input first, then reuses the label values path. WithLabelValues(...) stays as is.

Repro:

  1. check out the parent of this commit
  2. run go test ./prometheus -run TestMetricVecWithLabelsKeepsLabelValuesStable -count=1
  3. it fails with collected metric "test" ... was collected before with the same name and label values
  4. run the same command on this branch
  5. it passes

Checks:

  • go test ./...
  • cd exp && go test ./...
  • go test -race ./prometheus -run 'TestMetricVecWithLabelsKeepsLabelValuesStable|TestMetricVecWithConstraints|TestCurryVec|TestCurryVecWithConstraints|TestDelete|TestDeleteLabelValues|TestDeletePartialMatch' -count=1

Signed-off-by: immanuwell <pchpr.00@list.ru>
@immanuwell immanuwell force-pushed the fix-metricvec-getmetricwith-label-stability branch from 341c274 to 12770f7 Compare June 21, 2026 17:13
@bwplotka

bwplotka commented Jun 22, 2026

Copy link
Copy Markdown
Member

Thanks but we prefer performance vs making it ultra safe for all cases. However some commentary would be useful. See #1951 (comment)

Feel free to push back, we can always reopen 🤗

@bwplotka bwplotka closed this Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: metrics with no label constraint are exposed to potential race conditions

2 participants