feat: add pprof endpoint for router#1057
Conversation
Signed-off-by: Leo Xie <stleox@qq.com>
There was a problem hiding this comment.
Code Review
This pull request adds pprof endpoints to the debug server for performance profiling. Feedback suggests including missing standard endpoints like cmdline, symbol, and trace to ensure full functionality with debugging tools, and using gin.WrapH for more idiomatic handler wrapping.
| pprofGroup.GET("/", gin.WrapF(pprof.Index)) | ||
| pprofGroup.GET("/profile", gin.WrapF(pprof.Profile)) | ||
| pprofGroup.GET("/goroutine", gin.WrapF(pprof.Handler("goroutine").ServeHTTP)) | ||
| pprofGroup.GET("/heap", gin.WrapF(pprof.Handler("heap").ServeHTTP)) | ||
| pprofGroup.GET("/allocs", gin.WrapF(pprof.Handler("allocs").ServeHTTP)) | ||
| pprofGroup.GET("/block", gin.WrapF(pprof.Handler("block").ServeHTTP)) | ||
| pprofGroup.GET("/mutex", gin.WrapF(pprof.Handler("mutex").ServeHTTP)) |
There was a problem hiding this comment.
The current pprof implementation is missing several standard endpoints required for full functionality with debugging tools. Specifically, cmdline, symbol, trace, and threadcreate are missing. The symbol endpoint is critical for the pprof tool to resolve addresses to function names and must support both GET and POST methods. Additionally, using gin.WrapH is more idiomatic when wrapping an http.Handler returned by pprof.Handler.
| pprofGroup.GET("/", gin.WrapF(pprof.Index)) | |
| pprofGroup.GET("/profile", gin.WrapF(pprof.Profile)) | |
| pprofGroup.GET("/goroutine", gin.WrapF(pprof.Handler("goroutine").ServeHTTP)) | |
| pprofGroup.GET("/heap", gin.WrapF(pprof.Handler("heap").ServeHTTP)) | |
| pprofGroup.GET("/allocs", gin.WrapF(pprof.Handler("allocs").ServeHTTP)) | |
| pprofGroup.GET("/block", gin.WrapF(pprof.Handler("block").ServeHTTP)) | |
| pprofGroup.GET("/mutex", gin.WrapF(pprof.Handler("mutex").ServeHTTP)) | |
| pprofGroup.GET("/", gin.WrapF(pprof.Index)) | |
| pprofGroup.GET("/cmdline", gin.WrapF(pprof.Cmdline)) | |
| pprofGroup.GET("/profile", gin.WrapF(pprof.Profile)) | |
| pprofGroup.POST("/symbol", gin.WrapF(pprof.Symbol)) | |
| pprofGroup.GET("/symbol", gin.WrapF(pprof.Symbol)) | |
| pprofGroup.GET("/trace", gin.WrapF(pprof.Trace)) | |
| pprofGroup.GET("/allocs", gin.WrapH(pprof.Handler("allocs"))) | |
| pprofGroup.GET("/block", gin.WrapH(pprof.Handler("block"))) | |
| pprofGroup.GET("/goroutine", gin.WrapH(pprof.Handler("goroutine"))) | |
| pprofGroup.GET("/heap", gin.WrapH(pprof.Handler("heap"))) | |
| pprofGroup.GET("/mutex", gin.WrapH(pprof.Handler("mutex"))) | |
| pprofGroup.GET("/threadcreate", gin.WrapH(pprof.Handler("threadcreate"))) |
There was a problem hiding this comment.
Pull request overview
This PR adds runtime profiling support to the router’s localhost-only debug server, addressing the request to expose pprof diagnostics alongside existing debug/metrics capabilities.
Changes:
- Imports Go’s
net/http/pprofpackage. - Registers pprof endpoints on the router debug server under
/debug/pprof. - Keeps profiling on the existing localhost-bound debug server.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pprofGroup.GET("/profile", gin.WrapF(pprof.Profile)) | ||
| pprofGroup.GET("/goroutine", gin.WrapF(pprof.Handler("goroutine").ServeHTTP)) | ||
| pprofGroup.GET("/heap", gin.WrapF(pprof.Handler("heap").ServeHTTP)) | ||
| pprofGroup.GET("/allocs", gin.WrapF(pprof.Handler("allocs").ServeHTTP)) | ||
| pprofGroup.GET("/block", gin.WrapF(pprof.Handler("block").ServeHTTP)) | ||
| pprofGroup.GET("/mutex", gin.WrapF(pprof.Handler("mutex").ServeHTTP)) |
|
/lgtm |
|
@FAUST-BENCHOU: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hzxuzhonghu The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/kind enhancement
closed #1056