From 9cb10a9435b8120e200387fc15fb785027cd5b29 Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Fri, 23 Jun 2023 11:43:10 +0200 Subject: [PATCH] all: Add flags to enable block profiling --- bootstrap/kubeadm/main.go | 9 +++++++++ controlplane/kubeadm/main.go | 9 +++++++++ main.go | 9 +++++++++ test/infrastructure/docker/main.go | 9 +++++++++ test/infrastructure/inmemory/main.go | 9 +++++++++ 5 files changed, 45 insertions(+) diff --git a/bootstrap/kubeadm/main.go b/bootstrap/kubeadm/main.go index 1f0ac438a8fb..a3f90eb887ea 100644 --- a/bootstrap/kubeadm/main.go +++ b/bootstrap/kubeadm/main.go @@ -23,6 +23,7 @@ import ( "fmt" _ "net/http/pprof" "os" + goruntime "runtime" "time" // +kubebuilder:scaffold:imports @@ -81,6 +82,7 @@ var ( watchFilterValue string watchNamespace string profilerAddress string + enableContentionProfiling bool clusterConcurrency int kubeadmConfigConcurrency int syncPeriod time.Duration @@ -119,6 +121,9 @@ func InitFlags(fs *pflag.FlagSet) { fs.StringVar(&profilerAddress, "profiler-address", "", "Bind address to expose the pprof profiler (e.g. localhost:6060)") + fs.BoolVar(&enableContentionProfiling, "contention-profiling", false, + "Enable block profiling, if profiler-address is set.") + fs.IntVar(&clusterConcurrency, "cluster-concurrency", 10, "Number of clusters to process simultaneously") @@ -184,6 +189,10 @@ func main() { watchNamespaces = []string{watchNamespace} } + if profilerAddress != "" && enableContentionProfiling { + goruntime.SetBlockProfileRate(1) + } + ctrlOptions := ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsBindAddr, diff --git a/controlplane/kubeadm/main.go b/controlplane/kubeadm/main.go index dee362bd5250..f7b038a85252 100644 --- a/controlplane/kubeadm/main.go +++ b/controlplane/kubeadm/main.go @@ -23,6 +23,7 @@ import ( "fmt" _ "net/http/pprof" "os" + goruntime "runtime" "time" // +kubebuilder:scaffold:imports @@ -86,6 +87,7 @@ var ( watchFilterValue string watchNamespace string profilerAddress string + enableContentionProfiling bool kubeadmControlPlaneConcurrency int syncPeriod time.Duration restConfigQPS float32 @@ -124,6 +126,9 @@ func InitFlags(fs *pflag.FlagSet) { fs.StringVar(&profilerAddress, "profiler-address", "", "Bind address to expose the pprof profiler (e.g. localhost:6060)") + fs.BoolVar(&enableContentionProfiling, "contention-profiling", false, + "Enable block profiling, if profiler-address is set.") + fs.IntVar(&kubeadmControlPlaneConcurrency, "kubeadmcontrolplane-concurrency", 10, "Number of kubeadm control planes to process simultaneously") @@ -188,6 +193,10 @@ func main() { watchNamespaces = []string{watchNamespace} } + if profilerAddress != "" && enableContentionProfiling { + goruntime.SetBlockProfileRate(1) + } + ctrlOptions := ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsBindAddr, diff --git a/main.go b/main.go index 3d8cd268fddb..52efce438a7c 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ import ( "flag" "fmt" "os" + goruntime "runtime" "time" // +kubebuilder:scaffold:imports @@ -86,6 +87,7 @@ var ( watchNamespace string watchFilterValue string profilerAddress string + enableContentionProfiling bool clusterTopologyConcurrency int clusterClassConcurrency int clusterConcurrency int @@ -159,6 +161,9 @@ func InitFlags(fs *pflag.FlagSet) { fs.StringVar(&profilerAddress, "profiler-address", "", "Bind address to expose the pprof profiler (e.g. localhost:6060)") + fs.BoolVar(&enableContentionProfiling, "contention-profiling", false, + "Enable block profiling, if profiler-address is set.") + fs.IntVar(&clusterTopologyConcurrency, "clustertopology-concurrency", 10, "Number of clusters to process simultaneously") @@ -252,6 +257,10 @@ func main() { watchNamespaces = []string{watchNamespace} } + if profilerAddress != "" && enableContentionProfiling { + goruntime.SetBlockProfileRate(1) + } + ctrlOptions := ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsBindAddr, diff --git a/test/infrastructure/docker/main.go b/test/infrastructure/docker/main.go index b3b0a205f9da..111bcaeb4faf 100644 --- a/test/infrastructure/docker/main.go +++ b/test/infrastructure/docker/main.go @@ -22,6 +22,7 @@ import ( "flag" "fmt" "os" + goruntime "runtime" "time" // +kubebuilder:scaffold:imports @@ -73,6 +74,7 @@ var ( watchNamespace string watchFilterValue string profilerAddress string + enableContentionProfiling bool concurrency int syncPeriod time.Duration restConfigQPS float32 @@ -125,6 +127,9 @@ func initFlags(fs *pflag.FlagSet) { fs.StringVar(&profilerAddress, "profiler-address", "", "Bind address to expose the pprof profiler (e.g. localhost:6060)") + fs.BoolVar(&enableContentionProfiling, "contention-profiling", false, + "Enable block profiling, if profiler-address is set.") + fs.IntVar(&concurrency, "concurrency", 10, "The number of docker machines to process simultaneously") @@ -186,6 +191,10 @@ func main() { watchNamespaces = []string{watchNamespace} } + if profilerAddress != "" && enableContentionProfiling { + goruntime.SetBlockProfileRate(1) + } + ctrlOptions := ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsBindAddr, diff --git a/test/infrastructure/inmemory/main.go b/test/infrastructure/inmemory/main.go index 43332aba4d60..595f58549062 100644 --- a/test/infrastructure/inmemory/main.go +++ b/test/infrastructure/inmemory/main.go @@ -22,6 +22,7 @@ import ( "flag" "fmt" "os" + goruntime "runtime" "time" "github.com/spf13/pflag" @@ -68,6 +69,7 @@ var ( watchNamespace string watchFilterValue string profilerAddress string + enableContentionProfiling bool clusterConcurrency int machineConcurrency int syncPeriod time.Duration @@ -121,6 +123,9 @@ func InitFlags(fs *pflag.FlagSet) { fs.StringVar(&profilerAddress, "profiler-address", "", "Bind address to expose the pprof profiler (e.g. localhost:6060)") + fs.BoolVar(&enableContentionProfiling, "contention-profiling", false, + "Enable block profiling, if profiler-address is set.") + fs.IntVar(&clusterConcurrency, "cluster-concurrency", 10, "Number of clusters to process simultaneously") @@ -180,6 +185,10 @@ func main() { watchNamespaces = []string{watchNamespace} } + if profilerAddress != "" && enableContentionProfiling { + goruntime.SetBlockProfileRate(1) + } + ctrlOptions := ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsBindAddr,