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

Observability 1: GET /metrics speaks OpenMetrics - the forge's own series, ready for real Grafana #3741

Parked opened this in answer to
Closed without merging

GET /metrics now answers OpenMetrics text (application/openmetrics-text; version=1.0.0, ends in # EOF). It covers most of the series the issue asked for; ask→live seconds, red-main minutes and apps up/asleep are left out. The new tests and the design-audit and OpenAPI tests pass here.

Notes

stopped parked by the crew deploy fe7e123

opened this

GET /metrics now answers OpenMetrics text (application/openmetrics-text; version=1.0.0, ends in # EOF). It covers most of the series the issue asked for; ask→live seconds, red-main minutes and apps up/asleep are left out. The new tests and the design-audit and OpenAPI tests pass here. I could not run tsc in this sandbox (bun install fails on a read-only tempdir), so the type check is untested until the forge's check runs.

What it does

  • Reading it needs an admin's bearer token. A session, a password, a member's token or no credential gets the same 404 as an unknown path. Nothing new is stored: each scrape reads the tables the forge already keeps, with no new dependency.
  • The format is written by src/system/openmetrics.ts, which escapes label values and throws on an illegal name. The series are collected in src/system/metrics.ts, and the route is src/http/metrics.ts.
  • Series:
    • Build info.
    • Pulls merged.
    • Releases by result.
    • Check runs by state, check wall time, and queue depth.
    • Crew runs by member and state, and crew spend by member.
    • HTTP latency histogram by route pattern, in seconds.
    • Cell CPU and memory.
    • App count.
  • docs/METRICS.md lists every series with its type and labels, and includes a Prometheus scrape config.

Why the last attempt failed. Registering GET /metrics made the design-audit test count it as a page. I added metrics$ to that test's NOT_PAGES list. The test was wrong, since /metrics is a machine endpoint like /releases.json.

Tests. test/metrics.test.ts checks:

  • A strict grammar parse of a scrape.
  • The 404 for an anonymous caller, a non-admin token and a bad token.
  • That a release insert and a real request each move their series.
  • Label escaping.

Left out

  • Ask→live seconds, red-main minutes and apps up/asleep. Each needs a source I did not wire in; they are listed as follow-ups in the doc.
  • A separate scrape-token type. An admin-owned token does the job and can be revoked on its own.
  • Counters are totals over rows still kept. Route timing is pruned after 30 days, which a scraper reads as a counter reset.

Try it. Mint an admin token at /settings/tokens, then run curl -H "authorization: Bearer $T" $FORGE_URL/metrics.

Closes #3690

commented

GET /metrics now answers OpenMetrics text (application/openmetrics-text; version=1.0.0, ends in # EOF). It covers most of the series the issue asked for; ask→live seconds, red-main minutes and apps up/asleep are left out. The new tests and the design-audit and OpenAPI tests pass here. I could not run tsc in this sandbox (bun install fails on a read-only tempdir), so the type check is untested until the forge's check runs.

What it does

  • Reading it needs an admin's bearer token. A session, a password, a member's token or no credential gets the same 404 as an unknown path. Nothing new is stored: each scrape reads the tables the forge already keeps, with no new dependency.
  • The format is written by src/system/openmetrics.ts, which escapes label values and throws on an illegal name. The series are collected in src/system/metrics.ts, and the route is src/http/metrics.ts.
  • Series:
    • Build info.
    • Pulls merged.
    • Releases by result.
    • Check runs by state, check wall time, and queue depth.
    • Crew runs by member and state, and crew spend by member.
    • HTTP latency histogram by route pattern, in seconds.
    • Cell CPU and memory.
    • App count.
  • docs/METRICS.md lists every series with its type and labels, and includes a Prometheus scrape config.

Why the last attempt failed. Registering GET /metrics made the design-audit test count it as a page. I added metrics$ to that test's NOT_PAGES list. The test was wrong, since /metrics is a machine endpoint like /releases.json.

Tests. test/metrics.test.ts checks:

  • A strict grammar parse of a scrape.
  • The 404 for an anonymous caller, a non-admin token and a bad token.
  • That a release insert and a real request each move their series.
  • Label escaping.

Left out

  • Ask→live seconds, red-main minutes and apps up/asleep. Each needs a source I did not wire in; they are listed as follow-ups in the doc.
  • A separate scrape-token type. An admin-owned token does the job and can be revoked on its own.
  • Counters are totals over rows still kept. Route timing is pruned after 30 days, which a scraper reads as a counter reset.

Try it. Mint an admin token at /settings/tokens, then run curl -H "authorization: Bearer $T" $FORGE_URL/metrics.

commented

Parked by the crew: the check failed ("app.looks is the router's top-level pages minus the not-a-page list") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs