Skip to content

Commit da179d6

Browse files
kdomanskikubermatic-bot
authored andcommitted
add a cmdline flag to enable profiling (#455)
1 parent 9897fe6 commit da179d6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cmd/controller/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"net"
2525
"net/http"
26+
"net/http/pprof"
2627
"os"
2728
"reflect"
2829
"strings"
@@ -71,6 +72,7 @@ var (
7172
kubeconfig string
7273
clusterDNSIPs string
7374
listenAddress string
75+
profiling bool
7476
name string
7577
joinClusterTimeout string
7678
workerCount int
@@ -165,6 +167,7 @@ func main() {
165167
flag.StringVar(&listenAddress, "internal-listen-address", "127.0.0.1:8085", "The address on which the http server will listen on. The server exposes metrics on /metrics, liveness check on /live and readiness check on /ready")
166168
flag.StringVar(&name, "name", "", "When set, the controller will only process machines with the label \"machine.k8s.io/controller\": name")
167169
flag.StringVar(&joinClusterTimeout, "join-cluster-timeout", "", "when set, machines that have an owner and do not join the cluster within the configured duration will be deleted, so the owner re-creats them")
170+
flag.BoolVar(&profiling, "enable-profiling", false, "when set, enables the endpoints on the http server under /debug/pprof/")
168171

169172
flag.Parse()
170173
kubeconfig = flag.Lookup("kubeconfig").Value.(flag.Getter).Get().(string)
@@ -472,6 +475,13 @@ func createUtilHTTPServer(kubeClient kubernetes.Interface, kubeconfigProvider ma
472475
m.Handle("/metrics", promhttp.HandlerFor(prometheusGatherer, promhttp.HandlerOpts{}))
473476
m.Handle("/live", http.HandlerFunc(health.LiveEndpoint))
474477
m.Handle("/ready", http.HandlerFunc(health.ReadyEndpoint))
478+
if profiling {
479+
m.HandleFunc("/debug/pprof/", pprof.Index)
480+
m.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
481+
m.HandleFunc("/debug/pprof/profile", pprof.Profile)
482+
m.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
483+
m.HandleFunc("/debug/pprof/trace", pprof.Trace)
484+
}
475485

476486
return &http.Server{
477487
Addr: listenAddress,

hack/run-machine-controller.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ $(dirname $0)/../machine-controller \
99
-logtostderr \
1010
-v=6 \
1111
-cluster-dns=172.16.0.10 \
12+
-enable-profiling \
1213
-internal-listen-address=0.0.0.0:8085

0 commit comments

Comments
 (0)