Skip to content

Add pprof profiling endpoint on main HTTP port under /pprof#107

Merged
shawnburke merged 2 commits into
mainfrom
add-pprof-endpoint
May 29, 2026
Merged

Add pprof profiling endpoint on main HTTP port under /pprof#107
shawnburke merged 2 commits into
mainfrom
add-pprof-endpoint

Conversation

@shawnburke
Copy link
Copy Markdown
Collaborator

Summary

Exposes Go's standard net/http/pprof handlers on the main HTTP port (HTTP_PORT / DefaultHttpPort) under /pprof, so operators can collect heap dumps, CPU profiles, and goroutine stacks from a running agent.

Gated behind a new ENABLE_PPROF env flag (default off), mirroring the existing EnableApiProxy pattern. Routes register only when the flag is set — pprof exposes sensitive runtime data (raw memory, goroutine stacks) and the main HTTP port has no auth on any route today.

Changes

  • agent/config/config.go — new EnablePprof bool field, parsed from ENABLE_PPROF ("true"/"1", default false); shown in Print() when enabled.
  • agent/server/http/pprof_handler.go (new) — a RegisterableHandler (same pattern as metricsHandler) that mounts a /pprof subrouter wiring the standard pprof entry points (/, /cmdline, /profile, /symbol, /trace) plus named profiles (heap, goroutine, allocs, block, mutex, threadcreate). Logs an info line when enabled.
  • agent/server/main_http_server.go — conditional registration: if config.EnablePprof { ... }.
  • agent/server/http/pprof_handler_test.go (new) — httptest-based coverage of the index page and heap profile.
  • .vscode/launch.json — sets ENABLE_PPROF=true for the local debug config.

Usage

Start the agent with ENABLE_PPROF=true, then:

  • curl http://localhost:$HTTP_PORT/pprof/ — profile index
  • go tool pprof http://localhost:$HTTP_PORT/pprof/heap — memory profile
  • go tool pprof http://localhost:$HTTP_PORT/pprof/profile?seconds=5 — CPU profile

Testing

  • go build ./... — compiles
  • go test ./server/http/... ./config/... — passes

Security note

Since the main HTTP port has no auth on any route, keep ENABLE_PPROF off in environments where the port is publicly reachable.

🤖 Generated with Claude Code

Exposes Go's net/http/pprof handlers on the main HTTP port (HTTP_PORT)
under /pprof for collecting heap dumps, CPU profiles, and goroutine
stacks from a running agent.

Gated behind a new ENABLE_PPROF env flag (default off) since pprof
exposes sensitive runtime data and the main HTTP port has no auth on
any route. Logs an info line when the endpoint is enabled.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shawnburke shawnburke requested a review from ashiramin May 29, 2026 02:22
The PR Trivy scan flags CVE-2026-43494 in linux-libc-dev (pulled in
transitively via build-essential). The fix is already published in
trixie (linux-libc-dev 6.12.90-2); the cached apt layer was just stale.
Bumping APT_CACHE_BUST forces apt-get update && upgrade to re-fetch the
patched version.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shawnburke shawnburke enabled auto-merge (squash) May 29, 2026 03:39
@shawnburke shawnburke merged commit d5fb26a into main May 29, 2026
17 checks passed
@shawnburke shawnburke deleted the add-pprof-endpoint branch May 29, 2026 06:07
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.

2 participants