diff --git a/tsweb/debug.go b/tsweb/debug.go index 8125c5e8b..54fd188cb 100644 --- a/tsweb/debug.go +++ b/tsweb/debug.go @@ -47,6 +47,11 @@ func Debugger(mux *http.ServeMux) *DebugHandler { } mux.Handle("/debug/", ret) + // Register this one directly on mux, rather than using + // ret.URL/etc, as we don't need another line of output on the + // index page. The /pprof/ index already covers it. + mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) + ret.KVFunc("Uptime", func() interface{} { return Uptime() }) ret.KV("Version", version.Long) ret.Handle("vars", "Metrics (Go)", expvar.Handler()) diff --git a/tsweb/debug_test.go b/tsweb/debug_test.go index 9bb391e96..3d6216bfd 100644 --- a/tsweb/debug_test.go +++ b/tsweb/debug_test.go @@ -9,6 +9,7 @@ import ( "io" "net/http" "net/http/httptest" + "runtime" "strings" "testing" ) @@ -25,6 +26,25 @@ func TestDebugger(t *testing.T) { if dbg2 != dbg1 { t.Fatal("Debugger returned different debuggers for the same mux") } + + t.Run("cpu_pprof", func(t *testing.T) { + if testing.Short() { + t.Skip("skipping second long test") + } + switch runtime.GOOS { + case "linux", "darwin": + default: + t.Skipf("skipping test on %v", runtime.GOOS) + } + req := httptest.NewRequest("GET", "/debug/pprof/profile?seconds=1", nil) + req.RemoteAddr = "100.101.102.103:1234" + rec := httptest.NewRecorder() + mux.ServeHTTP(rec, req) + res := rec.Result() + if res.StatusCode != 200 { + t.Errorf("unexpected %v", res.Status) + } + }) } func get(m http.Handler, path, srcIP string) (int, string) {