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

GET /metrics serves forge_http_request_duration_seconds to an admin or an admin's token, listed as not-a-page #3881

Parked opened this
Closed without merging

GET /metrics now serves forgehttprequestdurationseconds as OpenMetrics text to a site admin. The new tests and the two not-a-page tests pass. I couldn't run the type check: bun install and bun x tsc both fail in this sandbox with a read-only tempdir error and nodemodules has no tsc.

Notes

stopped parked by the crew deploy c55d492

opened this

GET /metrics now serves forge_http_request_duration_seconds as OpenMetrics text to a site admin. The new tests and the two not-a-page tests pass. I couldn't run the type check: bun install and bun x tsc both fail in this sandbox with a read-only tempdir error and node_modules has no tsc. The forge's check will be the first type check.

  • Route: src/metrics/forge.ts builds the histogram and src/http/server.ts gets one route. The metric is labelled by route pattern and uses EDGES_MS converted to seconds as buckets. It is read from route_timing for the current and previous hour's rows (rows are hourly, so "last hour" is a little over an hour).
  • Access: no credentials gets 401, a non-admin gets 404, and an admin session or any-scope admin token gets 200. Every answer carries cache-control: no-store. The 200 carries the security headers, and I tested nosniff and referrer-policy.
  • Flush before read: src/core/route_timing.ts gains timingOf(db), a single recorder per database. The server now uses it to record requests, and /metrics flushes it before reading. That is what lets a request show up in its bucket straight away instead of after the roughly one-second flush delay.
  • Not-a-page lists: /metrics is added to NOT_PAGES in test/design-audit.test.ts and NOT_A_PAGE in test/forge-looks.test.ts. docs/design/audit.md is unchanged.
  • Docs: docs/METRICS.md lists the one family with its type, label and meaning, and shows a Prometheus scrape config that reads an admin's token from a file.
  • Tests: test/metrics-route.test.ts covers the 401, the 404 for a non-admin, the 200 for an admin ro token with its headers, and a recorded request moving its bucket. It also fails if /metrics serves a family docs/METRICS.md doesn't list.

I did not add other families, and I did not time the read against the 50 ms bound; it is one indexed hourly query.

Closes #3749

commented

GET /metrics now serves forge_http_request_duration_seconds as OpenMetrics text to a site admin. The new tests and the two not-a-page tests pass. I couldn't run the type check: bun install and bun x tsc both fail in this sandbox with a read-only tempdir error and node_modules has no tsc. The forge's check will be the first type check.

  • Route: src/metrics/forge.ts builds the histogram and src/http/server.ts gets one route. The metric is labelled by route pattern and uses EDGES_MS converted to seconds as buckets. It is read from route_timing for the current and previous hour's rows (rows are hourly, so "last hour" is a little over an hour).
  • Access: no credentials gets 401, a non-admin gets 404, and an admin session or any-scope admin token gets 200. Every answer carries cache-control: no-store. The 200 carries the security headers, and I tested nosniff and referrer-policy.
  • Flush before read: src/core/route_timing.ts gains timingOf(db), a single recorder per database. The server now uses it to record requests, and /metrics flushes it before reading. That is what lets a request show up in its bucket straight away instead of after the roughly one-second flush delay.
  • Not-a-page lists: /metrics is added to NOT_PAGES in test/design-audit.test.ts and NOT_A_PAGE in test/forge-looks.test.ts. docs/design/audit.md is unchanged.
  • Docs: docs/METRICS.md lists the one family with its type, label and meaning, and shows a Prometheus scrape config that reads an admin's token from a file.
  • Tests: test/metrics-route.test.ts covers the 401, the 404 for a non-admin, the 200 for an admin ro token with its headers, and a recorded request moving its bucket. It also fails if /metrics serves a family docs/METRICS.md doesn't list.

I did not add other families, and I did not time the read against the 50 ms bound; it is one indexed hourly query.

commented

Parked by the crew: the check failed ("reserved names > every top-level page of the forge is a reserved name") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs