avoid increasing the coordinates of metric labels (#3785)

This commit is contained in:
Konstantin Lebedev 2022-10-04 13:20:01 +05:00 committed by GitHub
parent 18d92dbd45
commit ec46a34f33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,6 +33,12 @@ func track(f http.HandlerFunc, action string) http.HandlerFunc {
recorder := NewStatusResponseWriter(w)
start := time.Now()
f(recorder, r)
if recorder.Status == http.StatusForbidden {
if m, _ := stats_collect.S3RequestCounter.GetMetricWithLabelValues(
action, strconv.Itoa(http.StatusOK), bucket); m == nil {
bucket = ""
}
}
stats_collect.S3RequestHistogram.WithLabelValues(action, bucket).Observe(time.Since(start).Seconds())
stats_collect.S3RequestCounter.WithLabelValues(action, strconv.Itoa(recorder.Status), bucket).Inc()
}