From 5fddd26069235337c92a7620c6b2dd478596b652 Mon Sep 17 00:00:00 2001 From: Ming Deng Date: Sat, 26 Dec 2020 21:54:57 +0800 Subject: [PATCH] Remove duration from prometheus label --- metric/prometheus.go | 4 ++-- metric/prometheus_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/metric/prometheus.go b/metric/prometheus.go index 86e2c1b1..fac50f87 100644 --- a/metric/prometheus.go +++ b/metric/prometheus.go @@ -37,7 +37,7 @@ func PrometheusMiddleWare(next http.Handler) http.Handler { "appname": beego.BConfig.AppName, }, Help: "The statics info for http request", - }, []string{"pattern", "method", "status", "duration"}) + }, []string{"pattern", "method", "status"}) prometheus.MustRegister(summaryVec) @@ -95,5 +95,5 @@ func report(dur time.Duration, writer http.ResponseWriter, q *http.Request, vec logs.Warn("we can not find the router info for this request, so request will be recorded as UNKNOWN: " + q.URL.String()) } ms := dur / time.Millisecond - vec.WithLabelValues(ptn, q.Method, strconv.Itoa(status), strconv.Itoa(int(ms))).Observe(float64(ms)) + vec.WithLabelValues(ptn, q.Method, strconv.Itoa(status)).Observe(float64(ms)) } diff --git a/metric/prometheus_test.go b/metric/prometheus_test.go index d82a6dec..fd722245 100644 --- a/metric/prometheus_test.go +++ b/metric/prometheus_test.go @@ -35,7 +35,7 @@ func TestPrometheusMiddleWare(t *testing.T) { }, Method: "POST", } - vec := prometheus.NewSummaryVec(prometheus.SummaryOpts{}, []string{"pattern", "method", "status", "duration"}) + vec := prometheus.NewSummaryVec(prometheus.SummaryOpts{}, []string{"pattern", "method", "status"}) report(time.Second, writer, request, vec) middleware.ServeHTTP(writer, request)