Skip to content

feat: add opt-in pprof server to the resource indexer - #117

Closed
ecv wants to merge 1 commit into
mainfrom
feat/indexer-pprof
Closed

ecv wants to merge 1 commit into
mainfrom
feat/indexer-pprof

Conversation

@ecv

@ecv ecv commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Why

Investigating #113 needed a heap and goroutine profile from a production indexer pod. The indexer had no pprof endpoint — net/http/pprof was imported nowhere and Run() started no HTTP server of any kind, not even for metrics or health. Getting a single profile therefore meant building a one-off image, pushing it, suspending Flux, patching the deployment, and rolling ten production pods before any data could be collected.

That work produced the findings in this comment: goroutines climbing 103 → 4,521 on one pod with 1,114 parked in meilisearch-go.waitForTask, a heap ~82% under the NATS connection read path, and 29.3% of CPU spent in jetstream.Metadata() from the trackMessage duplicate scan. None of it was reachable without this change.

What

Adds --pprof-bind-address, empty by default. When set, starts a net/http/pprof server on that address.

  • Handlers are registered on a dedicated ServeMux, not by importing net/http/pprof for its side effects, so http.DefaultServeMux is left untouched.
  • ListenAndServe errors other than http.ErrServerClosed are logged, never fatal — profiling must not be able to take down the indexer.
  • Shuts down on context cancellation with a 5s timeout.
  • ReadHeaderTimeout set to 10s.
  • Validate() rejects a malformed value via net.SplitHostPort.

The deployment passes --pprof-bind-address=$(PPROF_BIND_ADDRESS) in the same $(VAR) style as every other flag, defaulted to "".

Security

Inert unless deliberately enabled. No containerPort and no Service are added, deliberately — binding to 127.0.0.1:6060 keeps the endpoint reachable only through kubectl port-forward, which runs inside the pod network namespace, and never from the cluster network.

Usage

kubectl -n search-system set env deployment/resource-indexer PPROF_BIND_ADDRESS=127.0.0.1:6060
kubectl -n search-system port-forward pod/<indexer-pod> 6060:6060

curl -s 'http://localhost:6060/debug/pprof/goroutine?debug=2' > goroutines.txt
go tool pprof -inuse_space -top http://localhost:6060/debug/pprof/heap
go tool pprof -top 'http://localhost:6060/debug/pprof/profile?seconds=25'

Notes for review

Refs #113

🤖 Generated with Claude Code

https://claude.ai/code/session_01XHThCUggHF6zu6wMxHTrN3

The indexer exposed no profiling endpoint and started no HTTP server at
all, so diagnosing a production memory and goroutine problem required
building a one-off image and rolling it out before any data could be
collected.

Add a --pprof-bind-address flag, empty by default, which starts a
net/http/pprof server when set. Handlers are registered on a dedicated
ServeMux rather than by importing the package for its side effects, so
http.DefaultServeMux is left untouched. Failures are logged and never
fatal: profiling must not be able to take down the indexer.

Binding to 127.0.0.1:6060 keeps the endpoint reachable only through
kubectl port-forward, which runs inside the pod network namespace, and
not from the cluster network. The deployment wires PPROF_BIND_ADDRESS
through in the same $(VAR) style as the other flags and defaults it to
empty, so this is inert unless deliberately enabled. No containerPort
and no Service are added.

Refs #113

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XHThCUggHF6zu6wMxHTrN3
@ecv
ecv force-pushed the feat/indexer-pprof branch from b10300a to 2d0cb07 Compare September 9, 2026 21:43
@ecv

ecv commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing. The incident that prompted it was fixed in #114, and a profiling server can come back if another one needs it.

@ecv ecv closed this Sep 23, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Searching Resources in Milo Sep 23, 2026
@ecv
ecv deleted the feat/indexer-pprof branch October 29, 2026 18:10
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.

1 participant