Skip to content

🌱 runtime: loopback pprof, periodic memstats and cgroup-aware GOMEMLIMIT - #14682

Merged
hivecommons-hive[bot] merged 6 commits into
v5from
feat/runtime-pprof-memstats
Oct 28, 2026
Merged

hivecommons-hive[bot] merged 6 commits into
v5from
feat/runtime-pprof-memstats

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Why

Refs #14681 — the hive Go process on the hosted hive grows ~360 MiB/min and OOM-kills, and there was no net/http/pprof, no memstats log line and no GOMEMLIMIT, so the leak had to be chased from /proc alone.

What

  • pkg/runtimeobs (new):
    • StartPprof — net/http/pprof on a loopback-only listener. Config debug.pprof_addr, default 127.0.0.1:6060, off disables. A non-loopback host is rejected (ErrNotLoopback); bootConfig logs a warning and falls back to the default so a typo can never expose profiles on the pod network. /debug/runtime prints the snapshot below as text.
    • StartLogger — mem: runtime snapshot INFO line every 60 s: heap_inuse heap_live heap_objects total_sys next_gc gc_cycles goroutines threads gomemlimit. Read via runtime/metrics (no STW); threads from /proc/self/status.
    • ApplyMemoryLimit — honours GOMEMLIMIT if set; otherwise sets debug.SetMemoryLimit to MemoryLimitPercent (85%) of the cgroup limit (/sys/fs/cgroup/memory.max, v1 fallback). Unlimited cgroup → untouched. Logged at startup as runtime: memory limit source=env|cgroup|none.
  • cmd/hive/runtime_observability.go wires the three into bootConfig right after the root context exists; pprof stop is on the cleanup stack.
  • GET /api/health now carries the snapshot under runtime (goroutines, heap, threads) so the dashboard health probe / in-pod curl sees it without the pprof port.
  • docs/operator-reference.md → new "Runtime diagnostics" section with port-forward + go tool pprof recipe.
  • Changelog: changelog.d/added-runtime-pprof-memstats.md.

Tests

pkg/runtimeobs/runtimeobs_test.go: thread parsing, snapshot population, logger emits per injected tick (no sleeps in the hot path), loopback validation, pprof serves /debug/pprof/ + /debug/runtime, cgroup v1/v2/unlimited/garbage parsing, and the three ApplyMemoryLimit branches (env wins, cgroup derives 85%, none leaves the runtime default).

Operator use on the leaking pod once deployed

kubectl -n <ns> port-forward deploy/hive 6060:6060 &
go tool pprof -top http://127.0.0.1:6060/debug/pprof/heap
curl -s 'http://127.0.0.1:6060/debug/pprof/goroutine?debug=1' | head

@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 27, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 27, 2026
clubanderson added a commit that referenced this pull request Oct 27, 2026
Generated by changelog-fragment-guard from the PR title (#5675).
Edit the wording freely, or replace this file with the no-changelog
label if the change is not user-visible.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: clubanderson <407614+clubanderson@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#14790 🐛 fix: restore App reads for opt-in shared-UID agents same files src/cmd/hive/main.go
src/pkg/config/config.go
#14524 ✨ feat(hub,agent): Hub-coordinated live CLI session pool for multi-tenant runner capacity same files src/cmd/hive/main.go
src/docs/api-reference.md
#14701 ✨ feat(hub): add S256 PKCE verifier cookie to the Hub GitHub login same files src/docs/api-reference.md
#14702 ✨ review: scale reviewer concurrency up and down with backlog same files src/cmd/hive/main.go
src/pkg/config/config.go

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@clubanderson is auto-promoted for contributor-lane merging on this PR: the last 5 merged PRs by this author in this hive's repositories have no revert or sentinel-alert evidence. CI, reviewer verdict, diff fences, soak, holds and branch protection still apply.

@hivecommons-hive hivecommons-hive Bot added author/human A person pushed this PR themselves dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act labels Oct 27, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@clubanderson this PR is held at stage/071-needs-author and the hive will not merge it yet.

Failing checks:

  • changelog-fragment-guard

Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path.

@clubanderson
clubanderson force-pushed the feat/runtime-pprof-memstats branch from ac6b153 to 0c33054 Compare October 27, 2026 20:13
@github-actions github-actions Bot added the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Oct 27, 2026
clubanderson added a commit that referenced this pull request Oct 27, 2026
Generated by changelog-fragment-guard from the PR title (#5675).
Edit the wording freely, or replace this file with the no-changelog
label if the change is not user-visible.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: clubanderson <407614+clubanderson@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act labels Oct 27, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

Supersession sweep found that this PR's claimed issue is already closed by another merged PR.

  • Claimed issue: hive#14681
  • Closing PR: #14699

Decision needed (@hivecommons): #14699 already merged and closed the claimed issue, but this PR touches files the merged PR did not. Recommended: keep open until the extra changes are reviewed, or close as superseded if they are not wanted. Another option: merge anyway.

Files the merged PR did not touch: changelog.d/added-runtime-pprof-memstats.md, src/cmd/hive/main.go, src/cmd/hive/runtime_observability.go, src/internal/testutil/dashboard_import_allowlist.txt, src/pkg/config/config.go and 5 more.

This comment is edited in place by the supersession sweep; it is not duplicated.

@hivecommons-hive hivecommons-hive Bot added stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 27, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@clubanderson this PR is held at stage/071-needs-author and the hive will not merge it yet.

Why:

  • the branch conflicts with the base and needs a rebase

Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path.

@github-actions github-actions Bot removed the conflicts-with-open-pr Open PR has a merge conflict with another open PR label Oct 27, 2026
@hivecommons-hive hivecommons-hive Bot added the stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act label Oct 27, 2026

@hivecommons-hive hivecommons-hive Bot 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.

Read pkg/runtimeobs/runtimeobs.go and cmd/hive/runtime_observability.go in full against v5. The code looks correct to me; the only thing blocking this is the merge conflict.

Verified:

  • Loopback enforcement is belt-and-braces: IsLoopbackAddr (runtimeobs.go:171-181) rejects an empty host (":6060" → net.ParseIP("") is nil → false) as well as non-loopback IPs, StartPprof re-checks it (:189) so a caller bypassing bootConfig still cannot bind wide, and bootConfig's fallback to config.DefaultPprofAddr (runtime_observability.go:22-26) means a typo degrades to the default rather than to "off" or to the pod network.
  • ApplyMemoryLimit ordering is right: GOMEMLIMIT set → report only, never override (:233-235); max/empty/≥2^62 cgroup values all return ok=false and leave the runtime default (:264-276); DeriveMemoryLimit divides before multiplying so it cannot overflow on large limits.
  • StartLogger owns and stops its ticker only when it created it (:156-166), and StartPprof is non-fatal at boot with stop pushed onto b.cleanup.
  • All checks are green at c5112475; mergeable=DIRTY is the only blocker.

Conflicts — v5 has moved under 6 of the 13 files since your merge-base (18 commits behind): cmd/hive/main.go, pkg/config/config.go, pkg/dashboard/server.go, pkg/dashboard/settings_parity_allowlist.txt, docs/api-reference.md, docs/operator-reference.md. After rebasing, the 16 new server.go:NNN citations this PR adds to api-reference.md will almost certainly have drifted; bash src/scripts/check-api-reference-citations.sh --fix rewrites them.

Info, not blocking: Snapshot.HeapInuse is sampled from /memory/classes/heap/objects:bytes (:76, :98), which is live+unswept object bytes, not MemStats.HeapInuse (objects plus unused in-use spans). The value is the right one for chasing a leak; only the field/log name heap_inuse is slightly misleading to anyone comparing against runtime.MemStats.

— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 27, 2026
clubanderson and others added 6 commits October 27, 2026 21:04
Adds pkg/runtimeobs: a loopback-only net/http/pprof listener
(debug.pprof_addr, default 127.0.0.1:6060, 'off' disables), a 60 s
'mem: runtime snapshot' INFO line (heap in-use/live/objects, next GC,
goroutines, OS threads, GOMEMLIMIT) read via runtime/metrics, the same
snapshot under 'runtime' in GET /api/health, and a GOMEMLIMIT default of
85% of the cgroup memory limit when the env var is unset.

Refs #14681

Signed-off-by: Andy Anderson <andy@clubanderson.com>
- health body test decodes the new runtime object
- settings parity allowlist: debug.pprof_addr is an operator knob
- dashboard import ratchet: allow pkg/runtimeobs
- agent runtime golden: Config gained the debug block
- runtimeobs logger test waits on the record instead of sleeping
- api-reference citations re-pinned after the server.go import shift

Signed-off-by: Andy Anderson <andy@clubanderson.com>
Generated by changelog-fragment-guard from the PR title (#5675).
Edit the wording freely, or replace this file with the no-changelog
label if the change is not user-visible.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: clubanderson <407614+clubanderson@users.noreply.github.com>
…/proc paths

Signed-off-by: Andy Anderson <andy@clubanderson.com>
Signed-off-by: Andy Anderson <andy@clubanderson.com>
Signed-off-by: Andy Anderson <andy@clubanderson.com>
@clubanderson
clubanderson force-pushed the feat/runtime-pprof-memstats branch from c511247 to 53a9fc6 Compare October 28, 2026 01:07
@kubestellar-prow kubestellar-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 28, 2026
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act and removed stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 28, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@clubanderson this PR is held at stage/071-needs-author and the hive will not merge it yet.

Failing checks:

  • overlayfs-exec-guard

Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path.

@hivecommons-hive
hivecommons-hive Bot merged commit ebaf1c0 into v5 Oct 28, 2026
84 of 89 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the feat/runtime-pprof-memstats branch October 28, 2026 01:36
@hivecommons-hive

Copy link
Copy Markdown
Contributor
Evidence bundle `#1468253a9fc6` sha256:3892783f638748882c85435f946c21f32c0bee7b1fddafc05e2c9902c7cd9ad7 — download from the dashboard or `hivectl review evidence #14682`.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

@hivecommons-hive

Copy link
Copy Markdown
Contributor

merged by Hive trusted-author auto-merge: author @clubanderson holds role owner and GitHub permission admin on repo; CI green at 53a9fc6.

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/071-needs-author Human-authored PR: CI red, changes requested or conflicting; diagnosis posted, the author must act labels Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/human A person pushed this PR themselves dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant