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

Migrated from github.com/Trevato/SO-ARM100

src/live-metrics.ts: rolling counters and p50/p95, rendered as Prometheus text - a pure module with unit tests (re-run on today's main) #131

Closed opened this
Closed without merging

I added Software/so101/src/live-metrics.ts, a pure LiveMetrics module with tests in src/live-metrics.test.ts. The five new tests pass. I could not run bun x tsc --noEmit here: bun install failed with "unable to write files to tempdir: ReadOnlyFileSystem", so there were no types to check against.

Notes

stopped closed without shipping deploy 0dd9b9c

opened this

I added Software/so101/src/live-metrics.ts, a pure LiveMetrics module with tests in src/live-metrics.test.ts. The five new tests pass. I could not run bun x tsc --noEmit here: bun install failed with "unable to write files to tempdir: ReadOnlyFileSystem", so there were no types to check against. The forge's check will be the first type check.

No route or page changes.

  • API:

- observe(name, ms) keeps the last 512 timings per series and reports p50/p95 by nearest rank. - count(name, n) reports a per-second rate averaged over the last 60 one-second buckets. - gauge(name, value) stores the latest value. - snapshot() returns the three groups as plain objects. - prometheus() writes text format. - summaryLine() writes one log line.

  • Names: metric names and constructor label names and values must match [a-z_][a-z0-9_]*. Anything else throws. Label values are also escaped on output, and there is a cap of 256 series.
  • Allocation: each series gets its fixed Float64Array buffers the first time it is seen. After that, observe, count and gauge allocate nothing. snapshot() and prometheus() do allocate, because they copy and sort the window.
  • Clock and labels: the constructor is new LiveMetrics(now = Date.now, labels = {}). The clock is injectable, and the optional base labels go on every output line.
  • Output names: timings come out as <name>_ms{quantile="0.5"|"0.95"} plus <name>_ms_count. Rates come out as <name>_per_second. Gauges keep their own name.
  • Tests: the injected 10/200 ms timings give the right p50/p95, and the sample window rolls. Counters roll off after 60 seconds. Bad names are refused, and every non-comment line of prometheus() matches name{labels} value.

Non-finite numbers passed to observe, count or gauge are silently ignored rather than thrown.

🤖 Generated with Claude Code

Closes #127

2 earlier comments
commented

I added Software/so101/src/live-metrics.ts, a pure LiveMetrics module with tests in src/live-metrics.test.ts. The five new tests pass. I could not run bun x tsc --noEmit here: bun install failed with "unable to write files to tempdir: ReadOnlyFileSystem", so there were no types to check against. The forge's check will be the first type check.

No route or page changes.

  • API:

- observe(name, ms) keeps the last 512 timings per series and reports p50/p95 by nearest rank. - count(name, n) reports a per-second rate averaged over the last 60 one-second buckets. - gauge(name, value) stores the latest value. - snapshot() returns the three groups as plain objects. - prometheus() writes text format. - summaryLine() writes one log line.

  • Names: metric names and constructor label names and values must match [a-z_][a-z0-9_]*. Anything else throws. Label values are also escaped on output, and there is a cap of 256 series.
  • Allocation: each series gets its fixed Float64Array buffers the first time it is seen. After that, observe, count and gauge allocate nothing. snapshot() and prometheus() do allocate, because they copy and sort the window.
  • Clock and labels: the constructor is new LiveMetrics(now = Date.now, labels = {}). The clock is injectable, and the optional base labels go on every output line.
  • Output names: timings come out as <name>_ms{quantile="0.5"|"0.95"} plus <name>_ms_count. Rates come out as <name>_per_second. Gauges keep their own name.
  • Tests: the injected 10/200 ms timings give the right p50/p95, and the sample window rolls. Counters roll off after 60 seconds. Bad names are refused, and every non-comment line of prometheus() matches name{labels} value.

Non-finite numbers passed to observe, count or gauge are silently ignored rather than thrown.

🤖 Generated with Claude Code

commented

I added a check.run to forge.json, since the missing one is what failed the check. I haven't run the new command. I only confirmed the file still parses as JSON, and I pushed to the branch.

The command is bun install --cwd Software/so101 --frozen-lockfile && cd Software/so101 && bun x tsc --noEmit && bun test. The check block had only limits and no run.

This pull is the first one to get that block. check.run was already missing on main, so other pulls may hit the same failure until main gets it too.

The type check has still not run anywhere. The sandbox can't install the type packages, so the forge's check is where tsc will first run on live-metrics.ts. The five new tests in src/live-metrics.test.ts did pass locally.

src/live-metrics.ts is a pure module, and no route or page changed.

🤖 Generated with Claude Code

commented

Declined: the check now fails on main's forge.json, not on this pull's, and I can't change main. Run log: https://forge.open-platform.sh/trevato/arm/runs/01m5e19zj0atxrwcs55drqdsq7

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs