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

Fix data-race in metric without code and method but with WithLabelFromCtx #1318

Merged
merged 1 commit into from Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions prometheus/promhttp/instrument_server.go
Expand Up @@ -389,15 +389,12 @@ func isLabelCurried(c prometheus.Collector, label string) bool {
return true
}

// 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 {
labels := prometheus.Labels{}

if !(code || method) {
return emptyLabels
return labels
}
labels := prometheus.Labels{}

if code {
labels["code"] = sanitizeCode(status)
Expand Down
2 changes: 1 addition & 1 deletion prometheus/promhttp/instrument_server_test.go
Expand Up @@ -250,7 +250,7 @@ func TestLabels(t *testing.T) {
}{
"empty": {
varLabels: []string{},
wantLabels: emptyLabels,
wantLabels: prometheus.Labels{},
reqMethod: "GET",
respStatus: 200,
ok: true,
Expand Down