Skip to content

Commit

Permalink
Add pprof endpoints if enabled in configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Falck <[email protected]>
  • Loading branch information
Jonas Falck committed Nov 6, 2024
1 parent 9fbd0a2 commit 1d548d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/kured/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var (
period time.Duration
metricsHost string
metricsPort int
pprofEnabled bool
drainGracePeriod int
drainPodSelector string
skipWaitForDeleteTimeoutSeconds int
Expand Down Expand Up @@ -120,6 +121,8 @@ func main() {
"host where metrics will listen")
flag.IntVar(&metricsPort, "metrics-port", 8080,
"port number where metrics will listen")
flag.BoolVar(&pprofEnabled, "pprof-enabled", false,
"enable /debug/pprof on metrics port")
flag.IntVar(&drainGracePeriod, "drain-grace-period", -1,
"time in seconds given to each pod to terminate gracefully, if negative, the default value specified in the pod will be used")
flag.StringVar(&drainPodSelector, "drain-pod-selector", "",
Expand Down Expand Up @@ -278,6 +281,9 @@ func main() {
go rebootAsRequired(nodeID, rebooter, rebootChecker, window, lock, client)
go maintainRebootRequiredMetric(nodeID, rebootChecker)

if pprofEnabled {
enablePPROF()
}
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%d", metricsHost, metricsPort), nil))
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/kured/pprof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"net/http"
"net/http/pprof"
)

func enablePPROF() {
prefix := "GET "
http.HandleFunc(prefix+"/debug/pprof/", pprof.Index)
http.HandleFunc(prefix+"/debug/pprof/cmdline", pprof.Cmdline)
http.HandleFunc(prefix+"/debug/pprof/profile", pprof.Profile)
http.HandleFunc(prefix+"/debug/pprof/symbol", pprof.Symbol)
http.HandleFunc(prefix+"/debug/pprof/trace", pprof.Trace)
}

0 comments on commit 1d548d0

Please sign in to comment.