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

✨ import and enable pprof #289

Merged
merged 1 commit into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ issues:
# List of regexps of issue texts to exclude, empty list by default.
exclude:
- Using the variable on range scope `tc` in function literal
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
run:
deadline: 2m
skip-dirs:
Expand Down
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package main

import (
"flag"
"net/http"
_ "net/http/pprof"
"os"
"time"

Expand Down Expand Up @@ -54,6 +56,7 @@ func main() {
enableLeaderElection bool
syncPeriod time.Duration
watchNamespace string
profilerAddress string
)

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

flag.StringVar(
&profilerAddress,
"profiler-address",
"",
"Bind address to expose the pprof profiler (e.g. localhost:6060)",
)

flag.Parse()

ctrl.SetLogger(klogr.New())

if profilerAddress != "" {
klog.Infof("Profiler listening for requests at %s", profilerAddress)
go func() {
klog.Info(http.ListenAndServe(profilerAddress, nil))
}()
}

if controllers.DefaultTokenTTL-syncPeriod < 1*time.Minute {
setupLog.Info("warning: the sync interval is close to the configured token TTL, tokens may expire temporarily before being refreshed")
}
Expand Down