Skip to content

Commit

Permalink
adding flag to enable profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
yash97 committed Dec 22, 2024
1 parent 43535e1 commit 2797c9e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package main

import (
"context"
"net/http"
_ "net/http/pprof"
"os"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -70,6 +72,18 @@ func main() {
infoLogger.Error(err, "unable to load controller config")
os.Exit(1)
}

if controllerCFG.EnableProfiling {
infoLogger.Info("enable profiling true")
go func() {
infoLogger.Info("Starting pprof server at :7443/debug/pprof")
if err := http.ListenAndServe(":7443", nil); err != nil {
infoLogger.Error(err, "failed to start pprof server")
os.Exit(1)
}
}()
}

ctrlLogger := getLoggerWithLogLevel(controllerCFG.LogLevel)
ctrl.SetLogger(ctrlLogger)

Expand Down
17 changes: 12 additions & 5 deletions pkg/config/controller_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ const (
flagMaxConcurrentReconciles = "max-concurrent-reconciles"
flagEnableConfigMapCheck = "enable-configmap-check"
flagEndpointChunkSize = "endpoint-chunk-size"
defaultLogLevel = "info"
defaultMaxConcurrentReconciles = 3
defaultEndpointsChunkSize = 200
defaultEnableConfigMapCheck = true
flagEnableProfiling = "enable-profiling"
flagPodUpdateBatchPeriodDuration = "pod-update-batch-period-duration"
defaultBatchPeriodDuration = 1 * time.Second

defaultLogLevel = "info"
defaultMaxConcurrentReconciles = 3
defaultEndpointsChunkSize = 200
defaultEnableConfigMapCheck = true
defaultBatchPeriodDuration = 1 * time.Second
defaultEnableProfiling = false
)

// ControllerConfig contains the controller configuration
Expand All @@ -33,6 +36,8 @@ type ControllerConfig struct {
PodUpdateBatchPeriodDuration time.Duration
// Configurations for the Controller Runtime
RuntimeConfig RuntimeConfig
// To enable profiling
EnableProfiling bool
}

func (cfg *ControllerConfig) BindFlags(fs *pflag.FlagSet) {
Expand All @@ -46,5 +51,7 @@ func (cfg *ControllerConfig) BindFlags(fs *pflag.FlagSet) {
"Enable checking the configmap for starting the network policy controller")
fs.DurationVar(&cfg.PodUpdateBatchPeriodDuration, flagPodUpdateBatchPeriodDuration, defaultBatchPeriodDuration, ""+
"Duration between batch updates of pods")
fs.BoolVar(&cfg.EnableProfiling, flagEnableProfiling, defaultEnableProfiling,
"Enable checking the configmap for starting the network policy controller")
cfg.RuntimeConfig.BindFlags(fs)
}

0 comments on commit 2797c9e

Please sign in to comment.