Skip to content

Commit b9ad7c8

Browse files
authored
Add pprof flag (#703)
* add optional pprof to logging-operator * add extraArgs to chart
1 parent 3c9ab3f commit b9ad7c8

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ manager: generate fmt vet
100100

101101
# Run against the configured Kubernetes cluster in ~/.kube/config
102102
run: generate fmt vet
103-
go run ./main.go --verbose
103+
go run ./main.go --verbose --pprof
104104

105105
# remote debug
106106
debug: manager

charts/logging-operator/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ spec:
3434
containers:
3535
- name: {{ .Chart.Name }}
3636
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
37+
args: {{ range .Values.extraArgs }}
38+
- {{ . -}}
39+
{{ end }}
3740
imagePullPolicy: {{ .Values.image.pullPolicy }}
3841
resources:
3942
{{- toYaml .Values.resources | nindent 12 }}

charts/logging-operator/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ image:
99
tag: 3.9.1
1010
pullPolicy: IfNotPresent
1111

12+
extraArgs: []
1213
imagePullSecrets: []
1314
nameOverride: ""
1415
fullnameOverride: ""

main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package main
1717
import (
1818
"context"
1919
"flag"
20+
"net/http"
21+
"net/http/pprof"
2022
"os"
2123
"strings"
2224

@@ -54,11 +56,13 @@ func main() {
5456
var metricsAddr string
5557
var enableLeaderElection bool
5658
var verboseLogging bool
59+
var enableprofile bool
5760

5861
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
5962
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
6063
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
6164
flag.BoolVar(&verboseLogging, "verbose", false, "Enable verbose logging")
65+
flag.BoolVar(&enableprofile, "pprof", false, "enable pprof")
6266
flag.Parse()
6367

6468
ctx := context.Background()
@@ -81,6 +85,15 @@ func main() {
8185
os.Exit(1)
8286
}
8387

88+
if enableprofile {
89+
setupLog.Info("enabling pprof")
90+
err = mgr.AddMetricsExtraHandler("/debug/pprof/", http.HandlerFunc(pprof.Index))
91+
if err != nil {
92+
setupLog.Error(err, "unable to attach pprof to webserver")
93+
os.Exit(1)
94+
}
95+
}
96+
8497
if err := detectContainerRuntime(ctx, mgr.GetAPIReader()); err != nil {
8598
setupLog.Error(err, "failed to detect container runtime")
8699
os.Exit(1)

0 commit comments

Comments
 (0)