Skip to content

Add opt-in pprof HTTP server for profiling - #1244

Merged
CatherineF-dev merged 1 commit into
GoogleCloudPlatform:masterfrom
CatherineF-dev:pprof
Aug 24, 2026
Merged

Add opt-in pprof HTTP server for profiling#1244
CatherineF-dev merged 1 commit into
GoogleCloudPlatform:masterfrom
CatherineF-dev:pprof

Conversation

@CatherineF-dev

Copy link
Copy Markdown
Contributor

Expose Go's net/http/pprof handlers on a dedicated HTTP server, enabled only when the PPROF_SERVER_PORT environment variable is set (disabled by default). The server runs on its own ServeMux and port, is started in a goroutine, and is gracefully shut down when the process stop channel is closed.

Move the Prometheus /metrics handler off http.DefaultServeMux onto a private ServeMux so that importing net/http/pprof (which registers its handlers on the default mux in its init) cannot inadvertently expose the profiling endpoints on the metrics port.

Add a unit test for startPprofServer.

@baizhenyu
baizhenyu self-requested a review August 24, 2026 21:09

@baizhenyu baizhenyu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm Only one minor thing, this is the first instance that using env var for a config (i.e other configs are passed by CLI flags). Consider making them consistent if feasible.

@CatherineF-dev

Copy link
Copy Markdown
Contributor Author

I verified that the newly added env is not reconciled.

Expose Go's net/http/pprof handlers on a dedicated HTTP server, enabled only
when the PPROF_SERVER_PORT environment variable is set (disabled by default).
The server runs on its own ServeMux and port, is started in a goroutine, and is
gracefully shut down when the process stop channel is closed.

Move the Prometheus /metrics handler off http.DefaultServeMux onto a private
ServeMux so that importing net/http/pprof (which registers its handlers on the
default mux in its init) cannot inadvertently expose the profiling endpoints on
the metrics port.

Add a unit test for startPprofServer.
@CatherineF-dev
CatherineF-dev merged commit 7a7280c into GoogleCloudPlatform:master Aug 24, 2026
19 checks passed
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