From 01df6113c2b43fdae567382428ccf54c408eb476 Mon Sep 17 00:00:00 2001 From: Jonas Falck Date: Wed, 6 Nov 2024 08:12:37 +0100 Subject: [PATCH] Add pprof endpoints if enabled in configuration --- cmd/kured/main.go | 6 ++++++ cmd/kured/pprof.go | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 cmd/kured/pprof.go diff --git a/cmd/kured/main.go b/cmd/kured/main.go index c7bf94985..c46bc7714 100644 --- a/cmd/kured/main.go +++ b/cmd/kured/main.go @@ -48,6 +48,7 @@ var ( period time.Duration metricsHost string metricsPort int + pprofEnabled bool drainGracePeriod int drainPodSelector string skipWaitForDeleteTimeoutSeconds int @@ -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", "", @@ -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)) } diff --git a/cmd/kured/pprof.go b/cmd/kured/pprof.go new file mode 100644 index 000000000..b710d1bc5 --- /dev/null +++ b/cmd/kured/pprof.go @@ -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) +}