fix: TTFB prometheus metrics calculation (#11082)

until now metrics was reporting entire call
duration instead of ttfb's this PR fixes it
master
Harshavardhana 4 years ago committed by GitHub
parent 14792cdbc6
commit 3a0082f0f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      cmd/handler-utils.go
  2. 6
      cmd/http-stats.go

@ -29,7 +29,6 @@ import (
"net/url" "net/url"
"regexp" "regexp"
"strings" "strings"
"time"
xhttp "github.com/minio/minio/cmd/http" xhttp "github.com/minio/minio/cmd/http"
"github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/logger"
@ -379,12 +378,7 @@ func collectAPIStats(api string, f http.HandlerFunc) http.HandlerFunc {
f.ServeHTTP(statsWriter, r) f.ServeHTTP(statsWriter, r)
// Time duration in secs since the call started. globalHTTPStats.updateStats(api, r, statsWriter)
// We don't need to do nanosecond precision in this
// simply for the fact that it is not human readable.
durationSecs := time.Since(statsWriter.StartTime).Seconds()
globalHTTPStats.updateStats(api, r, statsWriter, durationSecs)
} }
} }

@ -161,7 +161,7 @@ func (st *HTTPStats) toServerHTTPStats() ServerHTTPStats {
} }
// Update statistics from http request and response data // Update statistics from http request and response data
func (st *HTTPStats) updateStats(api string, r *http.Request, w *logger.ResponseWriter, durationSecs float64) { func (st *HTTPStats) updateStats(api string, r *http.Request, w *logger.ResponseWriter) {
// A successful request has a 2xx response code // A successful request has a 2xx response code
successReq := (w.StatusCode >= 200 && w.StatusCode < 300) successReq := (w.StatusCode >= 200 && w.StatusCode < 300)
@ -172,10 +172,8 @@ func (st *HTTPStats) updateStats(api string, r *http.Request, w *logger.Response
} }
} }
if r.Method == http.MethodGet {
// Increment the prometheus http request response histogram with appropriate label // Increment the prometheus http request response histogram with appropriate label
httpRequestsDuration.With(prometheus.Labels{"api": api}).Observe(durationSecs) httpRequestsDuration.With(prometheus.Labels{"api": api}).Observe(w.TimeToFirstByte.Seconds())
}
} }
// Prepare new HTTPStats structure // Prepare new HTTPStats structure

Loading…
Cancel
Save