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

Add flag to enable HTTP pprof endpoint #373

Merged
merged 1 commit into from
Nov 24, 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
13 changes: 8 additions & 5 deletions cmd/synthetic-monitoring-agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type MuxOpts struct {
}
isReady *readynessHandler
disconnectEnabled bool
pprofEnabled bool
}

func NewMux(opts MuxOpts) *Mux {
Expand All @@ -54,11 +55,13 @@ func NewMux(opts MuxOpts) *Mux {
}

// Register pprof handlers
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)
if opts.pprofEnabled {
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)
}

requestCounter := prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: "http",
Expand Down
2 changes: 2 additions & 0 deletions cmd/synthetic-monitoring-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func run(args []string, stdout io.Writer) error {
httpListenAddr = flags.String("listen-address", ":4050", "listen address")
apiToken = flags.String("api-token", "", "synthetic monitoring probe authentication token")
enableDisconnect = flags.Bool("enable-disconnect", false, "enable HTTP /disconnect endpoint")
enablePProf = flags.Bool("enable-pprof", false, "exposes profiling data via HTTP /debug/pprof/ endpoint")
)

flags.Var(&features, "features", "optional feature flags")
Expand Down Expand Up @@ -114,6 +115,7 @@ func run(args []string, stdout io.Writer) error {
PromRegisterer: promRegisterer,
isReady: readynessHandler,
disconnectEnabled: *enableDisconnect,
pprofEnabled: *enablePProf,
})

httpConfig := http.Config{
Expand Down