Fix instrumenting handler nest issue

remove nested handler for instrumenting

Signed-off-by: DQ <dengq@vmware.com>
This commit is contained in:
DQ 2020-12-01 17:12:19 +08:00
parent f24d349ede
commit 72ff33f80b

View File

@ -17,9 +17,7 @@ func instrumentHandler(next http.Handler) http.Handler {
metric.TotalInFlightGauge.WithLabelValues(url).Inc()
defer metric.TotalInFlightGauge.WithLabelValues(url).Dec()
rc := lib.NewResponseRecorder(w)
next.ServeHTTP(rc, r)
metric.TotalReqDurSummary.WithLabelValues(r.Method, url).Observe(time.Since(now).Seconds())
metric.TotalReqCnt.WithLabelValues(r.Method, strconv.Itoa(rc.StatusCode), url).Inc()
})
@ -28,12 +26,7 @@ func instrumentHandler(next http.Handler) http.Handler {
// Middleware returns a middleware for handling requests
func Middleware() func(http.Handler) http.Handler {
if config.Metric().Enabled {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
next = instrumentHandler(next)
next.ServeHTTP(rw, req)
})
}
return instrumentHandler
}
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {