Skip to content

Commit

Permalink
Merge pull request #66 from topolvm/pprof
Browse files Browse the repository at this point in the history
Add pprof function
  • Loading branch information
satoru-takeuchi committed May 16, 2023
2 parents e15c2d7 + 0e4234e commit 75a4967
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions charts/pie/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ spec:
- "--probe-period"
- "{{ . }}"
{{- end }}
{{- with .Values.controller.enablePProf }}
- "--enable-pprof"
- "{{ . }}"
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
1 change: 1 addition & 0 deletions charts/pie/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ controller:
monitoringStorageClasses: []
createProbeThreshold:
nodeSelector:
enablePProf:
11 changes: 11 additions & 0 deletions cmd/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cmd
import (
"errors"
"flag"
"net/http"
"net/http/pprof"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -40,6 +42,7 @@ var (
controllerURL string
probePeriod int
createProbeThreshold time.Duration
enablePProf bool

opts zap.Options
)
Expand All @@ -58,6 +61,7 @@ func init() {
flags.StringVar(&controllerURL, "controller-url", "", "The controller URL which probe pods access")
flags.IntVar(&probePeriod, "probe-period", 1, "The period[minute] for CronJob to create a probe pod.")
flags.DurationVar(&createProbeThreshold, "create-probe-threshold", time.Minute, "The threshold of probe creation.")
flags.BoolVar(&enablePProf, "enable-pprof", false, "Enable PProf function")
opts.Development = true

goflags := flag.NewFlagSet("klog", flag.ExitOnError)
Expand Down Expand Up @@ -172,6 +176,13 @@ func subMain() error {
return err
}

if enablePProf {
if err := mgr.AddMetricsExtraHandler("/debug/pprof/", http.HandlerFunc(pprof.Index)); err != nil {
setupLog.Error(err, "unable to set up pprof endpoint")
return err
}
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down

0 comments on commit 75a4967

Please sign in to comment.