Skip to content

[baseserver] Serve pprof on /debug/pprof #9476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/common-go/baseserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package baseserver
import (
"context"
"fmt"
"github.com/gitpod-io/gitpod/common-go/pprof"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
Expand Down Expand Up @@ -213,7 +214,10 @@ func (s *Server) initializeHTTP() error {
func (s *Server) newHTTPMux() *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/ready", s.cfg.healthHandler.ReadyEndpoint)
s.Logger().WithField("protocol", "http").Debug("Serving readiness handler on /ready")

mux.HandleFunc("/live", s.cfg.healthHandler.LiveEndpoint)
s.Logger().WithField("protocol", "http").Debug("Serving liveliness handler on /live")

// Metrics endpoint
metricsHandler := promhttp.Handler()
Expand All @@ -223,6 +227,10 @@ func (s *Server) newHTTPMux() *http.ServeMux {
)
}
mux.Handle("/metrics", metricsHandler)
s.Logger().WithField("protocol", "http").Debug("Serving metrics on /metrics")

mux.Handle(pprof.Path, pprof.Handler())
s.Logger().WithField("protocol", "http").Debug("Serving profiler on /debug/pprof")

return mux
}
Expand Down
10 changes: 10 additions & 0 deletions components/common-go/baseserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package baseserver_test
import (
"fmt"
"github.com/gitpod-io/gitpod/common-go/baseserver"
"github.com/gitpod-io/gitpod/common-go/pprof"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
"net/http"
Expand Down Expand Up @@ -67,3 +68,12 @@ func TestServer_ServesMetricsEndpointWithCustomMetricsConfig(t *testing.T) {
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestServer_ServesPprof(t *testing.T) {
srv := baseserver.NewForTests(t)
baseserver.StartServerForTests(t, srv)

resp, err := http.Get(srv.HTTPAddress() + pprof.Path)
require.NoError(t, err)
require.Equalf(t, http.StatusOK, resp.StatusCode, "must serve pprof on %s", pprof.Path)
}