instance-usage
Bytes and requests served per instance, behind a read-only usage route (#1519). Consumer: Patrix's hosted dashboard (plaza's billing tick), enforcing monthly bandwidth from January 2027.
What changes
- Edge meter (
internal/edge/usagemeter.go): besides the per-host rows, counts each exchange under{UTC hour it completed, account, app, instance host}when the route is an instance. The far asset catch attributes only its own primary; an alias it delivers is unattributed (""). - Box flush (
internal/host/instance_usage.go): CAS-merges each drained batch intousage/instances/<box>/<date>/<account>/<app>.json, exactly once per batch and object (writer id per process, batch id per drain,appliedmarkers kept forever), oldest batch first per object, nothing started for buckets older than 24 h (dropped and counted asinstance_usage_dropped_byteson the box status).CARLOS_INSTANCE_USAGE=offin host.env stops counting and writing. Nothing underusage/edge/changes (pinned by golden tests). - Console (
internal/console/usagefrom.go,apiusage.go):usage/instances/@from.jsonholds the first whole month attribution is valid, written when the hostname history is verified active and moved forward only on a real break.GET /api/cli/apps/{account}/{app}/usage?month=YYYY-MMsums one app's objects for a month: a lower bound (Paul's ruling), 503 on any read fault (filed as theInstanceUsageReadjob), 409 beforefromor with the history not active, at most 10,000 instances, memo keyed by account, app and month. - Role
usage(internal/svcrole): outside Admin's union, one door (Exactly(Usage, Instance, Operate, Admin)), bound to one app, minted and rotated only while the switch is on; never offered on the browser form. - CLI
carlos usage --app <a> [--month YYYY-MM] [--json], docs indocs/site/cli.md, parity row (gap; console view filed as #1536). - Switch: the route, the mint and
@fromsit behindCONSOLE_INSTANCE_USAGE=true(off by default). Boxes count from the release.
Also: getJSON in the CLI now errors past 1 MiB instead of returning a silently truncated body (apimode_limit.go); a few functions moved verbatim to satisfy the code-health ratchet (internal/host/canary_count.go, internal/console/hostnorm.go).
Review history
- Design: Astra rounds 1-3 (spec rev 5, merged 9673143).
- Plan: Astra rounds 1-3, all NOT READY with a P1 in a new family each round; all fixed. No fourth round (my call, posted on #1519; Paul may ask for one).
- Per-task Astra (stopping rule 3): Task 2 meter, Task 3 flush, Task 5 role, Task 6 route: each READY AFTER FIXES in round 1, P2s fixed.
- Census: Astra APPROVED every unit and envelope, round 1, recorded on #280.
- Whole branch: Astra READY, round 1, no findings.
- Copy: Luna (one change); UX pass in docs/superpowers/notes/instance-usage-copy.md.
- Follow-up (P3): the oversized-object log line in
usagedays.gonames the economics sweep.
Testing: targeted tests per task (incl. a randomized exactly-once simulation and -race on the meter and flush), an end-to-end test across a month boundary, code-health and staticcheck clean, CI on amadan (see the CI tab).
Rollout (not done here): dev only after this merges and only if dev's hostname history is active (spec §12); flagship 2026-12-14 on Paul's go; first counted month January 2027.
Bytes and requests per instance behind a read-only usage route (#1519). Plan written; plan review round 1 under way.
Discussions
- No discussions on this branch yet.
Tasks 12/12 done
Activity
- paul@keymail.dev pushed a5d70b1da Merge origin/main (CI flake fixes) into instance-usage
- paul@keymail.dev pushed eae86e331 Merge origin/main (gvisor follow-ups) into instance-usage
- paul@keymail.dev pushed ff986b74c tests: teach three pins about instance usage
- paul@keymail.dev pushed 6075e5497 Reviews: census and whole-branch round 1, both READY
- paul@keymail.dev pushed ae3f77d9b Review briefs: instance usage census card and whole branch
- paul@keymail.dev pushed c5cdec97c census: re-propose instance-usage after the gate fix's moves
- paul@keymail.dev pushed de2f92037 Untrack a scratch report committed by mistake
- paul@keymail.dev pushed f097f2e30 gate: fix SA1026 and the code-health ratchet for instance usage
- paul@keymail.dev pushed b0280ed7a census: instance-usage card, overlay and record-write entries
- paul@keymail.dev pushed 6478b5c62 usage: an end-to-end test across a month boundary
- paul@keymail.dev pushed 14aabe050 Reviews: Task 6 round 1 findings
- paul@keymail.dev pushed 2f26b3e70 console: usage review R1: bounded start check, overflow-checked sums
- paul@keymail.dev pushed be51dac79 parity: file wp-instance-usage as discussion 1536
- paul@keymail.dev pushed 4f86ebf5d testdata: golden cases for carlos usage and the usage role help
- paul@keymail.dev pushed 5f7360152 cli: carlos usage, an app's bytes per instance this month
- paul@keymail.dev pushed 7239d9dcb Review brief: instance usage Task 6; job label approved
- paul@keymail.dev pushed 93887f31c console: the instance usage route and its start month
- paul@keymail.dev pushed 3974b2954 Reviews: Task 5 round 1 findings
- paul@keymail.dev pushed 928e5f8ca console: usage review R1: linked reads, rotation switch, CLI help
- paul@keymail.dev pushed 3acdc080d Review brief: instance usage Task 5, the usage role
- paul@keymail.dev pushed bf47d9cd5 console: a usage role and its one switched door
- paul@keymail.dev pushed 08293bdd4 usage: pin the edge family against the instance family
- paul@keymail.dev pushed 886a33a33 Reviews: Task 3 round 1 findings
- paul@keymail.dev pushed faf9d700a host: instance flush review R1: exact horizon, live rivals, log once
- paul@keymail.dev pushed dbc92e9c1 Reviews: Task 2 round 1 findings; Task 3 brief
- paul@keymail.dev pushed d56ed0a99 edge: test a served response spanning midnight counts at completion
- paul@keymail.dev pushed 964f7b7ce host: flush instance counts once per batch into their date
- paul@keymail.dev pushed 9ece53c64 Review brief: instance usage Task 2, the meter
- paul@keymail.dev pushed d13762193 edge: count bytes per instance by the hour each exchange ends
- paul@keymail.dev pushed e3c40ee38 Plan: declare the usage read as a request job (round 3 fix)