Skip to content

Commit 3968bec

Browse files
committed
fix erroneous handling of ignoredPaths
1 parent 3a69f87 commit 3968bec

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

collector.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,29 @@ func Collector(cfg Config) func(next http.Handler) http.Handler {
2929

3030
return func(next http.Handler) http.Handler {
3131
fn := func(w http.ResponseWriter, r *http.Request) {
32-
ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
32+
if r.Method == "GET" {
33+
if isPathIgnored(r.URL.Path) {
34+
next.ServeHTTP(w, r)
35+
return
36+
}
37+
if strings.EqualFold(r.URL.Path, "/metrics") {
38+
// serve metrics page
39+
metricsHandler.Handler(next).ServeHTTP(w, r)
40+
return
41+
}
42+
}
3343

44+
// measure request
45+
ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
3446
defer sample(time.Now().UTC(), r, ww)
3547

36-
if r.Method == "GET" && isPathIgnored(r.URL.Path) {
37-
metricsHandler.Handler(next).ServeHTTP(ww, r)
38-
return
39-
}
40-
4148
next.ServeHTTP(ww, r)
4249
}
4350
return http.HandlerFunc(fn)
4451
}
4552
}
4653

47-
var ignoredPaths = []string{"/metrics", "/ping", "/status"}
54+
var ignoredPaths = []string{"/ping", "/status"}
4855

4956
func isPathIgnored(path string) bool {
5057
for _, ignoredPath := range ignoredPaths {

0 commit comments

Comments
 (0)