Skip to content

Commit e31cf7b

Browse files
committed
fix: fix pprof by register handlers explicitly
see https://pkg.go.dev/net/http/pprof > By default, all the profiles listed in runtime/pprof.Profile are available (via Handler), in addition to the Cmdline, Profile, Symbol, and Trace profiles defined in this package. If you are not using DefaultServeMux, you will have to register handlers with the mux you are using. Signed-off-by: j4ckstraw <[email protected]>
1 parent 07b7a42 commit e31cf7b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: pkg/exporters/k8sexporter/k8s_exporter.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"net"
2222
"net/http"
23-
_ "net/http/pprof"
23+
"net/http/pprof"
2424
"strconv"
2525

2626
"k8s.io/klog/v2"
@@ -95,6 +95,13 @@ func (ke *k8sExporter) startHTTPReporting(npdo *options.NodeProblemDetectorOptio
9595
util.ReturnHTTPJson(w, ke.conditionManager.GetConditions())
9696
})
9797

98+
// register pprof
99+
mux.HandleFunc("/debug/pprof/", pprof.Index)
100+
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
101+
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
102+
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
103+
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
104+
98105
addr := net.JoinHostPort(npdo.ServerAddress, strconv.Itoa(npdo.ServerPort))
99106
go func() {
100107
err := http.ListenAndServe(addr, mux)

0 commit comments

Comments
 (0)