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

enable pprof #1039

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ package main
import (
"context"
"flag"
"net/http"
"net/http/pprof"
"os"
"strings"

Expand Down Expand Up @@ -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")
Expand All @@ -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))

Expand Down Expand Up @@ -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)
Expand Down