chore: add status code for request_total metrics (#5188)

This commit is contained in:
Konstantin Lebedev
2024-01-10 23:05:27 +05:00
committed by GitHub
parent fe417ee02d
commit a7fc723ae0
16 changed files with 101 additions and 66 deletions

View File

@@ -8,29 +8,11 @@ import (
"time"
)
type StatusRecorder struct {
http.ResponseWriter
Status int
}
func NewStatusResponseWriter(w http.ResponseWriter) *StatusRecorder {
return &StatusRecorder{w, http.StatusOK}
}
func (r *StatusRecorder) WriteHeader(status int) {
r.Status = status
r.ResponseWriter.WriteHeader(status)
}
func (r *StatusRecorder) Flush() {
r.ResponseWriter.(http.Flusher).Flush()
}
func track(f http.HandlerFunc, action string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
bucket, _ := s3_constants.GetBucketAndObject(r)
w.Header().Set("Server", "SeaweedFS S3")
recorder := NewStatusResponseWriter(w)
recorder := stats_collect.NewStatusResponseWriter(w)
start := time.Now()
f(recorder, r)
if recorder.Status == http.StatusForbidden {