Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable pprof endpoint #1632

Merged
merged 5 commits into from
Aug 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ metadata:
name: grafana-operator-operator-metrics-service
spec:
ports:
- name: metrics
port: 8443
protocol: TCP
targetPort: metrics
- name: metrics
port: 8443
protocol: TCP
targetPort: metrics
- port: 8888
targetPort: pprof
protocol: TCP
name: pprof
selector:
app.kubernetes.io/managed-by: olm
app.kubernetes.io/name: grafana-operator
Expand Down
4 changes: 4 additions & 0 deletions config/default/metrics_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ spec:
port: 8443
protocol: TCP
targetPort: metrics
- port: 8888
targetPort: pprof
protocol: TCP
name: pprof
selector:
app.kubernetes.io/name: grafana-operator
app.kubernetes.io/managed-by: olm
3 changes: 3 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ spec:
- containerPort: 9090
protocol: TCP
name: metrics
- containerPort: 8888
name: pprof
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
Expand Down
1 change: 1 addition & 0 deletions deploy/helm/grafana-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ It's easier to just manage this configuration outside of the operator.
| isOpenShift | bool | `false` | Determines if the target cluster is OpenShift. Additional rbac permissions for routes will be added on OpenShift |
| leaderElect | bool | `false` | If you want to run multiple replicas of the grafana-operator, this is not recommended. |
| metricsService.metricsPort | int | `9090` | metrics service port |
| metricsService.pprofPort | int | `8888` | port for the pprof profiling endpoint |
| metricsService.type | string | `"ClusterIP"` | metrics service type |
| nameOverride | string | `""` | Overrides the name of the chart. |
| namespaceOverride | string | `""` | Overrides the namespace name. |
Expand Down
4 changes: 4 additions & 0 deletions deploy/helm/grafana-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ spec:
args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=0.0.0.0:{{ .Values.metricsService.metricsPort }}
- --pprof-addr=0.0.0.0:{{ .Values.metricsService.pprofPort }}
{{- if .Values.leaderElect }}
- --leader-elect
{{- end }}
Expand All @@ -67,6 +68,9 @@ spec:
- containerPort: {{ .Values.metricsService.metricsPort }}
name: metrics
protocol: TCP
- containerPort: {{ .Values.metricsService.pprofPort }}
name: pprof
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
Expand Down
4 changes: 4 additions & 0 deletions deploy/helm/grafana-operator/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ spec:
targetPort: metrics
protocol: TCP
name: metrics
- port: {{ .Values.metricsService.pprofPort }}
targetPort: pprof
protocol: TCP
name: pprof
selector:
{{- include "grafana-operator.selectorLabels" . | nindent 4 }}
2 changes: 2 additions & 0 deletions deploy/helm/grafana-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ metricsService:
type: ClusterIP
# -- metrics service port
metricsPort: 9090
# -- port for the pprof profiling endpoint
pprofPort: 8888

# -- additional labels to add to all resources
additionalLabels: {}
Expand Down
3 changes: 3 additions & 0 deletions deploy/kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ spec:
- containerPort: 9090
name: metrics
protocol: TCP
- containerPort: 8888
name: pprof
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
Expand Down
4 changes: 4 additions & 0 deletions deploy/kustomize/base/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ spec:
targetPort: metrics
protocol: TCP
name: metrics
- port: 8888
targetPort: pprof
protocol: TCP
name: pprof
selector:
app.kubernetes.io/name: grafana-operator
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var pprofAddr string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&pprofAddr, "pprof-addr", ":8888", "The address to expose the pprof server. Empty string disables the pprof server.")
opts := zap.Options{
Development: true,
}
Expand All @@ -109,6 +111,7 @@ func main() {
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "f75f3bba.integreatly.org",
PprofBindAddress: pprofAddr,
}

getNamespaceConfig := func(namespaces string) map[string]cache.Config {
Expand Down
Loading