Skip to content

Commit c2028f6

Browse files
committed
[baseserver] Serve pprof on /debug/pprof
1 parent 5854438 commit c2028f6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

components/common-go/baseserver/server.go

+8
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"
@@ -213,7 +214,10 @@ func (s *Server) initializeHTTP() error {
213214
func (s *Server) newHTTPMux() *http.ServeMux {
214215
mux := http.NewServeMux()
215216
mux.HandleFunc("/ready", s.cfg.healthHandler.ReadyEndpoint)
217+
s.Logger().WithField("protocol", "http").Debug("Serving readiness handler on /ready")
218+
216219
mux.HandleFunc("/live", s.cfg.healthHandler.LiveEndpoint)
220+
s.Logger().WithField("protocol", "http").Debug("Serving liveliness handler on /live")
217221

218222
// Metrics endpoint
219223
metricsHandler := promhttp.Handler()
@@ -223,6 +227,10 @@ func (s *Server) newHTTPMux() *http.ServeMux {
223227
)
224228
}
225229
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")
226234

227235
return mux
228236
}

components/common-go/baseserver/server_test.go

+10
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"
@@ -67,3 +68,12 @@ func TestServer_ServesMetricsEndpointWithCustomMetricsConfig(t *testing.T) {
6768
require.NoError(t, err)
6869
require.Equal(t, http.StatusOK, resp.StatusCode)
6970
}
71+
72+
func TestServer_ServesPprof(t *testing.T) {
73+
srv := baseserver.NewForTests(t)
74+
baseserver.StartServerForTests(t, srv)
75+
76+
resp, err := http.Get(srv.HTTPAddress() + pprof.Path)
77+
require.NoError(t, err)
78+
require.Equalf(t, http.StatusOK, resp.StatusCode, "must serve pprof on %s", pprof.Path)
79+
}

0 commit comments

Comments
 (0)