Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: serve everything under path prefix when set #3186

Merged
merged 4 commits into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines -130 to -133
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a rewrite rule, but what's the purpose of this then? It feels like the other paths were overlooked. Otherwise, I'd remove this if-block and we do not change anything in the router when pathPrefix is set. WDYT?


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
Expand Down