Skip to content

Commit 3e7a3c8

Browse files
committed
Add pprof endpoints to vizier go services
Signed-off-by: Dom Del Nano <ddelnano@gmail.com> (cherry picked from commit f952071)
1 parent 4fb5d3f commit 3e7a3c8

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"
@@ -284,6 +285,8 @@ func main() {
284285
log.WithError(err).Fatal("Failed to create api environment")
285286
}
286287
mux := http.NewServeMux()
288+
// This handles all the pprof endpoints.
289+
mux.Handle("/debug/", http.DefaultServeMux)
287290
healthz.RegisterDefaultChecks(mux)
288291
metrics.MustRegisterMetricsHandlerNoDefaultMetrics(mux)
289292

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)