From 632626b553c480ad79495bcb4460972efcebbdd3 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Fri, 30 Nov 2018 13:30:32 +0100 Subject: [PATCH] web: deduplicate handler label for HTTP metrics (#4752) * web: deduplicate handler label for HTTP metrics Signed-off-by: Simon Pasquier * remove instrumentHandlerFunc Signed-off-by: Simon Pasquier --- web/web.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/web.go b/web/web.go index f4336cfb2..1945051a0 100644 --- a/web/web.go +++ b/web/web.go @@ -191,6 +191,12 @@ type Options struct { 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 { return promhttp.InstrumentHandlerDuration( requestDuration.MustCurryWith(prometheus.Labels{"handler": handlerName}), @@ -459,7 +465,7 @@ func (h *Handler) Run(ctx context.Context) error { mux := http.NewServeMux() mux.Handle("/", h.router) - av1 := route.New().WithInstrumentation(instrumentHandler) + av1 := route.New().WithInstrumentation(instrumentHandlerWithPrefix("/api/v1")) h.apiV1.Register(av1) apiPath := "/api" if h.options.RoutePrefix != "/" {