Skip to content

Commit

Permalink
capture all pprof routes
Browse files Browse the repository at this point in the history
  • Loading branch information
strantalis committed Jun 22, 2024
1 parent e0334f8 commit a784fc8
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions service/internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"net/http/pprof"
_ "net/http/pprof"

"github.com/bufbuild/protovalidate-go"
"github.com/go-chi/cors"
Expand Down Expand Up @@ -237,20 +236,20 @@ func newHTTPServer(c Config, h http.Handler, a *auth.Authentication, g *grpc.Ser
// ppprof handler
func pprofHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/debug/pprof/":
pprof.Index(w, r)
case "/debug/pprof/cmdline":
pprof.Cmdline(w, r)
case "/debug/pprof/heap":
pprof.Index(w, r)
case "/debug/pprof/profile":
pprof.Profile(w, r)
case "/debug/pprof/symbol":
pprof.Symbol(w, r)
case "/debug/pprof/trace":
pprof.Trace(w, r)
default:
if strings.HasPrefix(r.URL.Path, "/debug/pprof/") {
switch r.URL.Path {
case "/debug/pprof/cmdline":
pprof.Cmdline(w, r)
case "/debug/pprof/profile":
pprof.Profile(w, r)
case "/debug/pprof/symbol":
pprof.Symbol(w, r)
case "/debug/pprof/trace":
pprof.Trace(w, r)
default:
pprof.Index(w, r)
}
} else {
h.ServeHTTP(w, r)
}
})
Expand Down

0 comments on commit a784fc8

Please sign in to comment.