mirror of
https://github.com/goharbor/harbor.git
synced 2024-09-29 13:57:33 +02:00
Merge pull request #13652 from ninjadq/fix_metric_inc_with_huge_num
Fix instrumenting handler nest issue
This commit is contained in:
commit
688dc3af70
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user