Restore availability of pprof in the debug server

With CI Web Terminal initial implementation
(!934)
we've changed the way how the debug server is started.

It can be seen at !934 (diffs)

```diff
+		mux := http.NewServeMux()
+
		go func() {
-			log.Fatalln(http.Serve(listener, nil))
+			log.Fatalln(http.Serve(listener, mux))
		}()
```

Instead of relaying on the `http.DefaultServeMux` (which is used when
`http.Serve(listener, nil)` is called), we're creating our own ServeMux
which next is used for handling requests.

Unfortunately this breaks automatic registration of pprof handlers,
which in `net/http/pprof`'s `init()` are using `http.Handle()`, which
registers the handlers in `http.DefaultServeMux`.

This commit adds an explicit registration of pprof handlers to the
`mux` ServeMux created by us. This will restore the functionality
that we had present before version 11.3.0.
parent bda9765d
Pipeline #51227549 passed with stages
in 75 minutes and 33 seconds
......@@ -5,7 +5,7 @@ import (
"fmt"
"net"
"net/http"
_ "net/http/pprof" // pprof package adds everything itself inside its init() function
"net/http/pprof"
"os"
"os/signal"
"runtime"
......@@ -474,6 +474,14 @@ func (mr *RunCommand) serveDebugData(mux *http.ServeMux) {
mux.HandleFunc("/debug/jobs/list", mr.buildsHelper.ListJobsHandler)
}
func (mr *RunCommand) servePprof(mux *http.ServeMux) {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
func (mr *RunCommand) setupMetricsAndDebugServer() {
listenAddress, err := mr.listenAddress()
......@@ -505,6 +513,7 @@ func (mr *RunCommand) setupMetricsAndDebugServer() {
mr.serveMetrics(mux)
mr.serveDebugData(mux)
mr.servePprof(mux)
mr.log().
WithField("address", listenAddress).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment