-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: net/http/pprof: function to register all profiles to a mux #71213
Comments
Here is an example of where a re-implementation of this handler caused issues: |
Related Issues Related Code Changes
Related Discussions (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
Closely related to #42834. |
net/http/pprof
to support enabling on non-default ServeMux
A relatively straight forward way to do this currently is: import _ "net/http/pprof"
...
mux.Handle("/debug/pprof/", http.DefaultServerMux) and then rely on the init registration against |
CL 641858 proposes func AttachHandlers(prefix string, mux *http.ServeMux) But I don't think it's necessary to expose prefix as:
#42834 (comment) proposes a simpler: func RegisterHandlers(mux *http.ServeMux) |
Makes sense. I revised the CL to not expose |
CC @neild |
User Story
mux
instances.net/http/pprof
on a specificmux
instance.net/http/pprof
does not provide an ergonomic interface for attaching the handlers to a specific mux.Current Options / Alternatives Considered
The
net/http/pprof
packageinit
function is the recommended path for enabling thepprof
handler.1 This method uses theDefaultServeMux
:go/src/net/http/pprof/pprof.go
Lines 95 to 105 in 46b576b
If the user wants to mount the
pprof
handlers using a non-default mux, they must do this by manually enumerating all of the available profilers2. For example:Proposal
This experience could be made better for users by moving the logic in the
init
function into a separate method (with themux
as an argument), then invoking this within the default package init function.Footnotes
https://pkg.go.dev/net/http/pprof#:~:text=To%20use%20pprof%2C%20link%20this%20package%20into%20your%20program%3A ↩
https://pkg.go.dev/net/http/pprof#:~:text=If%20you%20are%20not%20using%20DefaultServeMux%2C%20you%20will%20have%20to%20register%20handlers%20with%20the%20mux%20you%20are%20using. ↩
The text was updated successfully, but these errors were encountered: