Skip to content

Commit

Permalink
Add support for profiling via pprof
Browse files Browse the repository at this point in the history
Disabled by default in case we're incurring a performance hit
  • Loading branch information
evenh committed Feb 3, 2025
1 parent 08115ab commit fb190b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/skiperator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package main
import (
"flag"
"fmt"
"os"
"strings"

"github.com/kartverket/skiperator/internal/controllers"
"github.com/kartverket/skiperator/internal/controllers/common"
"github.com/kartverket/skiperator/pkg/flags"
"github.com/kartverket/skiperator/pkg/k8sfeatures"
"github.com/kartverket/skiperator/pkg/resourceschemas"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
"os"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"strings"

"go.uber.org/zap/zapcore"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -69,13 +70,19 @@ func main() {

detectK8sVersion(kubeconfig)

pprofBindAddr := ""
if flags.FeatureFlags.EnableProfiling {
pprofBindAddr = ":8281"
}

mgr, err := ctrl.NewManager(kubeconfig, ctrl.Options{
Scheme: scheme,
HealthProbeBindAddress: ":8081",
LeaderElection: *leaderElection,
LeaderElectionNamespace: *leaderElectionNamespace,
Metrics: metricsserver.Options{BindAddress: ":8181"},
LeaderElectionID: "skiperator",
PprofBindAddress: pprofBindAddr,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
2 changes: 2 additions & 0 deletions pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ var FeatureFlags *Features
// environment variables.
type Features struct {
DisablePodTopologySpreadConstraints bool
EnableProfiling bool
}

func init() {
FeatureFlags = &Features{
DisablePodTopologySpreadConstraints: getEnvWithFallback("DISABLE_PTSC", false),
EnableProfiling: getEnvWithFallback("ENABLE_PROFILING", false),
}
}

Expand Down

0 comments on commit fb190b4

Please sign in to comment.