88 "net/http"
99 "strconv"
1010 "strings"
11+ "time"
1112
1213 "code.gitea.io/gitea/modules/cache"
1314 "code.gitea.io/gitea/modules/gtprof"
@@ -19,7 +20,6 @@ import (
1920
2021 "gitea.com/go-chi/session"
2122 "github.com/chi-middleware/proxy"
22- "github.com/felixge/httpsnoop"
2323 "github.com/go-chi/chi/v5"
2424 "github.com/prometheus/client_golang/prometheus"
2525 "github.com/prometheus/client_golang/prometheus/promauto"
@@ -158,13 +158,14 @@ func RouteMetrics() func(h http.Handler) http.Handler {
158158 inflight := reqInflightGauge .WithLabelValues (req .Method )
159159 inflight .Inc ()
160160 defer inflight .Dec ()
161+ start := time .Now ()
161162
162- m := httpsnoop .CaptureMetrics (next , resp , req )
163163 next .ServeHTTP (resp , req )
164+ m := context .WrapResponseWriter (resp )
164165 route := chi .RouteContext (req .Context ()).RoutePattern ()
165- code := strconv .Itoa (m .Code )
166- reqDurationHistogram .WithLabelValues (req .Method , code , route ).Observe (m . Duration .Seconds ())
167- respSizeHistogram .WithLabelValues (req .Method , code , route ).Observe (float64 (m .Written ))
166+ code := strconv .Itoa (m .WrittenStatus () )
167+ reqDurationHistogram .WithLabelValues (req .Method , code , route ).Observe (time . Since ( start ) .Seconds ())
168+ respSizeHistogram .WithLabelValues (req .Method , code , route ).Observe (float64 (m .Size () ))
168169 size := req .ContentLength
169170 if size < 0 {
170171 size = 0
0 commit comments