Skip to content

feat(usage): derive compute-usage rollups and prune the raw compute log (RIG-2872) - #1513

Open
rigel-mintaka wants to merge 2 commits into
mainfrom
compass-server/rig-2872-compute-rollups
Open

rigel-mintaka wants to merge 2 commits into
mainfrom
compass-server/rig-2872-compute-rollups

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

The compute-usage event log from the previous PR gets the rest of the usage-store contract: derived rollups, a retention policy, and an in-memory reference checked by the same contract suite as Postgres.

Changes

  • Migration 0005_compute_usage_rollups.sql adds hourly and daily rollups keyed by tenant, bucket, owner, and agent (active_ms, intervals), plus a compute prune horizon. Tenant RLS and grants match the token rollups.
  • An AFTER INSERT trigger on compute_usage_events rolls up each end event. Every end-writing path (release, runner sweep, re-point, orphan sweep) is covered in the same transaction. Duration is split across UTC hour and day buckets; an interval counts once, in its starting bucket. Open intervals contribute nothing.
  • RebuildComputeUsageRollups recomputes rollups from the prune horizon using the same clipping rule as the trigger.
  • PruneComputeUsageBefore deletes both events of intervals that ended before the cutoff day, never an open start, and keeps rollups. The daily RetentionSweeper prunes token and compute logs with the same window.
  • usage.Store gains ComputeUsageSeries, RebuildComputeUsageRollups, and PruneComputeUsageBefore. The memory backend is the reference implementation.

Verification

  • Contract suite on memory and Postgres: bucket splits across hour and day, open-interval exclusion, rebuild equals incremental (including across a prune horizon and many crossing intervals), prune keeps rollups and open starts, tenant isolation.
  • pgtest race: ./internal/usage, ./internal/store, ./internal/runnerhub, ./server, ./cmd/compass-server all ok. sqlc drift, migration gate, nilaway, and golangci-lint pass.

Refs RIG-2872

Co-authored-by: Matt Wilkinson matt@rigel.build

@linear-code

linear-code Bot commented Oct 3, 2026

Copy link
Copy Markdown

RIG-2872

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Compass engineering docs preview: https://compass-server-rig-2872-comp-ueya.compass-eng-docs.pages.dev

Deployed from compass-server/rig-2872-compute-rollups at 68cc4c1.

Changed pages:

@rigel-mintaka
rigel-mintaka force-pushed the compass-server/rig-2872-compute-rollups branch from 2933f2d to a342064 Compare October 3, 2026 17:11
@rigel-mintaka
rigel-mintaka force-pushed the compass-server/rig-2872-compute-rollups branch from a342064 to 64138a8 Compare October 3, 2026 20:26
@mattwilkinsonn
mattwilkinsonn added this pull request to stack #1560 October 3, 2026 21:57
@rigel-mintaka
rigel-mintaka force-pushed the compass-server/rig-2872-compute-rollups branch 3 times, most recently from c6a2703 to 0ba7873 Compare October 4, 2026 13:13
Base automatically changed from compass-server/rig-2872-compute-intervals to main October 4, 2026 14:09
@trunk-io

trunk-io Bot commented Oct 4, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@rigel-mintaka
rigel-mintaka force-pushed the compass-server/rig-2872-compute-rollups branch 2 times, most recently from af5cd13 to ffcb49a Compare October 5, 2026 18:22
@rigel-mintaka
rigel-mintaka marked this pull request as ready for review October 5, 2026 18:46
…og (RIG-2872)

Rebuilt on the collapsed migration baseline as 0002_compute_usage_rollups.sql.

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@rigel-mintaka
rigel-mintaka force-pushed the compass-server/rig-2872-compute-rollups branch from ffcb49a to 8b595a1 Compare October 6, 2026 05:03
Co-authored-by: Matt Wilkinson <matt@rigel.build>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant