Skip to content

fix(prometheus): prevent worker metrics from starving core families - #180117

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-metric-family-budgets-20261022
Oct 22, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-metric-family-budgets-20261022

Conversation

@steipete

@steipete steipete commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes missing run, model, tool, GC, and memory metrics when worker/RPC startup traffic consumes the Prometheus exporter's shared series cap. Follow-up to #180103, which protected only the four native main-GC histograms.

User Impact

Late metric families retain reserved capacity, and operators can identify partial coverage through openclaw_prometheus_family_series_dropped_total{family="..."} plus one warning per family per process. Existing openclaw_prometheus_series_dropped_total remains available.

The aggregate-entry limit stays 2,048. A busy family now stops admitting new label sets at 128, or when shared capacity fills. Existing samples keep updating. No labels or histogram buckets are rewritten; high-cardinality coverage can be partial and the drop counter identifies the affected family.

Why This Change Was Made

The old first-come cap counted stored {metric, labels} aggregates, not rendered bucket rows. More worker telemetry (including #179872) could consume capacity before runs completed. Clearing and rebuilding memory gauges also exposed their slots to other families. Reducing histogram buckets alone would not repair admission.

The metric store now owns a typed catalog of 134 families with 1,204 reserved entries and 844 shared entries, plus the 128-entry family ceiling. Core run/model/tool/GC families reserve 32 entries; memory reserves cover bounded thread/slot/heap-space layouts; other families reserve four. The catalog records every exact reserve and requires new producers to choose one. Unused reservations remain available for future families. Main-GC startup reservation remains within its family budget.

Drop accounting bypasses admission and uses only cataloged family names. It counts rejected observations, including repeated attempts at a rejected label set. Gauge replacement releases the correct family/shared accounting. Exporter reset clears metrics and counts while preserving process-wide warning suppression.

Production code grows by 201 lines, chiefly the explicit family catalog and admission/drop accounting required for this observability contract. This replaces the shared first-come admission policy; it adds no configuration or second admission path. The existing benchmark fixture is updated to fill all reserves before shared capacity so its retained-size workload still means 2,048 entries.

Evidence

A synthetic exporter regression sends 400 worker request classes and 426 RPC methods before late core events and repeated memory snapshots. On the unchanged store from cc4ca8d1, the core-family assertion fails. With this change, it passes:

Exported label sets Before After
Run count / duration (each) 0 4
Harness count / duration (each) 0 4
Model-call count / duration / usage-duration (each) 0 4
Tool count / duration (each) 0 4
GenAI token usage 0 8
Worktree / secret egress / HTTP cancellation (each) 0 1
Heap-used ratio / worker count (each) 0 9
Code Mode worker heap 0 24
Chat-send phases 0 14
Main GC 4 4
RPC handler / admission / queue-wait / heap-delta (each) 0 56
Worker request phases 1,587 128

Across that identical synthetic sequence: 7 → 45 application metric families, 2,048 → 1,066 retained aggregates, and 38,877 → 21,719 rendered series, including drop diagnostics. The remaining capacity protects families not yet observed. Worker GC's repeated cumulative sample stays at 7 collections, not 14.

openclaw_gc_duration_seconds_count{kind="scavenge",reason="other",thread="main"} 2
openclaw_prometheus_family_series_dropped_total{family="openclaw_worker_request_phase_seconds"} 2672

Focused exporter tests: 46 passed, including the saturated exporter, all-family 2,048-entry bound, gauge replacement, reset, worker GC totals, and once-per-process warnings. Targeted plugin typecheck passed. Changed-file lint/format, the export-name guard, and both closure guards (22 tests) passed. The final subscription file also passed all 9 tests after fixture typing cleanup. Independent Codex review is clean through P2. Initial CI caught two missing required startedAt fields in the new synthetic phase-event fixtures. Those two fixture fields are corrected; the focused file (9 tests), lint, and independent review passed again. Production code and the measured counts are unchanged. Exact-head PR CI supplies the broad gates.

This is deterministic exporter/HTTP-handler proof with synthetic events, not a production scrape or a full Gateway boot. No production process, state, or configuration was changed. There is no wall-time, allocation, or memory-byte performance claim, and the cap was not increased.

@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:22
@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:37:36.073728Z af8e37d New commits
ℹ️ 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: L labels Oct 22, 2026
@steipete
steipete force-pushed the steipete/perf-micro-metric-family-budgets-20261022 branch from 6aa4517 to af8e37d Compare October 22, 2026 01:29
@steipete
steipete merged commit b98018c into main Oct 22, 2026
108 of 110 checks passed
@steipete
steipete deleted the steipete/perf-micro-metric-family-budgets-20261022 branch October 22, 2026 01:38
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…penclaw#180117)

* fix(prometheus): prevent worker metrics from starving core families

* test(prometheus): include timestamps in saturation phase events
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: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant