Public: anyone can read this; the crew can change it.

/metrics: forge_process_restarts_total and forge_child_processes{comm} #16864

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

/metrics now serves the two restart counters and a per-name child-process gauge, and the branch is pushed. The new tests, bun x tsc --noEmit and scripts/gate.ts pass. I did not run bun scripts/design-lint.ts (no src/web/ change) or the full suite.

Notes

opened this

/metrics now serves the two restart counters and a per-name child-process gauge, and the branch is pushed. The new tests, bun x tsc --noEmit and scripts/gate.ts pass. I did not run bun scripts/design-lint.ts (no src/web/ change) or the full suite.

  • Restart counters: forge_process_restarts_total is bootCounts().restarts and forge_process_unclean_restarts_total is unclean. Both are counters, read live from boots.json on each scrape.
  • Child processes: forge_child_processes{comm="…"} is a gauge with one series per name from census(processRows()). Label values go through the existing OpenMetrics escaping.
  • Code: a new processSources and processFamilies pair in src/metrics/forge.ts builds the three series, and forgeMetrics takes the sources as an optional last argument. The /metrics route in src/http/api.ts passes them in. I reused bootCounts, census and processRows unchanged and did not run similar.ts.
  • Docs: docs/METRICS.md lists the three new families.
  • Tests:
    • In test/metrics-forge.test.ts, a unit test checks the counts and the escaping of a quote in a command name.
    • In test/metrics-route.test.ts, a boot-and-scrape test checks that all three series appear.

I left out the terminal and web doors, since /metrics is a scrape endpoint. The first push was refused until a commit line said how to try it, so I added a Try: commit.

To try it, call GET /metrics with a read-only admin token and look for forge_process_restarts_total and forge_child_processes{comm="socat"}.

Closes #3727

commented

/metrics now serves the two restart counters and a per-name child-process gauge, and the branch is pushed. The new tests, bun x tsc --noEmit and scripts/gate.ts pass. I did not run bun scripts/design-lint.ts (no src/web/ change) or the full suite.

  • Restart counters: forge_process_restarts_total is bootCounts().restarts and forge_process_unclean_restarts_total is unclean. Both are counters, read live from boots.json on each scrape.
  • Child processes: forge_child_processes{comm="…"} is a gauge with one series per name from census(processRows()). Label values go through the existing OpenMetrics escaping.
  • Code: a new processSources and processFamilies pair in src/metrics/forge.ts builds the three series, and forgeMetrics takes the sources as an optional last argument. The /metrics route in src/http/api.ts passes them in. I reused bootCounts, census and processRows unchanged and did not run similar.ts.
  • Docs: docs/METRICS.md lists the three new families.
  • Tests:
    • In test/metrics-forge.test.ts, a unit test checks the counts and the escaping of a quote in a command name.
    • In test/metrics-route.test.ts, a boot-and-scrape test checks that all three series appear.

I left out the terminal and web doors, since /metrics is a scrape endpoint. The first push was refused until a commit line said how to try it, so I added a Try: commit.

To try it, call GET /metrics with a read-only admin token and look for forge_process_restarts_total and forge_child_processes{comm="socat"}.

commented

/metrics now serves forge_process_restarts_total, forge_process_unclean_restarts_total and forge_child_processes{comm}, and the child-process gauge is now bounded.

  • Bounded series (finding 1): forge_child_processes keeps the 10 most numerous command names, with ties broken by name. Every other name is summed into one comm="other" series, so a scrape carries at most 11 series. I took the top-N option rather than an allowlist, so new helper names show up without code changes. A cell can still pick a name that lands in the top 10, but it can no longer add series beyond that.
  • Test for the bound: a new test feeds in 202 distinct names and checks the 11-series cap, the counts for socat and bwrap, and the other sum.
  • Cached census (finding 2): the /proc walk now runs at most once every 5 seconds, so repeated scrapes in that window reuse the last result. A test checks that a second read within the window returns the cached census and a read after it does not. Boot counts are still read on every scrape. I did not measure the cost of one walk.
  • Order of checks (finding 3): unchanged. processSources is still called only after accountAdmin passes.
  • Docs: docs/METRICS.md describes the cap, the other series and the 5-second cache.
  • Checks: bun x tsc --noEmit is clean, and the metrics-forge and metrics-route tests pass (10 tests). gate.ts --fix rewrapped comments in one file and the commit includes it.

No door is needed: /metrics is a scrape endpoint.

To try it, scrape GET /metrics with a read-only admin token. forge_child_processes{comm="socat"} and forge_child_processes{comm="other"} should both appear, with at most 11 comm values in total.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs