88 "net/http"
99 "strconv"
1010 "strings"
11+ "time"
1112
1213 "code.gitea.io/gitea/modules/cache"
1314 "code.gitea.io/gitea/modules/httplib"
@@ -18,7 +19,6 @@ import (
1819
1920 "gitea.com/go-chi/session"
2021 "github.com/chi-middleware/proxy"
21- "github.com/felixge/httpsnoop"
2222 "github.com/go-chi/chi/v5"
2323 "github.com/prometheus/client_golang/prometheus"
2424 "github.com/prometheus/client_golang/prometheus/promauto"
@@ -145,13 +145,14 @@ func RouteMetrics() func(h http.Handler) http.Handler {
145145 inflight := reqInflightGauge .WithLabelValues (req .Method )
146146 inflight .Inc ()
147147 defer inflight .Dec ()
148+ start := time .Now ()
148149
149- m := httpsnoop .CaptureMetrics (next , resp , req )
150150 next .ServeHTTP (resp , req )
151+ m := context .WrapResponseWriter (resp )
151152 route := chi .RouteContext (req .Context ()).RoutePattern ()
152- code := strconv .Itoa (m .Code )
153- reqDurationHistogram .WithLabelValues (req .Method , code , route ).Observe (m . Duration .Seconds ())
154- respSizeHistogram .WithLabelValues (req .Method , code , route ).Observe (float64 (m .Written ))
153+ code := strconv .Itoa (m .WrittenStatus () )
154+ reqDurationHistogram .WithLabelValues (req .Method , code , route ).Observe (time . Since ( start ) .Seconds ())
155+ respSizeHistogram .WithLabelValues (req .Method , code , route ).Observe (float64 (m .Size () ))
155156 size := req .ContentLength
156157 if size < 0 {
157158 size = 0
0 commit comments