Skip to content

fix(prometheus): retain main GC metrics under series saturation - #180103

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-main-gc-metric-missing-20260919
Oct 22, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-main-gc-metric-missing-20260919

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: main-thread GC histograms can stay absent forever when startup traffic fills the Prometheus exporter's shared 2,048-series cap before its first GC batch arrives.

User Impact

Native main-thread GC counts, total time, and duration buckets remain available under exporter saturation. Existing worker GC totals and the shared cap are preserved. No configuration or migration is required; restart into the fixed build to restore a saturated exporter.

Why This Change Was Made

The observer already rechecks late diagnostic interest every 30 seconds. The permanent loss is at metric admission: existing series continue updating, but newly arriving GC label sets are rejected once the shared budget is full. The additional retained worker metrics in #179872 (548a331adb18) exposed this ordering problem.

Reserve the four fixed native main-thread GC label sets when the exporter starts. Reservations consume the existing budget, remain invisible until a real collection arrives, and reset with the exporter. Counting and bucket aggregation still use the same histogram owner. Other GC label sets retain normal cap behavior.

Production code grows by 36 lines to add explicit, observation-free histogram reservation and its four bounded callers; this is an observability repair, not a speculative performance optimization. The old histogram admission/aggregation path is reused rather than duplicated.

Evidence

A synthetic loopback HTTP exporter reproduction initializes the GC observer before loading the plugin, records identical startup RPC and worker-memory traffic, then activates demand and forces one real native GC. It uses each revision's actual exporter sources with the unchanged diagnostic dispatcher/observer owner. All scrapes return HTTP 200:

Exporter revision Main GC count Worker GC count after two identical snapshots
5817d926 1 Not implemented yet
548a331a^ 1 Not implemented yet
548a331a (#179872) Absent 7
4d35c3d2 Absent 7
Fixed 1 7

Fixed scrape:

openclaw_gc_duration_seconds_count{kind="mark_sweep_compact",reason="other",thread="main"} 1
openclaw_worker_gc_collections_total{kind="mark_sweep_compact",script="provider-prompt-state.worker.js",worker_class="compute"} 7

The committed saturation regression fails on the original code and passes with the fix; it verifies late samples for all four native kinds, sums, and bucket counts without manufactured observations. The four focused exporter files pass (41 tests; 9.75 seconds wrapper wall time, including compilation). GC-owner tests pass (8 tests), and both requested closure guards pass (22 tests). Export-name collision guard, targeted extension typecheck (tsrs), formatting, and diff checks pass. Independent Codex review is clean for P0–P2; the subsequent test relocation and explicit undefined return only address lint. Changed-file lint passes. Exact-head PR CI provides broad validation.

Scope: real native GC, real diagnostic dispatch, and the exporter HTTP handler on loopback with synthetic state. This does not claim a full historical Gateway boot or a production deployment. Broad validation is delegated to PR CI; no Testbox lease or benchmark run was needed.

Reserve the four native main-thread GC histograms before startup traffic can exhaust the shared series cap. Keep reservations invisible until observed and preserve worker totals and the existing cap.
@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review October 22, 2026 01:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T01:06:16.073345Z afd5831 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: diagnostics-prometheus size: S labels Oct 22, 2026
@steipete
steipete merged commit cc4ca8d into main Oct 22, 2026
173 of 176 checks passed
@steipete
steipete deleted the steipete/perf-micro-main-gc-metric-missing-20260919 branch October 22, 2026 01:12
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…claw#180103)

Reserve the four native main-thread GC histograms before startup traffic can exhaust the shared series cap. Keep reservations invisible until observed and preserve worker totals and the existing cap.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: diagnostics-prometheus gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant