Skip to content

Commit 80ebd2e

Browse files
committed
Profiler
1 parent 899c9ab commit 80ebd2e

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ data:
9292
9393
Please see [chart/k8sdb-controller](https://github.com/DoodleScheduling/k8sdb-controller) for the helm chart docs.
9494
95+
## Profiling
96+
To profile controller, access web server on #profilerPort (default 6060).
97+
98+
In Kubernetes, port-forward to this port, and open the `/debug/pprof` URL in browser. For example, if you port-forward 6060 from container to 6060 on your machine, access:
99+
```
100+
http://localhost:6060/debug/pprof/
101+
```
102+
95103
## Limitations
96104
97105
Currently there is no garbage collection implemented, meaning all the things created are not removed.

chart/k8sdb-controller/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ spec:
6060
- name: probes
6161
containerPort: {{ .Values.probesPort }}
6262
protocol: TCP
63+
- name: profiler
64+
containerPort: {{ .Values.profilerPort }}
65+
protocol: TCP
6366
livenessProbe:
6467
{{- toYaml .Values.livenessProbe | nindent 10 }}
6568
readinessProbe:

chart/k8sdb-controller/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ podAnnotations: {}
3939

4040
metricsPort: "8080"
4141
probesPort: "9558"
42+
profilerPort: "6060"
4243

4344
# Change the metrics path
4445
metricsPath: /metrics

main.go

Lines changed: 14 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

2224
"github.com/spf13/pflag"
2325
"github.com/spf13/viper"
@@ -49,6 +51,7 @@ var (
4951
const (
5052
MetricAddr = "metrics-addr"
5153
ProbeAddr = "probe-addr"
54+
ProfilerAddr = "profiler-addr"
5255
EnableLeaderElection = "enable-leader-election"
5356
LeaderElectionNamespace = "leader-election-namespace"
5457
Namespaces = "namespaces"
@@ -59,6 +62,7 @@ const (
5962
var (
6063
metricsAddr = ":8080"
6164
probesAddr = ":9558"
65+
profilerAddr = ":6060"
6266
enableLeaderElection = false
6367
leaderElectionNamespace = ""
6468
namespacesConfig = ""
@@ -75,6 +79,7 @@ func init() {
7579
func main() {
7680
flag.StringVar(&metricsAddr, MetricAddr, ":8080", "The address the metric endpoint binds to.")
7781
flag.StringVar(&probesAddr, ProbeAddr, ":9558", "The address of the probe endpoints bind to.")
82+
flag.StringVar(&profilerAddr, ProfilerAddr, ":6060", "The address of the profiler endpoints bind to.")
7883
flag.BoolVar(&enableLeaderElection, EnableLeaderElection, false,
7984
"Enable leader election for controller manager. "+
8085
"Enabling this will ensure there is only one active controller manager.")
@@ -101,6 +106,7 @@ func main() {
101106
probesAddr = viper.GetString(ProbeAddr)
102107
namespacesConfig = viper.GetString(Namespaces)
103108
maxConcurrentReconciles = viper.GetInt(MaxConcurrentReconciles)
109+
profilerAddr = viper.GetString(ProfilerAddr)
104110

105111
namespaces := strings.Split(namespacesConfig, ",")
106112
options := ctrl.Options{
@@ -121,6 +127,14 @@ func main() {
121127
options.LeaderElectionNamespace = leaderElectionNamespace
122128
}
123129

130+
// Profiler
131+
go func() {
132+
setupLog.Info("Starting profiler...")
133+
if err := http.ListenAndServe(profilerAddr, nil); err != nil {
134+
setupLog.Error(err, "Profiler failed to start")
135+
}
136+
}()
137+
124138
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
125139
if err != nil {
126140
setupLog.Error(err, "unable to start manager")

0 commit comments

Comments
 (0)