OCPBUGS-125793: Add opt-in pprof endpoint to machine-controller-manager - #189
Conversation
|
@perdasilva: This pull request explicitly references no jira issue. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
Caution Review failedAn error occurred during the review process. Please try again later. WalkthroughThe manager binary now includes an HTTP pprof profiling server. CLI flags Changespprof profiling server feature
🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 13 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (13 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Tools execution failed with the following error: Failed to run tools: Ping-pong health check failed Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
cmd/manager/main_test.go (1)
93-93: ⚡ Quick winAvoid
InsecureSkipVerifyin TLS test clients.Even in tests, prefer trusting the generated self-signed cert via a dedicated
RootCAspool instead of disabling verification entirely.Also applies to: 155-155
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/manager/main_test.go` at line 93, Replace the insecure TLS configuration that sets TLSClientConfig: &tls.Config{InsecureSkipVerify: true} with a verification-friendly setup: create an x509.CertPool, add the test server's generated self-signed certificate (the PEM bytes used to start the test server) to that pool, and set TLSClientConfig: &tls.Config{RootCAs: certPool} for the test HTTP/TLS client; update both occurrences (the TLSClientConfig at the earlier location and the similar one at the later occurrence) so the client trusts only the test cert instead of disabling verification.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/manager/main_test.go`:
- Around line 70-75: The tests currently call net.Listen(...) and
client.Get(...) without contexts which can hang; create a bounded context (e.g.,
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5); defer
cancel()) before listening, replace net.Listen("tcp", ...) with
net.ListenConfig{}.Listen(ctx, "tcp", "127.0.0.1:0") (keep the listener variable
and Addr().String() usage), and replace client.Get(url) calls with an
http.NewRequestWithContext(ctx, "GET", url, nil) followed by client.Do(req) to
perform the request; ensure you handle and close response bodies and propagate
errors as before (references: net.ListenConfig{}.Listen,
http.NewRequestWithContext, client.Do, ctx/cancel).
- Around line 46-58: The test currently ignores error returns from pem.Encode
and from certOut.Close()/keyOut.Close(), and also ignores listener.Close() and
resp.Body.Close() in the pprof tests; update the self-signed cert generation
(the blocks calling pem.Encode(certOut, ...) and pem.Encode(keyOut, ...)) to
check and handle the returned error (return or t.Fatalf as appropriate) and
likewise check and handle errors from certOut.Close() and keyOut.Close();
additionally, locate the pprof test code that calls listener.Close() and
resp.Body.Close() and capture their errors (check and fail the test or log them)
instead of discarding them so no I/O failures are ignored.
In `@cmd/manager/main.go`:
- Around line 139-143: The pprof bind default currently uses
flag.String("pprof-bind-address", ":6060", ...) which listens on all interfaces;
change the default value to "127.0.0.1:6060" so pprofAddr defaults to
loopback-only, keeping the same flag name ("pprof-bind-address") and help text
so users must explicitly opt-in to expose it more widely.
---
Nitpick comments:
In `@cmd/manager/main_test.go`:
- Line 93: Replace the insecure TLS configuration that sets TLSClientConfig:
&tls.Config{InsecureSkipVerify: true} with a verification-friendly setup: create
an x509.CertPool, add the test server's generated self-signed certificate (the
PEM bytes used to start the test server) to that pool, and set TLSClientConfig:
&tls.Config{RootCAs: certPool} for the test HTTP/TLS client; update both
occurrences (the TLSClientConfig at the earlier location and the similar one at
the later occurrence) so the client trusts only the test cert instead of
disabling verification.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 731611e2-a703-406c-93d9-64d3a1b6b73b
📒 Files selected for processing (2)
cmd/manager/main.gocmd/manager/main_test.go
|
Actionable comments posted: 0 |
|
/hold wip |
|
/retest |
|
/retest |
66f7adc to
e2d50a5
Compare
|
/unhold |
damdo
left a comment
There was a problem hiding this comment.
Thanks Per,
I personally like the change.
Unfortunately we need to tweak it for the TLS constraints we have.
Add an opt-in pprof profiling endpoint to the AWS machine controller manager, gated behind the --enable-pprof flag (default: disabled). The pprof server listens on plaintext HTTP at 127.0.0.1:6060 (loopback only). TLS termination and authentication are expected to be handled by a kube-rbac-proxy sidecar configured in the machine-api-operator deployment, consistent with how other serving endpoints are secured across machine-api controllers. Changes: - Add pprofServer runnable (cmd/manager/pprof.go) that serves net/http/pprof handlers via the manager lifecycle with graceful shutdown on context cancellation - Add --enable-pprof and --pprof-bind-address CLI flags - Unit tests for server response, graceful shutdown, and leader election opt-out Signed-off-by: Per G. da Silva <pegoncal@redhat.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e2d50a5 to
b1d0852
Compare
|
/retest |
|
/retest |
2 similar comments
|
/retest |
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: damdo The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/verified by @perdasilva |
|
@perdasilva: This PR has been marked as verified by DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
/retest |
1 similar comment
|
/retest |
|
/retest |
|
/test e2e-aws |
|
@perdasilva: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
@perdasilva: Jira Issue OCPBUGS-125793: Some pull requests linked via external trackers have merged: The following pull request, linked via external tracker, has not merged: All associated pull requests must be merged or unlinked from the Jira bug in order for it to move to the next state. Once unlinked, request a bug refresh with Jira Issue OCPBUGS-125793 has not been moved to the MODIFIED state. This PR is marked as verified. If the remaining PRs listed above are marked as verified before merging, the issue will automatically be moved to VERIFIED after all of the changes from the PRs are available in an accepted nightly payload. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
Description
Add an opt-in pprof profiling endpoint to the AWS machine controller manager, gated behind the
--enable-pprofflag (default: disabled).The pprof server listens on plaintext HTTP at
127.0.0.1:6060(loopback only). TLS termination and authentication are expected to be handled by a kube-rbac-proxy sidecar configured in themachine-api-operatordeployment, consistent with how other serving endpoints are secured across machine-api controllers.Changes
cmd/manager/pprof.go—pprofServerrunnable that servesnet/http/pprofhandlers via the manager lifecycle with graceful shutdown on context cancellation.cmd/manager/main.go—--enable-pprofand--pprof-bind-addressCLI flags. When enabled, registers the pprof server as a manager runnable (no leader election required).cmd/manager/main_test.go— unit tests for server response, graceful shutdown, and leader election opt-out.Dependencies
machine-api-operatorto inject a kube-rbac-proxy sidecar for the pprof port in themachine-api-controllersdeployment (AWS only).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
--enable-pprofto activate profiling and--pprof-bind-addressto specify the listen address (default:127.0.0.1:6060).Tests