Skip to content

Commit

Permalink
Fix debug pprof handler routing (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
jace-ys authored Aug 21, 2024
1 parent 59e3094 commit 8ae47a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ func MountPprofHandlers(mux Muxer, opts ...PprofOption) {
mux.HandleFunc(o.prefix+"profile", pprof.Profile)
mux.HandleFunc(o.prefix+"symbol", pprof.Symbol)
mux.HandleFunc(o.prefix+"trace", pprof.Trace)

mux.Handle(o.prefix+"goroutine", pprof.Handler("goroutine"))
mux.Handle(o.prefix+"threadcreate", pprof.Handler("threadcreate"))
mux.Handle(o.prefix+"mutex", pprof.Handler("mutex"))
mux.Handle(o.prefix+"heap", pprof.Handler("heap"))
mux.Handle(o.prefix+"block", pprof.Handler("block"))
mux.Handle(o.prefix+"allocs", pprof.Handler("allocs"))
}

// LogPayloads returns a Goa endpoint middleware that logs request payloads and
Expand Down
11 changes: 6 additions & 5 deletions debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"goa.design/clue/internal/testsvc"
"goa.design/clue/internal/testsvc/gen/test"
"goa.design/clue/log"
goahttp "goa.design/goa/v3/http"
)

func TestMountDebugLogEnabler(t *testing.T) {
Expand Down Expand Up @@ -76,18 +77,18 @@ func TestMountDebugLogEnabler(t *testing.T) {
}

func TestMountPprofHandlers(t *testing.T) {
mux := http.NewServeMux()
MountPprofHandlers(mux)
MountPprofHandlers(mux, WithPrefix("test"))
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mux := goahttp.NewMuxer()
MountPprofHandlers(Adapt(mux))
MountPprofHandlers(Adapt(mux), WithPrefix("test"))
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
w.WriteHeader(http.StatusNotFound)
return
}
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK")) // nolint: errcheck
})
mux.Handle("/", handler)
mux.Handle(http.MethodGet, "/", handler)
ts := httptest.NewServer(mux)
defer ts.Close()

Expand Down

0 comments on commit 8ae47a5

Please sign in to comment.