Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit f65dbc7

Browse files
authored
Merge pull request #289 from noamran/pprof
✨ import and enable pprof
2 parents 41beb1d + c908455 commit f65dbc7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ issues:
1414
# List of regexps of issue texts to exclude, empty list by default.
1515
exclude:
1616
- Using the variable on range scope `tc` in function literal
17+
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
1718
run:
1819
deadline: 2m
1920
skip-dirs:

main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package main
1818

1919
import (
2020
"flag"
21+
"net/http"
22+
_ "net/http/pprof"
2123
"os"
2224
"time"
2325

@@ -54,6 +56,7 @@ func main() {
5456
enableLeaderElection bool
5557
syncPeriod time.Duration
5658
watchNamespace string
59+
profilerAddress string
5760
)
5861

5962
flag.StringVar(
@@ -91,10 +94,24 @@ func main() {
9194
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.",
9295
)
9396

97+
flag.StringVar(
98+
&profilerAddress,
99+
"profiler-address",
100+
"",
101+
"Bind address to expose the pprof profiler (e.g. localhost:6060)",
102+
)
103+
94104
flag.Parse()
95105

96106
ctrl.SetLogger(klogr.New())
97107

108+
if profilerAddress != "" {
109+
klog.Infof("Profiler listening for requests at %s", profilerAddress)
110+
go func() {
111+
klog.Info(http.ListenAndServe(profilerAddress, nil))
112+
}()
113+
}
114+
98115
if controllers.DefaultTokenTTL-syncPeriod < 1*time.Minute {
99116
setupLog.Info("warning: the sync interval is close to the configured token TTL, tokens may expire temporarily before being refreshed")
100117
}

0 commit comments

Comments
 (0)