feat: add on-demand pprof server and heap auto-dump via environment variables - #475
Open
david-garcia-garcia wants to merge 2 commits into
Open
feat: add on-demand pprof server and heap auto-dump via environment variables#475david-garcia-garcia wants to merge 2 commits into
david-garcia-garcia wants to merge 2 commits into
Conversation
# Conflicts: # go.mod # go.sum
Member
|
Hello, Thank you for the PR. A few comments:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Adds
pkg/profiling— a zero-dependency package (stdlib only) that provides two opt-in profiling features, both controlled exclusively by environment variables so they can be turned on in a running container without rebuilding the image or editing config files.Fixes #476
pprof HTTP server (
CS_PROFILING_ENABLED=true)/debug/pprof/*on a dedicated listener (default:6060)http.ServeMux— pprof handlers are never registered onhttp.DefaultServeMuxand cannot leak onto the Prometheus/metricsserverGODEBUG=gctrace=1on startHeap auto-dump watcher (
CS_PROFILING_HEAP_DUMP_DIR=<path>)runtime.ReadMemStatseveryCS_PROFILING_HEAP_POLL_INTERVAL(default30s)heap-<RFC3339>.pb.gz) whenHeapAllocexceedsCS_PROFILING_HEAP_DUMP_THRESHOLD_MB(default200 MiB)CS_PROFILING_HEAP_DUMP_COOLDOWN, default5m) to avoid flooding the volumeBoth features are disabled by default — existing deployments are unaffected.
Why
The process intermittently spikes from ~30 MB to >300 MB and gets OOM-killed in container deployments. There was no way to collect a heap profile during or after a spike.
Changes
pkg/profiling/profiling.go— new packagecmd/root.go— two call sites after the Prometheus block