Skip to content

feat: expose opt-in pprof via PPROF_BIND_ADDRESS [RHIDP-15222] - #4249

Merged
NiallTwomey2 merged 10 commits into
mainfrom
RHIDP-15222-pprof-bind-address
Dec 3, 2026
Merged

NiallTwomey2 merged 10 commits into
mainfrom
RHIDP-15222-pprof-bind-address

Conversation

@NiallTwomey2

@NiallTwomey2 NiallTwomey2 commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Work in progress, enabling pprof via PPROF_BIND_ADDRESS to accessible for the rhdh-operator.

main
  read PPROF_BIND_ADDRESS
  ctrl.Options.PprofBindAddress
    empty  -> controller-runtime opens no pprof port
    set    -> HTTP server on that address, /debug/pprof/heap and /debug/pprof/allocs

RHIDP-15222 makes the operator serve Go pprof when an admin opts in. cmd/main.go reads PPROF_BIND_ADDRESS at process start and passes it to controller-runtime. Unset or empty leaves pprof off, which is the production default. The value to enable it is 127.0.0.1:6060.

The Deployment, CSV, Service, and Route stay unchanged. No Service or Route is added for 6060. The operator image still has no curl or wget. A new pod is required after the variable changes, because controller-runtime reads the address only at startup. On an OLM install the variable has to be set on the CSV. oc set env on the Deployment is reverted.

Must-gather does not change here. The handoff for RHIDP-15223 is: label app=rhdh-operator, Deployment rhdh-operator, container manager, port-forward to 6060, then GET /debug/pprof/heap and GET /debug/pprof/allocs. The response is a Go pprof protobuf.

Evidence

  • Before: On the shipping 2.1.0 image, pod rhdh-operator-86795b94d4-fr5s6 had PPROF_BIND_ADDRESS=127.0.0.1:6060 and still listened only on 8081 and 8443. /manager --help has no pprof flag. curl and wget are not in the image.
  • After: This branch wires the variable into PprofBindAddress. Still to show on a build of this commit: with the variable unset, nothing listens on 6060; with 127.0.0.1:6060, curl http://127.0.0.1:6060/debug/pprof/heap from outside the pod returns a profile that go tool pprof -top can open. The same check for /debug/pprof/allocs.

Merge Danger

Door: two-way

The default install does not set the variable, so merging does not open a port. Reverting the commit removes the option.

Blast radius: operator pod, and only after someone sets PPROF_BIND_ADDRESS and the pod restarts. A value of :6060 listens on every interface. 127.0.0.1:6060 stays on the pod loopback.

@rhdh-qodo-merge

rhdh-qodo-merge Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add opt-in pprof server via PPROF_BIND_ADDRESS env var

✨ Enhancement ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Reads PPROF_BIND_ADDRESS at startup and passes it to controller-runtime's PprofBindAddress.
• Empty or unset keeps pprof disabled, so the default install opens no new port.
• No Deployment, Service, Route, or must-gather changes; a pod restart is required after setting the
 variable.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed helper reads one environment variable, emits a startup status log, and supplies the resulting address to the manager's pprof option.
  • These effects serve the single bounded runtime profiling diagnostics behavior, with no source path to reconciliation, admission, persistent state or other user-facing functions.
Sources

cmd/main.go[235-235]

		PprofBindAddress:       pprofAddr,

cmd/main.go[438-440]

func pprofBindAddress() string {
	return os.Getenv("PPROF_BIND_ADDRESS")
}
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before, the manager did not populate PprofBindAddress from this helper or log profiling status.
  • After, it performs a direct environment lookup, applies a simple enabled-versus-disabled branch, logs the result, and assigns the value to the existing manager option.
  • The follow-up adds documentation and a README navigation link only; it introduces no new production correctness condition.
  • The correctness condition remains that the environment value and the "0"/empty status distinction reach the intended option and log; no new state protocol, transformation, concurrency algorithm or coordinated invariant is introduced.
Sources

cmd/main.go[235-235]

		PprofBindAddress:       pprofAddr,

cmd/main.go[438-440]

func pprofBindAddress() string {
	return os.Getenv("PPROF_BIND_ADDRESS")
}
Potential damage 🟡 Medium 🩹 Recoverable

  • If the configured profiling address is absent, invalid or otherwise unavailable, runtime profiling diagnostics can be lost while the manager's other configured services remain available.
  • Reverting or correcting the profiling configuration restores the diagnostics path; no persistent-state repair or external compensation is indicated.
  • Reverting or correcting the profiling configuration restores the diagnostics path.
  • No automatic repair or persistent-state recovery is required by the source.
Sources

cmd/main.go[235-235]

		PprofBindAddress:       pprofAddr,

cmd/main.go[438-440]

func pprofBindAddress() string {
	return os.Getenv("PPROF_BIND_ADDRESS")
}
Assessed commit c19b404
Diagram

graph TD
  A["PPROF_BIND_ADDRESS env"] --> B["cmd/main.go"] --> C["ctrl.Options"] --> D["controller-runtime pprof server"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Validate the address is loopback-only
  • ➕ Prevents accidental exposure on all interfaces from a mistyped value like ':6060'
  • ➕ Small added check next to the env read
  • ➖ Blocks legitimate use cases that need a non-loopback bind, such as port-forward from another host
  • ➖ Adds a rule that operators must learn
2. Command-line flag instead of env var
  • ➕ Consistent with other manager flags if they exist
  • ➕ Visible in --help output
  • ➖ Needs CSV args changes on OLM installs, not just env
  • ➖ The PR notes the existing --help has no pprof flag, so the change is larger

Recommendation: Keep the env var and controller-runtime option, since it is the smallest change and matches how the admin sets config on an OLM install. Add a guard that warns or rejects non-loopback addresses such as ':6060', because the PR notes that form listens on every interface and the endpoint has no authentication. The PR's current approach is otherwise sound; no alternative was judged better.

Files changed (1) +3 / -0

Enhancement (1) +3 / -0
main.goPass PPROF_BIND_ADDRESS env var to controller-runtime pprof option +3/-0

Pass PPROF_BIND_ADDRESS env var to controller-runtime pprof option

• Reads PPROF_BIND_ADDRESS with os.Getenv at startup and assigns it to ctrl.Options.PprofBindAddress. When the variable is empty, controller-runtime does not open a pprof port, so the default behavior is unchanged.

cmd/main.go

@rhdh-qodo-merge

rhdh-qodo-merge Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Code Review by Qodo


View medium (1)
Remediation recommended
1. Startup log says pprof is off when "0" is set 🐞 Bug
Description
The pprofAddr != "0" check in main makes the log report "pprof endpoint disabled (default)" for
the value 0, but PprofBindAddress is passed unchanged to controller-runtime, which only treats
the empty string as off. With PPROF_BIND_ADDRESS=0 the manager attempts to listen on 0, which is
not a valid TCP address, so the operator fails to start while the log reports that pprof is
disabled. The "0" special case copies the metrics-server convention, and nothing in this change
implements that convention for pprof.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
In `cmd/main.go`, the new startup log treats `PPROF_BIND_ADDRESS=0` as disabled (`pprofAddr != "" && pprofAddr != "0"`), but `pprofAddr` is passed unchanged to `ctrl.Options.PprofBindAddress`. controller-runtime only skips pprof for an empty string, so `0` makes the manager try to bind an invalid address and exit, while the log claims pprof is disabled.

## Fix Focus Areas
- cmd/main.go[221-236]

## Recommended Fix
Decide one contract and apply it in both places. Simplest: make the log use `pprofAddr != ""` only, matching controller-runtime, and document that an empty value is the only way to disable pprof. Alternatively, if `0` should disable pprof, normalise it in `pprofBindAddress()` (return "" for "0") so that the value passed to `ctrl.Options` and the log agree. Add a test in `cmd/main_test.go` covering the `0` case.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


@rhdh-qodo-merge

Copy link
Copy Markdown

Important

The /generate_labels command by Qodo was deprecated on the 1st of October 2026 and is no longer available. We recommend switching to the latest Qodo review capabilities. Learn more

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

✅ PR images built and pushed successfully!

Images are available for testing (expires in 7 days):

Image Full tag PR tag
Operator quay.io/rhdh-community/operator:2.2.0-pr-4249-64e57a3 quay.io/rhdh-community/operator:2.2.0-pr-4249
Bundle quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249-64e57a3 quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249
Catalog quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249-64e57a3 quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.08%. Comparing base (5fbae1b) to head (c19b404).
⚠️ Report is 37 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4249      +/-   ##
==========================================
+ Coverage   60.55%   65.08%   +4.52%     
==========================================
  Files          52       52              
  Lines        3684     3282     -402     
==========================================
- Hits         2231     2136      -95     
+ Misses       1257     1146     -111     
+ Partials      196        0     -196     
Flag Coverage Δ
nightly ?
unittests 65.08% <ø> (+4.52%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 52 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NiallTwomey2

NiallTwomey2 commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

Diagnostic analysis from testing:

Verified on pod rhdh-operator-67f75fc787-7gcv8, image quay.io/rhdh-community/operator:2.2.0-pr-4249-64e57a3, with PPROF_BIND_ADDRESS=127.0.0.1:6060.

/proc/net/tcp shows 0100007F:17AC in state 0A. That is 127.0.0.1:6060 listening. 8081 and 8443 are unchanged. No Service or Route was added for 6060.

Port-forward from the laptop, then:

The go tool pprof command reads the files within the operator cluster

The go tool pprof has managed to read 100% of the files in the cluster:
go tool pprof -top /tmp/operator-heap.pb
File: manager
Type: inuse_space
Showing nodes accounting for 6178.93kB, 100% of 6178.93kB total

go tool pprof -top /tmp/operator-allocs.pb
File: manager
Type: alloc_space
Showing nodes accounting for 38625.18kB, 100% of 38625.18kB total

The operator image has no curl or wget, so the request was made through the port-forward, not by exec of curl inside the pod.

Running the oc command from the first terminal, it stays in the running state because connection to port 6060 for pprof information is sustained in this session:

$> oc port-forward -n rhdh-operator "pod/$POD" 6060:6060
Forwarding from 127.0.0.1:6060 -> 6060
Forwarding from [::1]:6060 -> 6060

The operator can open port 6060 to accept pprof information

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

✅ PR images built and pushed successfully!

Images are available for testing (expires in 7 days):

Image Full tag PR tag
Operator quay.io/rhdh-community/operator:2.2.0-pr-4249-8a790b8 quay.io/rhdh-community/operator:2.2.0-pr-4249
Bundle quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249-8a790b8 quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249
Catalog quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249-8a790b8 quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249

@OpinionatedHeron OpinionatedHeron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall, I think you have something pretty solid here. Just a few callouts.

Before committing this, I think the ReadMe needs to be updated with this change as per the best_practices.md, as a new enablement is being added to the repo. I think the admin doc is a good place to start - is should show the restart requirements and details about the new configuration.

Comment thread cmd/main.go Resolved
Comment thread cmd/main.go Resolved
Comment thread cmd/main_test.go Resolved
NiallTwomey2 and others added 2 commits December 2, 2026 14:53
Co-authored-by: Leanne Ahern <127859485+OpinionatedHeron@users.noreply.github.com>
Co-authored-by: Leanne Ahern <127859485+OpinionatedHeron@users.noreply.github.com>
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

❌ PR image build failed

See workflow run for details.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

✅ PR images built and pushed successfully!

Images are available for testing (expires in 7 days):

Image Full tag PR tag
Operator quay.io/rhdh-community/operator:2.2.0-pr-4249-53ff0d0 quay.io/rhdh-community/operator:2.2.0-pr-4249
Bundle quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249-53ff0d0 quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249
Catalog quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249-53ff0d0 quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

✅ PR images built and pushed successfully!

Images are available for testing (expires in 7 days):

Image Full tag PR tag
Operator quay.io/rhdh-community/operator:2.2.0-pr-4249-a717ca7 quay.io/rhdh-community/operator:2.2.0-pr-4249
Bundle quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249-a717ca7 quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249
Catalog quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249-a717ca7 quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

✅ PR images built and pushed successfully!

Images are available for testing (expires in 7 days):

Image Full tag PR tag
Operator quay.io/rhdh-community/operator:2.2.0-pr-4249-dfb53c0 quay.io/rhdh-community/operator:2.2.0-pr-4249
Bundle quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249-dfb53c0 quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249
Catalog quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249-dfb53c0 quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

✅ PR images built and pushed successfully!

Images are available for testing (expires in 7 days):

Image Full tag PR tag
Operator quay.io/rhdh-community/operator:2.2.0-pr-4249-1c057c7 quay.io/rhdh-community/operator:2.2.0-pr-4249
Bundle quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249-1c057c7 quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249
Catalog quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249-1c057c7 quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249

Comment thread docs/admin.md Resolved
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

✅ PR images built and pushed successfully!

Images are available for testing (expires in 7 days):

Image Full tag PR tag
Operator quay.io/rhdh-community/operator:2.2.0-pr-4249-c19b404 quay.io/rhdh-community/operator:2.2.0-pr-4249
Bundle quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249-c19b404 quay.io/rhdh-community/operator-bundle:2.2.0-pr-4249
Catalog quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249-c19b404 quay.io/rhdh-community/operator-catalog:2.2.0-pr-4249

Comment thread docs/admin.md Resolved
@OpinionatedHeron

Copy link
Copy Markdown
Member

Everything looks good to me, happy to merge.

/lgtm

@NiallTwomey2
NiallTwomey2 merged commit 07da34a into main Dec 3, 2026
11 checks passed
@NiallTwomey2
NiallTwomey2 deleted the RHIDP-15222-pprof-bind-address branch December 3, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants