-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: pprof debug endpoints not working with --web.route-prefix #4698
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: pprof debug endpoints not working with --web.route-prefix #4698
Conversation
ea08ffa to
c77837c
Compare
c77837c to
fba85a3
Compare
When using --web.route-prefix or --web.external-url with a path component, the pprof debug endpoints were not accessible. The handlers were directly passing requests to http.DefaultServeMux without adjusting the URL path to match what the pprof handlers expect. For example, with --web.route-prefix=/prometheus/alertmanager, a request to /prometheus/alertmanager/debug/pprof/ was being forwarded with the full path intact, but http.DefaultServeMux only has handlers registered for paths starting with /debug/pprof/. This fix reconstructs the request path by extracting the subpath parameter from the route and prepending /debug to it, ensuring the path matches what http.DefaultServeMux expects. The fix also preserves trailing slashes which are required by some pprof handlers. Added unit tests to verify pprof endpoints work correctly both with and without route prefix configuration. Co-authored-by: Claude <[email protected]> Signed-off-by: Will Hegedus <[email protected]>
fba85a3 to
45851d9
Compare
Co-authored-by: Siavash Safi <[email protected]> Signed-off-by: Will Hegedus <[email protected]>
Signed-off-by: Will Hegedus <[email protected]>
e50f8a3 to
81053db
Compare
Updated based on PR comments to conform with existing testing patterns Signed-off-by: Will Hegedus <[email protected]>
6e16897 to
b1f68ca
Compare
ui/web_test.go
Outdated
| router.ServeHTTP(w, req) | ||
|
|
||
| require.Equal(t, http.StatusOK, w.Code) | ||
| require.NotEqual(t, 0, w.Body.Len()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| require.NotEqual(t, 0, w.Body.Len()) | |
| require.Positive(t, w.Body.Len(), "body should not be empty") |
Alternatively we could replace the checks with https://pkg.go.dev/github.com/stretchr/testify/require#Assertions.HTTPBodyContains
but feel free to skip it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I think HTTPBodyContains might not be suitable here, it is best for custom handlers and not a router.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 7317f2d to use require.Contains() for checking the body, since -- as you said -- HTTPBodyContains would've required having access to the handlerFunc to pass to the test case.
Signed-off-by: Will Hegedus <[email protected]>
8e7f650 to
7317f2d
Compare
siavashs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thank you for your contribution!
|
@SuperQ we can merge this one. |
When using
--web.route-prefixor--web.external-urlwith a path component, the pprof debug endpoints were not accessible. The handlers were directly passing requests to http.DefaultServeMux without adjusting the URL path to match what the automatic pprof handlers expect.For example, with
--web.route-prefix=/prometheus/alertmanager, a request to/prometheus/alertmanager/debug/pprof/was being forwarded with the full path intact, but http.DefaultServeMux only has handlers registered for paths starting with/debug/pprof/.This fix reconstructs the request path by extracting the subpath parameter from the route and prepending /debug to it, ensuring the path matches what http.DefaultServeMux expects. The fix also preserves trailing slashes, which are required by some pprof handlers.
Added tests to verify pprof endpoints work correctly both with and without route prefix configuration.