diff --git a/pkg/server/server.go b/pkg/server/server.go index fb9158abedc..3d31b6eb8d4 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -127,25 +127,19 @@ func (s *Server) ListenAndServe(ctx context.Context, logger log.Logger, addr str grpc_health.RegisterHealthServer(srv, s.grpcProbe.HealthServer()) internalMux := chi.NewRouter() - if pathPrefix != "" { - internalMux.Mount(pathPrefix+"/api", grpcWebMux) - } - internalMux.Mount("/api", grpcWebMux) - internalMux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) { - promhttp.HandlerFor(s.reg, promhttp.HandlerOpts{}).ServeHTTP(w, r) - }) - // Add the pprof handler to profile Parca - internalMux.HandleFunc("/debug/pprof/*", func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/debug/pprof/profile" { - pprof.Profile(w, r) - return - } - if r.URL.Path == "/debug/pprof/fgprof" { - fgprof.Handler().ServeHTTP(w, r) - return - } - pprof.Index(w, r) + internalMux.Route(pathPrefix+"/", func(r chi.Router) { + r.Mount("/api", grpcWebMux) + + r.Handle("/metrics", promhttp.HandlerFor(s.reg, promhttp.HandlerOpts{})) + + // Add the pprof handler to profile Parca + r.Handle("/debug/pprof/*", http.StripPrefix(pathPrefix, http.HandlerFunc(pprof.Index))) + r.Handle("/debug/pprof/fgprof", fgprof.Handler()) + r.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + r.HandleFunc("/debug/pprof/profile", pprof.Profile) + r.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + r.HandleFunc("/debug/pprof/trace", pprof.Trace) }) // Strip the subpath