-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal
Milestone
Description
User Story
- I have an application that has
mux
instances. - I want to enable
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
package init
function is the recommended path for enabling the pprof
handler.1 This method uses the DefaultServeMux
:
go/src/net/http/pprof/pprof.go
Lines 95 to 105 in 46b576b
func init() { | |
prefix := "" | |
if godebug.New("httpmuxgo121").Value() != "1" { | |
prefix = "GET " | |
} | |
http.HandleFunc(prefix+"/debug/pprof/", Index) | |
http.HandleFunc(prefix+"/debug/pprof/cmdline", Cmdline) | |
http.HandleFunc(prefix+"/debug/pprof/profile", Profile) | |
http.HandleFunc(prefix+"/debug/pprof/symbol", Symbol) | |
http.HandleFunc(prefix+"/debug/pprof/trace", Trace) | |
} |
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:
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline/", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile/", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol/", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace/", pprof.Trace)
Proposal
This experience could be made better for users by moving the logic in the init
function into a separate method (with the mux
as an argument), then invoking this within the default package init function.
Footnotes
tmthrgd and MaciejKaras
Metadata
Metadata
Assignees
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal
Type
Projects
Status
Incoming