From 58e9769dff9478b361a132ba610ad9a81eee6beb Mon Sep 17 00:00:00 2001 From: Jay Wren Date: Tue, 15 Aug 2023 10:58:32 -0400 Subject: [PATCH 1/3] enable pprof --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index 8f821677f..6206f048c 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,8 @@ package main import ( "context" "flag" + "net/http" + "net/http/pprof" "os" "strings" @@ -138,6 +140,7 @@ func main() { setupLog.Error(err, "unable to start manager") os.Exit(1) } + mgr.AddMetricsExtraHandler("/debug/pprof/", http.HandlerFunc(pprof.Index)) if err := certv1.AddToScheme(mgr.GetScheme()); err != nil { setupLog.Error(err, "") From 1dcdf07b65e30d34f09fa18f8f587704a61eab0b Mon Sep 17 00:00:00 2001 From: Jay Wren Date: Fri, 18 Aug 2023 10:45:13 -0400 Subject: [PATCH 2/3] suggestions --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 6206f048c..4f7031e0c 100644 --- a/main.go +++ b/main.go @@ -91,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") @@ -105,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)) @@ -140,7 +142,14 @@ func main() { setupLog.Error(err, "unable to start manager") os.Exit(1) } - mgr.AddMetricsExtraHandler("/debug/pprof/", http.HandlerFunc(pprof.Index)) + + if enableprofile { + mgr.AddMetricsExtraHandler("/debug/pprof/", http.HandlerFunc(pprof.Index)) + mgr.AddMetricsExtraHandler("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) + mgr.AddMetricsExtraHandler("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) + mgr.AddMetricsExtraHandler("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) + mgr.AddMetricsExtraHandler("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) + } if err := certv1.AddToScheme(mgr.GetScheme()); err != nil { setupLog.Error(err, "") From 156ea95abcdfc0c814386b9b00ef1a4b83e9d0bc Mon Sep 17 00:00:00 2001 From: Jay Wren Date: Mon, 11 Sep 2023 12:07:31 -0400 Subject: [PATCH 3/3] check returned errors --- main.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 4f7031e0c..eb6f46c73 100644 --- a/main.go +++ b/main.go @@ -144,11 +144,31 @@ func main() { } if enableprofile { - mgr.AddMetricsExtraHandler("/debug/pprof/", http.HandlerFunc(pprof.Index)) - mgr.AddMetricsExtraHandler("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) - mgr.AddMetricsExtraHandler("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) - mgr.AddMetricsExtraHandler("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) - mgr.AddMetricsExtraHandler("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) + 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 {