Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions server/http_instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"maps"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -30,10 +31,10 @@ func (m httpMetricsCollector) initializeMetrics(labels prometheus.Labels) {
}
}

m.requestCounter.MustCurryWith(labels).WithLabelValues("", "", "")
m.requestSize.MustCurryWith(labels).WithLabelValues("", "", "")
m.requestDuration.MustCurryWith(labels).WithLabelValues("", "", "")
m.responseSize.MustCurryWith(labels).WithLabelValues("", "", "")
m.requestCounter.MustCurryWith(labels)
m.requestSize.MustCurryWith(labels)
m.requestDuration.MustCurryWith(labels)
m.responseSize.MustCurryWith(labels)
}

// newHTTPMetricsCollector creates a new httpMetricsCollector.
Expand Down Expand Up @@ -93,9 +94,7 @@ func (m instrumentedHandlerFactory) NewHandler(extraLabels prometheus.Labels, ne

return func(w http.ResponseWriter, r *http.Request) {
requestLabels := make(prometheus.Labels, len(extraLabels))
for k, v := range extraLabels {
requestLabels[k] = v
}
maps.Copy(requestLabels, extraLabels)

r = r.WithContext(context.WithValue(r.Context(), ExtraLabelContextKey, requestLabels))

Expand All @@ -107,9 +106,7 @@ func (m instrumentedHandlerFactory) NewHandler(extraLabels prometheus.Labels, ne
// if different extra labels come back through the context after serving the request, merge them.
if labels := r.Context().Value(ExtraLabelContextKey); labels != nil {
ctxLabels := labels.(prometheus.Labels)
for k, v := range ctxLabels {
requestLabels[k] = v
}
maps.Copy(requestLabels, ctxLabels)
}

tenant, _ := authentication.GetTenantID(r.Context())
Expand Down Expand Up @@ -155,9 +152,7 @@ func InjectLabelsCtx(labels prometheus.Labels, handler http.Handler) http.Handle
extraLabels = prometheus.Labels{}
}
if extraLabels != nil {
for k, v := range labels {
extraLabels[k] = v
}
maps.Copy(extraLabels, labels)
r = r.WithContext(context.WithValue(r.Context(), ExtraLabelContextKey, extraLabels))
}
handler.ServeHTTP(w, r)
Expand Down