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

Fleet graph: the selection's spend and runs over time beside the table #456

Closed opened this in answer to
Closed without merging

This adds a fleet graph: one chart per window showing a set of repositories' spend and runs, for the last 24 hours by UTC hour and the last 14 days by UTC day. Bars are stacked per repository, and the same numbers sit in a table beside the chart. The SVG is drawn on the server (no chart library).

Notes

stopped closed without shipping deploy 057ae23

opened this

This adds a fleet graph: one chart per window showing a set of repositories' spend and runs, for the last 24 hours by UTC hour and the last 14 days by UTC day. Bars are stacked per repository, and the same numbers sit in a table beside the chart. The SVG is drawn on the server (no chart library). It reads from the usage ledger, so a run counts in the hour or day it ended, at the provider's reported cost in US dollars. The full forge.json check passed (610 tests), and the new test/fleet-graph.test.ts is now part of that check.

What to look at

  • src/core/usage.ts: usageBuckets adds up the ledger per repository per hour or day in one grouped query. It groups by the first characters of the timestamp, so a run near midnight can't land on the wrong side because of rounding.
  • src/actions/fleet-graph.ts: the shared data behind the page, the CSV and the API.
    • The selection (?repo=owner/name, repeated) is checked at the boundary. A malformed name, or more than 100 names, gets a 422.
    • With no ?repo=, it shows every repository the viewer can write that spent anything in the last 14 days.
    • Only repositories the viewer can write are shown, because spend is the owner's to see. Names that don't exist and names the viewer can't see are counted together, so neither is told apart from the other.
    • Past eight repositories, the smallest spenders share one grey series, "N others".
    • fleetGraphFor lets the fleet table (#446) pass in a selection it has already resolved and checked.
  • src/web/fleet-graph.ts: the SVG, the table, the stated assumptions, and a small redraw script. The scale is written down in the file. The redraw fetches /fleet/graph/live every 30 s while the tab is visible, and at once on a forge:fleet-op DOM event, so an operation's effect shows within a minute.
  • src/web/pages/fleet-graph.ts and routes: GET /fleet/graph (the page, with the selection in its URL), /fleet/graph/live, /fleet/graph.csv, and GET /api/v1/fleet/graph (JSON).
  • docs/APPS.md describes it.

The tests check bucket boundaries and bar heights against hand calculations, that one owner can't see another's spend, and that a bad repository name echoed back in the error is escaped. One fixture changed while writing them: the first account is the site admin and can write everything, so the test makes a separate admin first. One assertion was too strict: the response repeats the caller's own asked names, so the test now checks only what is drawn.

Left out on purpose

  • The repo autonomy:… spent>50 query language belongs to #446 and the operations to #447; both are in progress elsewhere. For now the selection is a list of owner/name.
  • When an operation lands, the page redraws only if something sends forge:fleet-op — nothing does yet, so until #447/#448 do, the 30-second poll is what shows the effect. That's within a minute either way.
  • Nothing is pushed over SSE: the stream works per repository and a browser can hold only 3 connections.
  • Runs that are queued or still running don't appear until they end, because the ledger only gets a line when a run finishes.

Try it: sign in, open /fleet/graph (or /fleet/graph?repo=owner/name&repo=owner/other), then use the "Table file" and "JSON" buttons, or print the page.

🤖 Generated with Claude Code

Closes #449

4 earlier comments
commented

Operator: main moved under this branch (forge.json's check command was shortened, among others). Merge main into the branch, resolve the conflicts keeping this change's intent, run the check locally, and push.

commented

The fleet graph shows a selection's spend and runs by UTC hour or day, next to the selection's table. It reads one aggregate from the ledger: usageBuckets in src/core/usage.ts groups runs by the hour or day prefix of their ISO end time. reposWithUsage lists the repositories with ledger lines since a given time. The graph is drawn server-side by actions/fleet-graph.ts and covered by test/fleet-graph.test.ts.

Main is now merged in. It had two conflicts:

  • forge.json: uses main's shortened check command, with fleet-graph added after usage so the graph's tests still run in the check.
  • src/core/usage.ts: keeps this branch's usageBuckets and reposWithUsage and main's new topUsage side by side; neither changes the others.

The full check (type check plus the three test shards) ran once with one failure: a test in apps-adversarial ("private grant: forged, tampered, expired, wrong-env, and open-redirect are all refused") went over its 60-second limit. This change doesn't touch that file. It passed on a rerun of that file alone (68/68), and fleet-graph and usage pass (23/23), but the whole check hasn't been rerun clean. If the slowness under the full parallel run happens again, the forge's check on this push will fail the same way.

To try it, open a fleet selection on the preview and switch the graph between hours and days.

🤖 Generated with Claude Code

commented

The fleet graph shows a selection's spend and runs by UTC hour or day, next to the selection's table. It reads one aggregate from the ledger: usageBuckets in src/core/usage.ts groups runs by the hour or day prefix of their ISO end time. reposWithUsage lists the repositories with ledger lines since a given time. The graph is drawn server-side by actions/fleet-graph.ts and covered by test/fleet-graph.test.ts.

Main is merged in again. The only conflict was the check command in forge.json. It now uses main's list, which adds crew-parks, and keeps fleet-graph after usage so the graph's tests still run in the check. The earlier merge kept main's topUsage next to usageBuckets and reposWithUsage in src/core/usage.ts; that is unchanged.

The full check from forge.json passes locally after the merge: the type check plus all three test shards, 700 tests across 48 files, none failing.

To try it, open a fleet selection on the preview and switch the graph between hours and days.

🤖 Generated with Claude Code

commented

The fleet graph shows a selection's spend and runs by UTC hour or day, next to the selection's table. It reads one aggregate from the ledger: usageBuckets in src/core/usage.ts groups runs by the hour or day prefix of their ISO end time. reposWithUsage lists the repositories with ledger lines since a given time. The graph is drawn server-side by actions/fleet-graph.ts and covered by test/fleet-graph.test.ts.

Main is merged in again. The only conflict was the check command in forge.json. It now uses main's list, which adds told-by, and keeps fleet-graph after usage so the graph's tests still run in the check. The earlier merges are unchanged: main's topUsage sits next to usageBuckets and reposWithUsage in src/core/usage.ts, and the check also runs crew-parks.

The full check from forge.json passes locally after the merge: the type check plus all three test shards, 705 tests across 49 files, none failing.

To try it, open a fleet selection on the preview and switch the graph between hours and days.

🤖 Generated with Claude Code

commented

Parked by the crew: main moved under it 2 times and the branch could not be brought up to date (forge.json)

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs