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 #114

Parked opened this
Closed without merging

I added Software/so101/src/live-metrics.ts and src/live-metrics.test.ts. They touch no route or page. The five new tests pass.

Notes

stopped parked by the crew deploy e71fd81

opened this

I added Software/so101/src/live-metrics.ts and src/live-metrics.test.ts. They touch no route or page. The five new tests pass. bun x tsc --noEmit printed only a read-only-tempdir warning and no type errors, but I couldn't confirm a clean exit.

  • LiveMetrics class: it has observe, count, gauge, snapshot, prometheus and summaryLine, and takes an injectable clock for tests.
  • Timings: observe keeps the last 256 samples in a fixed Float64Array ring. The snapshot gives p50, p95, count and sum using nearest-rank percentiles.
  • Counters: count uses 60 one-second buckets in fixed arrays. The rate is the sum over the last 60 seconds divided by 60, and the all-time total is kept as well.
  • Allocation: updates only write into those arrays. Sorting for percentiles happens in snapshot(), which does allocate.
  • Names: metric names must match [a-z_][a-z0-9_]* and be at most 64 characters, otherwise the call throws. Non-finite values are also refused.
  • Labels: the API has no caller-supplied labels, so the only label is the fixed quantile one on timings, which goes through escapeLabel. If you want caller-supplied labels, that needs an API addition.
  • Prometheus output: timings render as <name>_ms summaries, counters as <name>_total plus <name>_rate, and gauges as <name>.
  • Tests: they cover 10/200 ms p50/p95, the timing window dropping old samples, counters rolling off after 60 s, every non-comment prometheus() line parsing, and bad names being refused.

🤖 Generated with Claude Code

Closes #109

2 earlier comments
commented

I added Software/so101/src/live-metrics.ts and src/live-metrics.test.ts. They touch no route or page. The five new tests pass. bun x tsc --noEmit printed only a read-only-tempdir warning and no type errors, but I couldn't confirm a clean exit.

  • LiveMetrics class: it has observe, count, gauge, snapshot, prometheus and summaryLine, and takes an injectable clock for tests.
  • Timings: observe keeps the last 256 samples in a fixed Float64Array ring. The snapshot gives p50, p95, count and sum using nearest-rank percentiles.
  • Counters: count uses 60 one-second buckets in fixed arrays. The rate is the sum over the last 60 seconds divided by 60, and the all-time total is kept as well.
  • Allocation: updates only write into those arrays. Sorting for percentiles happens in snapshot(), which does allocate.
  • Names: metric names must match [a-z_][a-z0-9_]* and be at most 64 characters, otherwise the call throws. Non-finite values are also refused.
  • Labels: the API has no caller-supplied labels, so the only label is the fixed quantile one on timings, which goes through escapeLabel. If you want caller-supplied labels, that needs an API addition.
  • Prometheus output: timings render as <name>_ms summaries, counters as <name>_total plus <name>_rate, and gauges as <name>.
  • Tests: they cover 10/200 ms p50/p95, the timing window dropping old samples, counters rolling off after 60 s, every non-comment prometheus() line parsing, and bad names being refused.

🤖 Generated with Claude Code

commented

I haven't pushed anything for #114. The failure doesn't come from my change, so I couldn't find a code fix.

  • The failed run: it is the preview deploy, not the check. Its summary reads ready: /status answered 503 for 30s — … (arm 100.89.95.68:8101: reconnecting).
  • Why it's unrelated: the preview waits for /status to answer, and /status returns 503 while the app can't reach the physical arm at 100.89.95.68:8101. My two files are a new module and its test, and nothing imports them.
  • The check itself: it was still queued and hadn't run when I looked, so I have no log showing a test or type failure.
  • What I ran before pushing: bun test src/live-metrics.test.ts passes (5 tests) and bun x tsc --noEmit showed no type errors. I changed nothing since.

Changing the code to chase a 503 caused by the arm link would be guessing. If the check does fail once it runs, send me its log and I'll fix that. Otherwise the deploy probably needs a re-run once the arm is reachable.

commented

Parked by the crew: the preview's deploy failed in the place it ran, not in the change, and it could not be run again

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs