mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Merge pull request #3132 from tomwilkie/fix-debug-handlers
Get pprof handlers working again
This commit is contained in:
commit
fae3bd17b9
|
@ -246,6 +246,11 @@ func serveDebug(w http.ResponseWriter, req *http.Request) {
|
|||
ctx := req.Context()
|
||||
subpath := route.Param(ctx, "subpath")
|
||||
|
||||
if subpath == "/pprof" {
|
||||
http.Redirect(w, req, req.URL.Path+"/", http.StatusMovedPermanently)
|
||||
return
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(subpath, "/pprof/") {
|
||||
http.NotFound(w, req)
|
||||
return
|
||||
|
@ -262,6 +267,7 @@ func serveDebug(w http.ResponseWriter, req *http.Request) {
|
|||
case "trace":
|
||||
pprof.Trace(w, req)
|
||||
default:
|
||||
req.URL.Path = "/debug/pprof/" + subpath
|
||||
pprof.Index(w, req)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package web
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -146,3 +147,37 @@ func TestReadyAndHealthy(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDebugHandler(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
prefix, url string
|
||||
code int
|
||||
}{
|
||||
{"/", "/debug/pprof/cmdline", 200},
|
||||
{"/foo", "/foo/debug/pprof/cmdline", 200},
|
||||
|
||||
{"/", "/debug/pprof/goroutine", 200},
|
||||
{"/foo", "/foo/debug/pprof/goroutine", 200},
|
||||
|
||||
{"/", "/debug/pprof/foo", 404},
|
||||
{"/foo", "/bar/debug/pprof/goroutine", 404},
|
||||
} {
|
||||
opts := &Options{
|
||||
RoutePrefix: tc.prefix,
|
||||
MetricsPath: "/metrics",
|
||||
}
|
||||
handler := New(opts)
|
||||
handler.Ready()
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, err := http.NewRequest("GET", tc.url, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %s", err)
|
||||
}
|
||||
|
||||
handler.router.ServeHTTP(w, req)
|
||||
if w.Code != tc.code {
|
||||
t.Fatalf("Unexpected status code %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue