Skip to content

feat: filter Amberflo usage queries by project_id dimension#1317

Closed
mattdjenkinson wants to merge 1 commit into
mainfrom
feat/usage-project-id-dimension
Closed

feat: filter Amberflo usage queries by project_id dimension#1317
mattdjenkinson wants to merge 1 commit into
mainfrom
feat/usage-project-id-dimension

Conversation

@mattdjenkinson

@mattdjenkinson mattdjenkinson commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Usage queries sent to Amberflo are currently scoped only by customerId (the billing account UID). When multiple projects share a billing account, or when the per-project billing account binding is absent, there is no way to isolate a single project's consumption in the response. This PR adds project_id as an optional dimension filter on all Amberflo /usage/sparse requests so the portal can scope results to a specific project once events carry that dimension.

The change is additive and backwards compatible: when projectId is undefined (org-wide views), the filter object is unchanged. When set, dimensions: { project_id: [projectId] } is spread into the existing customerId filter.

Key behaviors:

  • fetchUsageForCustomerIds accepts an optional projectId that is forwarded as an Amberflo dimension filter
  • fetchProjectUsage threads the projectId it already resolves through to the shared fetch helper
  • Org-wide queries (fetchOrgUsage) are unaffected — no dimension filter when no project is selected

Test plan

Notes for reviewers

This PR is intentionally a no-op until milo-os/billing#60 ships the consumer-side injection of project_id as a system dimension. Until that lands, the dimension filter is sent to Amberflo but matches nothing, so results are unchanged from today.

Confirm the Amberflo /usage/sparse filter format accepts dimensions: { key: string[] } — if the API expects a different shape (e.g. dimensionFilters: [{ key, values }]), only the spread in queryUsage needs updating.

When a project is selected, include a dimensions filter on the Amberflo
/usage/sparse request so results are scoped to events emitted for that
specific project, not the entire billing account.

Key changes:
- Add optional projectId param to fetchUsageForCustomerIds
- Spread dimensions: { project_id: [projectId] } into the Amberflo
  filter when projectId is set; no-ops when absent (org-wide queries)
- Thread projectId through fetchProjectUsage to the shared fetch helper

Requires the billing consumer to inject project_id as a system dimension
after event validation passes (see infra/docs/project-id-dimension-billing-change.md).
@github-actions

Copy link
Copy Markdown

🧪 Test Summary

Job Status
Bun Unit Tests ✅ success
E2E Regression (0) ⏭️ pending
E2E Regression (1) ⏭️ pending
E2E Regression (2) ⏭️ pending
E2E Regression (3) ⏭️ pending
E2E Smoke ✅ success
Unit Tests ✅ success

View workflow run

📎 Artifacts

Videos and screenshots from failed E2E tests:

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