Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data race when using promhttp handlers without methodor code but with WithLabelFromCtx #1317

Closed
tigrato opened this issue Jul 30, 2023 · 0 comments · Fixed by #1318
Closed

Comments

@tigrato
Copy link
Contributor

tigrato commented Jul 30, 2023

When using any promhttp handler or roundtripper instrumentation middleware, we have a data race if the metric doesn't record code nor method but uses WithLabelFromCtx.

It exists because when we don't record code or method, the labels function returns a pre-created map called emptyLabels.

// emptyLabels is a one-time allocation for non-partitioned metrics to avoid
// unnecessary allocations on each request.
var emptyLabels = prometheus.Labels{}
func labels(code, method bool, reqMethod string, status int, extraMethods ...string) prometheus.Labels {
if !(code || method) {
return emptyLabels
}

This map is later returned to collect the metrics from the context.

for label, resolve := range hOpts.extraLabelsFromCtx {
l[label] = resolve(r.Context())
}

This affects all promhttp versions

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 a pull request may close this issue.

1 participant