diff --git a/main.go b/main.go index 8f821677f..eb6f46c73 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,8 @@ package main import ( "context" "flag" + "net/http" + "net/http/pprof" "os" "strings" @@ -89,6 +91,7 @@ func main() { certSigningDisabled bool certManagerEnabled bool maxKafkaTopicConcurrentReconciles int + enableprofile bool ) flag.StringVar(&namespaces, "namespaces", "", "Comma separated list of namespaces where operator listens for resources") @@ -103,6 +106,7 @@ func main() { flag.BoolVar(&certManagerEnabled, "cert-manager-enabled", false, "Enable cert-manager integration") flag.BoolVar(&certSigningDisabled, "disable-cert-signing-support", false, "Disable native certificate signing integration") flag.IntVar(&maxKafkaTopicConcurrentReconciles, "max-kafka-topic-concurrent-reconciles", 10, "Define max amount of concurrent KafkaTopic reconciles") + flag.BoolVar(&enableprofile, "pprof", false, "Enable pprof") flag.Parse() ctrl.SetLogger(util.CreateLogger(verboseLogging, developmentLogging)) @@ -139,6 +143,34 @@ func main() { os.Exit(1) } + if enableprofile { + err := mgr.AddMetricsExtraHandler("/debug/pprof/", http.HandlerFunc(pprof.Index)) + if err != nil { + setupLog.Error(err, "unable to attach pprof to webserver") + os.Exit(1) + } + err = mgr.AddMetricsExtraHandler("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) + if err != nil { + setupLog.Error(err, "unable to attach pprof/cmdline to webserver") + os.Exit(1) + } + err = mgr.AddMetricsExtraHandler("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) + if err != nil { + setupLog.Error(err, "unable to attach pprof/profile to webserver") + os.Exit(1) + } + err = mgr.AddMetricsExtraHandler("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) + if err != nil { + setupLog.Error(err, "unable to attach pprof/symbol to webserver") + os.Exit(1) + } + err = mgr.AddMetricsExtraHandler("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) + if err != nil { + setupLog.Error(err, "unable to attach pprof/trace to webserver") + os.Exit(1) + } + } + if err := certv1.AddToScheme(mgr.GetScheme()); err != nil { setupLog.Error(err, "") os.Exit(1)