Skip to content

Commit

Permalink
fix erroneous handling of ignoredPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
xiam committed Jul 20, 2021
1 parent 3a69f87 commit 3968bec
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,29 @@ func Collector(cfg Config) func(next http.Handler) http.Handler {

return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
if r.Method == "GET" {
if isPathIgnored(r.URL.Path) {
next.ServeHTTP(w, r)
return
}
if strings.EqualFold(r.URL.Path, "/metrics") {
// serve metrics page
metricsHandler.Handler(next).ServeHTTP(w, r)
return
}
}

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

if r.Method == "GET" && isPathIgnored(r.URL.Path) {
metricsHandler.Handler(next).ServeHTTP(ww, r)
return
}

next.ServeHTTP(ww, r)
}
return http.HandlerFunc(fn)
}
}

var ignoredPaths = []string{"/metrics", "/ping", "/status"}
var ignoredPaths = []string{"/ping", "/status"}

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

0 comments on commit 3968bec

Please sign in to comment.