Skip to content

Commit

Permalink
resolve port conflict for profiling feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Aug 31, 2023
1 parent 806e69d commit 517fb0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,20 @@ func init() {

func main() {
var metricsAddr string
var healthAddr string
var profilingAddr string
var configName string
var enableLeaderElection bool
var enableLoggerMode bool
var enableProfiling bool
flag.StringVar(&metricsAddr, cnst.ArgMetricsAddr, cnst.DefaultMetricsAddr, "The address the metric endpoint binds to.")
flag.StringVar(&healthAddr, cnst.ArgHealthAddr, cnst.DefaultHealthAddr, "The address the health endpoint binds to.")
flag.StringVar(&profilingAddr, cnst.ArgProfilingAddr, cnst.DefaultProfilingAddr, "The address the profiling endpoint binds to.")
flag.BoolVar(&enableLeaderElection, cnst.ArgEnableLeaderElection, false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(&enableLoggerMode, cnst.ArgEnableLoggerMode, false,
"Enable logger mode. Enabling this will only log events of the current namespace.")
flag.BoolVar(&enableProfiling, cnst.ArgEnableProfiling, false,
"Enable profiling on port ':8081'.")
flag.BoolVar(&enableProfiling, cnst.ArgEnableProfiling, false, "Enable profiling endpoint.")

flag.StringVar(&configName, cnst.ArgConfigName, "",
"The name of the eventlogger config to work with.")
Expand Down Expand Up @@ -100,7 +103,7 @@ func main() {
LeaderElection: enableLeaderElection && !enableLoggerMode,
LeaderElectionID: "leader.eventlogger.bakito.ch",
LeaderElectionResourceLock: os.Getenv(cnst.EnvLeaderElectionResourceLock),
HealthProbeBindAddress: ":8081",
HealthProbeBindAddress: healthAddr,
Cache: crtlcache.Options{
Namespaces: []string{watchNamespace},
},
Expand Down Expand Up @@ -168,7 +171,7 @@ func main() {
// +kubebuilder:scaffold:builder

if enableProfiling {
if err = mgr.Add(pprof.New(":8081")); err != nil {
if err = mgr.Add(pprof.New(profilingAddr)); err != nil {
setupLog.Error(err, "unable to create pprof service")
os.Exit(1)
}
Expand Down
18 changes: 15 additions & 3 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ const (
// ArgEnableLoggerMode enable logger mode
ArgEnableLoggerMode = "enable-logger-mode"

// ArgMetricsAddr metrics address
ArgMetricsAddr = "metrics-addr"

// ArgConfigName name of the config
ArgConfigName = "config-name"

// ArgMetricsAddr metrics address
ArgMetricsAddr = "metrics-addr"

// DefaultMetricsAddr default metrics address
DefaultMetricsAddr = ":8080"

// ArgHealthAddr health address
ArgHealthAddr = "health-addr"

// DefaultHealthAddr default health address
DefaultHealthAddr = ":8081"

// ArgProfilingAddr profiling address
ArgProfilingAddr = "profiling-addr"

// DefaultProfilingAddr default profiling address
DefaultProfilingAddr = ":8082"

// ArgEnableLeaderElection enable leader election
ArgEnableLeaderElection = "enable-leader-election"

Expand Down

0 comments on commit 517fb0c

Please sign in to comment.