Skip to content
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

feat: enable profiling endpoints #2482

Merged
merged 1 commit into from
May 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
2 changes: 2 additions & 0 deletions cmd/dex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ type Web struct {
// Telemetry is the config format for telemetry including the HTTP server config.
type Telemetry struct {
HTTP string `json:"http"`
// EnableProfiling makes profiling endpoints available via web interface host:port/debug/pprof/
EnableProfiling bool `json:"enableProfiling"`
nabokihms marked this conversation as resolved.
Show resolved Hide resolved
}

// GRPC is the config for the gRPC API.
Expand Down
13 changes: 13 additions & 0 deletions cmd/dex/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net"
"net/http"
"net/http/pprof"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -368,6 +369,10 @@ func runServe(options serveOptions) error {
return fmt.Errorf("listening (%s) on %s: %v", name, c.Telemetry.HTTP, err)
}

if c.Telemetry.EnableProfiling {
pprofHandler(telemetryRouter)
}

server := &http.Server{
Handler: telemetryRouter,
}
Expand Down Expand Up @@ -550,3 +555,11 @@ func applyConfigOverrides(options serveOptions, config *Config) {
config.Frontend.Dir = os.Getenv("DEX_FRONTEND_DIR")
}
}

func pprofHandler(router *http.ServeMux) {
router.HandleFunc("/debug/pprof/", pprof.Index)
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
1 change: 1 addition & 0 deletions examples/config-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ web:
# Configuration for telemetry
telemetry:
http: 0.0.0.0:5558
# enableProfiling: true

# Uncomment this block to enable the gRPC API. This values MUST be different
# from the HTTP endpoints.
Expand Down