proposal: net/http/pprof: function to register all profiles to a mux
- Dominant language
- Go
- Stars
- 139k
- Forks
- 19.4k
- PR merge metrics
- PR metrics pending
Description
## User Story
- I have an application that has `mux` instances.
- I want to enable `net/http/pprof` on a specific `mux` 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`:
https://github.com/golang/go/blob/46b576be724b6e64359fd872b9bd5109aba93cc0/src/net/http/pprof/pprof.go#L95-L105
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 profilers[^2]. 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.
[^1]: https://pkg.go.dev/net/http/pprof#:~:text=To%20use%20pprof%2C%20link%20this%20package%20into%20your%20program%3A
[^2]: 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.
Contributor guide
Research direction
Start with src/net/http/pprof/pprof.go, especially the init function and the handlers listed in the issue. Compare the current DefaultServeMux registration with the documented manual-registration path; done means the public API and its behavior for a caller-supplied mux are agreed and implemented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100