Skip to content

Commit 7ab7ee2

Browse files
authored
Add pprof endpoints to vizier go services (#2221)
Summary: Add pprof endpoints to vizier go services I'm working with a few community users who are seeing the metadata service consume lots of memory. This change adds the Go pprof endpoints to all vizier Go services to facilitate debugging heap usage. Relevant Issues: N/A Type of change: /kind functionality Test Plan: Skaffolded the change and verified I can use the `/debug/pprof` endpoints without auth Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent bd395f3 commit 7ab7ee2

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/shared/services/httpmiddleware/middleware.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func isMetricsEndpoint(input string) bool {
6666
return strings.HasPrefix(input, "/metrics")
6767
}
6868

69+
func isPprofEndpoint(input string) bool {
70+
return strings.HasPrefix(input, "/debug")
71+
}
72+
6973
// WithBearerAuthMiddleware checks for valid bearer auth or rejects the request.
7074
// This middleware should be use on all services (except auth/api) to validate our tokens.
7175
func WithBearerAuthMiddleware(env env.Env, next http.Handler) http.Handler {
@@ -80,6 +84,11 @@ func WithBearerAuthMiddleware(env env.Env, next http.Handler) http.Handler {
8084
next.ServeHTTP(w, r)
8185
return
8286
}
87+
if isPprofEndpoint(r.URL.Path) {
88+
// Skip auth for pprof endpoints.
89+
next.ServeHTTP(w, r)
90+
return
91+
}
8392
token, ok := GetTokenFromBearer(r)
8493
if !ok {
8594
http.Error(w, "Must have bearer auth", http.StatusUnauthorized)

src/vizier/services/cloud_connector/cloud_connector_server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"errors"
2424
"fmt"
2525
"net/http"
26+
_ "net/http/pprof"
2627
"time"
2728

2829
"github.com/gofrs/uuid"
@@ -174,6 +175,8 @@ func main() {
174175
defer svr.Stop()
175176

176177
mux := http.NewServeMux()
178+
// This handles all the pprof endpoints.
179+
mux.Handle("/debug/", http.DefaultServeMux)
177180
// Set up healthz endpoint.
178181
healthz.RegisterDefaultChecks(mux)
179182
// Set up readyz endpoint.

src/vizier/services/metadata/metadata_server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"crypto/tls"
2424
"fmt"
2525
"net/http"
26+
_ "net/http/pprof"
2627
"os"
2728
"path/filepath"
2829
"strings"
@@ -283,6 +284,8 @@ func main() {
283284
log.WithError(err).Fatal("Failed to create api environment")
284285
}
285286
mux := http.NewServeMux()
287+
// This handles all the pprof endpoints.
288+
mux.Handle("/debug/", http.DefaultServeMux)
286289
healthz.RegisterDefaultChecks(mux)
287290
metrics.MustRegisterMetricsHandlerNoDefaultMetrics(mux)
288291

src/vizier/services/query_broker/query_broker_server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"net"
2626
"net/http"
27+
_ "net/http/pprof"
2728
"time"
2829

2930
"github.com/cenkalti/backoff/v4"
@@ -106,6 +107,8 @@ func main() {
106107
log.WithError(err).Fatal("Failed to create api environment.")
107108
}
108109
mux := http.NewServeMux()
110+
// This handles all the pprof endpoints.
111+
mux.Handle("/debug/", http.DefaultServeMux)
109112
healthz.RegisterDefaultChecks(mux)
110113
metrics.MustRegisterMetricsHandlerNoDefaultMetrics(mux)
111114

0 commit comments

Comments
 (0)