Skip to content

Add a flag for enabling pprof on the controller manager#4449

Merged
nikola-jokic merged 4 commits into
actions:masterfrom
mercari:Okabe-Junya/feature/add-pprof-flag
Apr 24, 2026
Merged

Add a flag for enabling pprof on the controller manager#4449
nikola-jokic merged 4 commits into
actions:masterfrom
mercari:Okabe-Junya/feature/add-pprof-flag

Conversation

@Okabe-Junya
Copy link
Copy Markdown
Contributor

cf. mercari#3

What

Add a --pprof-addr flag to the controller manager to expose Go's built-in pprof endpoint.

When the flag is set (e.g. --pprof-addr=:6060), the controller-runtime manager starts a pprof HTTP server on the specified address. When the flag is omitted or empty, pprof remains disabled (no behavior change).

The Helm chart is also updated to support configuring this via values.yaml.

Why

When operating ARC at scale, profiling the controller is essential for diagnosing memory leaks, goroutine issues, and CPU bottlenecks. controller-runtime already supports PprofBindAddress in its manager options, but ARC does not expose it as a flag, so there is currently no way to enable pprof without modifying the source code.

@Okabe-Junya Okabe-Junya marked this pull request as ready for review April 17, 2026 07:08
@Okabe-Junya Okabe-Junya requested a review from mumoshu as a code owner April 17, 2026 07:08
Copilot AI review requested due to automatic review settings April 17, 2026 07:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR exposes controller-runtime’s built-in pprof server configuration through a new controller-manager flag and wires it through the Helm chart so operators can enable profiling without patching the controller.

Changes:

  • Add --pprof-addr flag to controller-manager and pass it to controller-runtime manager options (PprofBindAddress).
  • Add Helm values.yaml configuration stub for pprof.
  • Update the controller Deployment template to optionally pass the flag and expose a pprof container port.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
main.go Adds --pprof-addr and forwards it into ctrl.Options.PprofBindAddress.
charts/gha-runner-scale-set-controller/values.yaml Documents new pprof.addr values block for enabling profiling.
charts/gha-runner-scale-set-controller/templates/deployment.yaml Renders --pprof-addr and conditionally adds a pprof container port when configured.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +105 to +110
- containerPort: {{regexReplaceAll ":([0-9]+)" .controllerManagerAddr "${1}"}}
protocol: TCP
name: metrics
{{- end }}
{{- with .Values.pprof }}
- containerPort: {{regexReplaceAll ":([0-9]+)" .addr "${1}"}}
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

containerPort is derived from .Values.pprof.addr using regexReplaceAll ":([0-9]+)" ..., which breaks for common bind addresses that include a host (e.g. 127.0.0.1:6060 becomes 127.0.0.16060). This will render an invalid containerPort and Kubernetes will reject the Deployment. Consider extracting the trailing port number (e.g. via regexFind on [0-9]+$ or splitList and take the last element), and optionally fail fast if no port can be parsed.

Suggested change
- containerPort: {{regexReplaceAll ":([0-9]+)" .controllerManagerAddr "${1}"}}
protocol: TCP
name: metrics
{{- end }}
{{- with .Values.pprof }}
- containerPort: {{regexReplaceAll ":([0-9]+)" .addr "${1}"}}
- containerPort: {{ required "Values.metrics.controllerManagerAddr must end with a numeric port" (regexFind "[0-9]+$" .controllerManagerAddr) }}
protocol: TCP
name: metrics
{{- end }}
{{- with .Values.pprof }}
- containerPort: {{ required "Values.pprof.addr must end with a numeric port" (regexFind "[0-9]+$" .addr) }}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good suggestion to be honest

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point, fixed this in 6640911

Comment thread charts/gha-runner-scale-set-controller/templates/deployment.yaml Outdated
Comment thread charts/gha-runner-scale-set-controller/values.yaml
Comment thread charts/gha-runner-scale-set-controller/templates/deployment.yaml Outdated
Copy link
Copy Markdown
Collaborator

@nikola-jokic nikola-jokic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! Maybe we can apply the suggestion from the copilot to wrap it in require, but otherwise, looks good!

@Okabe-Junya
Copy link
Copy Markdown
Contributor Author

Let me check CI red... 👀

@Okabe-Junya
Copy link
Copy Markdown
Contributor Author

Hope e859905 would fix

Copy link
Copy Markdown
Collaborator

@nikola-jokic nikola-jokic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nikola-jokic nikola-jokic merged commit 13a0330 into actions:master Apr 24, 2026
27 checks passed
@Okabe-Junya Okabe-Junya deleted the Okabe-Junya/feature/add-pprof-flag branch April 24, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants