8
8
"net/http"
9
9
"strconv"
10
10
"strings"
11
+ "time"
11
12
12
13
"code.gitea.io/gitea/modules/cache"
13
14
"code.gitea.io/gitea/modules/httplib"
@@ -18,7 +19,6 @@ import (
18
19
19
20
"gitea.com/go-chi/session"
20
21
"github.com/chi-middleware/proxy"
21
- "github.com/felixge/httpsnoop"
22
22
"github.com/go-chi/chi/v5"
23
23
"github.com/prometheus/client_golang/prometheus"
24
24
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -145,13 +145,14 @@ func RouteMetrics() func(h http.Handler) http.Handler {
145
145
inflight := reqInflightGauge .WithLabelValues (req .Method )
146
146
inflight .Inc ()
147
147
defer inflight .Dec ()
148
+ start := time .Now ()
148
149
149
- m := httpsnoop .CaptureMetrics (next , resp , req )
150
150
next .ServeHTTP (resp , req )
151
+ m := context .WrapResponseWriter (resp )
151
152
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 () ))
155
156
size := req .ContentLength
156
157
if size < 0 {
157
158
size = 0
0 commit comments