Skip to content

Commit

Permalink
Enable pprof in controller-manager (openshift#896)
Browse files Browse the repository at this point in the history
* Enable pprof in controller-manager

* Expose profiling options in chart
  • Loading branch information
derekwaynecarr authored and arschles committed Jun 5, 2017
1 parent f4233a0 commit d3d29f0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions charts/catalog/templates/controller-manager-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ spec:
args:
- --port
- "8080"
{{ if .Values.controllerManager.profiling.disabled -}}
- "--profiling=false"
{{- end}}
{{ if .Values.controllerManager.profiling.contentionProfiling -}}
- "--contention-profiling=true"
{{- end}}
{{- if not .Values.useAggregator }}
- --service-catalog-api-server-url
{{- if .Values.apiserver.insecure }}
Expand Down
6 changes: 6 additions & 0 deletions charts/catalog/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ controllerManager:
# Whether or not the controller supports a --broker-relist-interval flag. If this is
# set to true, brokerRelistInterval will be used as the value for that flag
brokerRelistIntervalActivated: true
# enables profiling via web interface host:port/debug/pprof/
profiling:
# Disable profiling via web interface host:port/debug/pprof/
disabled: false
# Enables lock contention profiling, if profiling is enabled.
contentionProfiling: false
useAggregator: false
11 changes: 11 additions & 0 deletions cmd/controller-manager/app/controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"fmt"
"net"
"net/http"
"net/http/pprof"
"os"
goruntime "runtime"
"strconv"
"time"

Expand Down Expand Up @@ -149,6 +151,15 @@ func Run(controllerManagerOptions *options.ControllerManagerServer) error {
healthz.InstallHandler(mux)
configz.InstallHandler(mux)

if controllerManagerOptions.EnableProfiling {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
if controllerManagerOptions.EnableContentionProfiling {
goruntime.SetBlockProfileRate(1)
}
}
server := &http.Server{
Addr: net.JoinHostPort(controllerManagerOptions.Address, strconv.Itoa(int(controllerManagerOptions.Port))),
Handler: mux,
Expand Down
4 changes: 4 additions & 0 deletions cmd/controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func NewControllerManagerServer() *ControllerManagerServer {
OSBAPIContextProfile: defaultOSBAPIContextProfile,
ConcurrentSyncs: defaultConcurrentSyncs,
LeaderElection: leaderelection.DefaultLeaderElectionConfiguration(),
EnableProfiling: true,
EnableContentionProfiling: false,
},
}
s.LeaderElection.LeaderElect = true
Expand All @@ -79,5 +81,7 @@ func (s *ControllerManagerServer) AddFlags(fs *pflag.FlagSet) {
fs.DurationVar(&s.ResyncInterval, "resync-interval", s.ResyncInterval, "The interval on which the controller will resync its informers")
fs.DurationVar(&s.BrokerRelistInterval, "broker-relist-interval", s.BrokerRelistInterval, "The interval on which a broker's catalog is relisted after the broker becomes ready")
fs.BoolVar(&s.OSBAPIContextProfile, "enable-osb-api-context-profile", s.OSBAPIContextProfile, "Whether or not to send the proposed optional OpenServiceBroker API Context Profile field")
fs.BoolVar(&s.EnableProfiling, "profiling", s.EnableProfiling, "Enable profiling via web interface host:port/debug/pprof/")
fs.BoolVar(&s.EnableContentionProfiling, "contention-profiling", s.EnableContentionProfiling, "Enable lock contention profiling, if profiling is enabled")
leaderelection.BindFlags(&s.LeaderElection, fs)
}
6 changes: 6 additions & 0 deletions pkg/apis/componentconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ type ControllerManagerConfiguration struct {

// leaderElection defines the configuration of leader election client.
LeaderElection componentconfig.LeaderElectionConfiguration

// enableProfiling enables profiling via web interface host:port/debug/pprof/
EnableProfiling bool

// enableContentionProfiling enables lock contention profiling, if enableProfiling is true.
EnableContentionProfiling bool
}

0 comments on commit d3d29f0

Please sign in to comment.