Skip to content

Commit 89b8498

Browse files
committed
[baseserver] Serve pprof on /debug/pprof
1 parent 74e5863 commit 89b8498

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

components/common-go/baseserver/server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package baseserver
77
import (
88
"context"
99
"fmt"
10+
"github.com/gitpod-io/gitpod/common-go/pprof"
1011
"github.com/prometheus/client_golang/prometheus/promhttp"
1112
"github.com/sirupsen/logrus"
1213
"google.golang.org/grpc"
@@ -216,6 +217,7 @@ func (s *Server) newHTTPMux() *http.ServeMux {
216217
mux.HandleFunc("/ready", func(w http.ResponseWriter, r *http.Request) {
217218
_, _ = w.Write([]byte(`ready`))
218219
})
220+
s.Logger().WithField("protocol", "http").Debug("Serving readiness handler on /ready")
219221

220222
// Metrics endpoint
221223
metricsHandler := promhttp.Handler()
@@ -225,6 +227,10 @@ func (s *Server) newHTTPMux() *http.ServeMux {
225227
)
226228
}
227229
mux.Handle("/metrics", metricsHandler)
230+
s.Logger().WithField("protocol", "http").Debug("Serving metrics on /metrics")
231+
232+
mux.Handle(pprof.Path, pprof.Handler())
233+
s.Logger().WithField("protocol", "http").Debug("Serving profiler on /debug/pprof")
228234

229235
return mux
230236
}

components/common-go/baseserver/server_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package baseserver_test
77
import (
88
"fmt"
99
"github.com/gitpod-io/gitpod/common-go/baseserver"
10+
"github.com/gitpod-io/gitpod/common-go/pprof"
1011
"github.com/prometheus/client_golang/prometheus"
1112
"github.com/stretchr/testify/require"
1213
"net/http"
@@ -58,3 +59,12 @@ func TestServer_ServesMetricsEndpointWithCustomMetricsConfig(t *testing.T) {
5859
require.NoError(t, err)
5960
require.Equal(t, http.StatusOK, resp.StatusCode)
6061
}
62+
63+
func TestServer_ServesPprof(t *testing.T) {
64+
srv := baseserver.NewForTests(t)
65+
baseserver.StartServerForTests(t, srv)
66+
67+
resp, err := http.Get(srv.HTTPAddress() + pprof.Path)
68+
require.NoError(t, err)
69+
require.Equalf(t, http.StatusOK, resp.StatusCode, "must serve pprof on %s", pprof.Path)
70+
}

0 commit comments

Comments
 (0)