Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note
Profiling, as debugging and security hardening is a process and not a one-shot feature. Efforts should be put in simplifying the automation and onboarding the whole team into this process.
🏋️♀️ WIP
Jira: ARO-23245
What this PR does / why we need it:
I've refactored the pprof implementation to be production-ready and explicit.
Here's what was done:
cmd/aro/pprof.go (new file) -
Dedicated pprof server implementation with: Environment variable-based configuration (PPROF_ENABLED, PPROF_PORT, PPROF_HOST)
Localhost-only binding for security (rejects 0.0.0.0 or external IPs)
Request origin validation middleware that blocks non-localhost requests
Port collision detection before starting
Graceful shutdown support
Configurable timeouts
cmd/aro/pprof_test.go (new file) -
Comprehensive unit tests covering:
Enable/disable logic
Port configuration
Host configuration
Localhost validation
Server start/stop lifecycle
Port collision detection
Nil-safety
cmd/aro/const.go - Added pprof environment variable constants
cmd/aro/main.go - Replaced anonymous pprof goroutine with proper server initialization
env - Added pprof configuration variables
Dockerfile.ci-rp - Enabled pprof during CI tests
Makefile - Added comprehensive pprof profiling targets:
pprof-check - Check if pprof server is running
pprof-collect-all - Collect all profile types (CPU, heap, goroutine, allocs, block, mutex, trace)
pprof-cpu, pprof-heap, pprof-goroutine, etc. - Open specific profiles in browser
pprof-trace - Collect and view execution trace
loadtest-hey - Run load tests with hey
loadtest-vegeta - Run load tests with vegeta
pprof-loadtest - Combined load test + profiling
pprof-clean - Clean up profile outputs
.gitignore - Added /pprof-data/ directory
Security Features
Localhost-only binding: The server only binds to 127.0.0.1, localhost, ::1, or [::1]
Request origin validation: Middleware rejects requests from non-localhost IPs
Default disabled: In production (RP_MODE not set to development), pprof is disabled by default
Explicit enable required: Must set PPROF_ENABLED=true to enable in production
Why pprof is in cmd/aro?
The pprof server is in cmd/aro because it's application-level profiling for the entire binary
It needs to start before any service-specific code, it should be available across all service modes (rp, monitor, portal, etc.) and it's not a reusable package - it's entry-point configuration
Test plan for issue:
Usage:
Is there any documentation that needs to be updated for this PR?
How do you know this will function as expected in production?
Endpoints are secured to be accessible only from the localhost.
Also whenever production usage will be ready, specific env vars should be enabled.
Screenshots