Merge pull request #14126 from ninjadq/fix_unknown_metrics

Fix: unkonw metrics issue
This commit is contained in:
Qian Deng 2021-01-29 18:59:35 +08:00 committed by GitHub
commit a211b0c9d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,11 +49,13 @@ func instrumentHandler(next http.Handler) http.Handler {
now, rc, op := time.Now(), lib.NewResponseRecorder(w), ""
ctx := context.WithValue(r.Context(), contextOpIDKey{}, &op)
next.ServeHTTP(rc, r.WithContext(ctx))
if len(op) == 0 && isChartMuseumURL(r.URL.Path) {
op = "chartmuseum"
} else {
// From swagger's perspective the operation of this legacy URL is unknown
op = "unknown"
if len(op) == 0 {
if isChartMuseumURL(r.URL.Path) {
op = "chartmuseum"
} else {
// From swagger's perspective the operation of this legacy URL is unknown
op = "unknown"
}
}
metric.TotalReqDurSummary.WithLabelValues(r.Method, op).Observe(time.Since(now).Seconds())
metric.TotalReqCnt.WithLabelValues(r.Method, strconv.Itoa(rc.StatusCode), op).Inc()