mirror of https://github.com/prometheus/prometheus
web: deduplicate handler label for HTTP metrics (#4752)
* web: deduplicate handler label for HTTP metrics Signed-off-by: Simon Pasquier <spasquie@redhat.com> * remove instrumentHandlerFunc Signed-off-by: Simon Pasquier <spasquie@redhat.com>pull/4941/head
parent
61cf4365d6
commit
632626b553
|
@ -191,6 +191,12 @@ type Options struct {
|
||||||
RemoteReadConcurrencyLimit int
|
RemoteReadConcurrencyLimit int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func instrumentHandlerWithPrefix(prefix string) func(handlerName string, handler http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return func(handlerName string, handler http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return instrumentHandler(prefix+handlerName, handler)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func instrumentHandler(handlerName string, handler http.HandlerFunc) http.HandlerFunc {
|
func instrumentHandler(handlerName string, handler http.HandlerFunc) http.HandlerFunc {
|
||||||
return promhttp.InstrumentHandlerDuration(
|
return promhttp.InstrumentHandlerDuration(
|
||||||
requestDuration.MustCurryWith(prometheus.Labels{"handler": handlerName}),
|
requestDuration.MustCurryWith(prometheus.Labels{"handler": handlerName}),
|
||||||
|
@ -459,7 +465,7 @@ func (h *Handler) Run(ctx context.Context) error {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/", h.router)
|
mux.Handle("/", h.router)
|
||||||
|
|
||||||
av1 := route.New().WithInstrumentation(instrumentHandler)
|
av1 := route.New().WithInstrumentation(instrumentHandlerWithPrefix("/api/v1"))
|
||||||
h.apiV1.Register(av1)
|
h.apiV1.Register(av1)
|
||||||
apiPath := "/api"
|
apiPath := "/api"
|
||||||
if h.options.RoutePrefix != "/" {
|
if h.options.RoutePrefix != "/" {
|
||||||
|
|
Loading…
Reference in New Issue