mirror of
https://github.com/goharbor/harbor
synced 2025-04-22 04:35:11 +00:00
Merge pull request #13452 from ninjadq/fix_status_code_issue_on_metrics
Fix status code in metrics issue
This commit is contained in:
commit
3536a5dfac
@ -6,23 +6,22 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/core/config"
|
"github.com/goharbor/harbor/src/core/config"
|
||||||
|
"github.com/goharbor/harbor/src/lib"
|
||||||
"github.com/goharbor/harbor/src/lib/metric"
|
"github.com/goharbor/harbor/src/lib/metric"
|
||||||
)
|
)
|
||||||
|
|
||||||
func instrumentHandler(next http.Handler) http.Handler {
|
func instrumentHandler(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
now, url, code := time.Now(), r.URL.EscapedPath(), "0"
|
now, url := time.Now(), r.URL.EscapedPath()
|
||||||
|
|
||||||
metric.TotalInFlightGauge.WithLabelValues(url).Inc()
|
metric.TotalInFlightGauge.WithLabelValues(url).Inc()
|
||||||
defer metric.TotalInFlightGauge.WithLabelValues(url).Dec()
|
defer metric.TotalInFlightGauge.WithLabelValues(url).Dec()
|
||||||
|
rc := lib.NewResponseRecorder(w)
|
||||||
|
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(rc, r)
|
||||||
if r.Response != nil {
|
|
||||||
code = strconv.Itoa(r.Response.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
metric.TotalReqDurSummary.WithLabelValues(r.Method, url).Observe(time.Since(now).Seconds())
|
metric.TotalReqDurSummary.WithLabelValues(r.Method, url).Observe(time.Since(now).Seconds())
|
||||||
metric.TotalReqCnt.WithLabelValues(r.Method, code, url).Inc()
|
metric.TotalReqCnt.WithLabelValues(r.Method, strconv.Itoa(rc.StatusCode), url).Inc()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user