Skip to content

test(billing): pin usage subject to project name + fix metering doc#287

Closed
ecv wants to merge 1 commit into
mainfrom
fix/billing-usage-project-subject
Closed

test(billing): pin usage subject to project name + fix metering doc#287
ecv wants to merge 1 commit into
mainfrom
fix/billing-usage-project-subject

Conversation

@ecv

@ecv ecv commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Note

Repurposed after review. An earlier revision changed the VRL to build the subject from the project UID — that was wrong. The billing consumer attributes by project name, so the existing VRL (subject = project name) is correct and is unchanged here. This PR is now test + doc hardening only.

Summary

Attribution for gateway usage runs in the billing consumer (milo-os/billing, internal/controller/consumer): it strips projects/ from the CloudEvent subject and matches the remainder against BillingAccountBinding.spec.projectRef.name. So the subject must be projects/<project-name> — and the current VRL already does exactly that.

Two gaps let a wrong-identifier change (and a months-old misconception) look plausible. This PR closes both:

  • The e2e didn't pin the subject. The billing e2e accepted any single subject that carried the four CloudEvents, so a subject built from the wrong identifier (e.g. the namespace UID) still passed. It now asserts the subject is exactly projects/<project_name>, and guards that project_name differs from the namespace UID so a UID-based regression is actually distinguishable.
  • The doc mislabeled the key. http-traffic-metering.md called project_name a "dimension" and framed the namespace UID as the project identity — implying the subject should be the UID. Corrected: project_name is the attribution subject, with the consumer contract (subject → projectRef.name) now documented.

No VRL behavior change.

Test plan

  • chainsaw YAML parses
  • Billing e2e passes with the name-pinned subject assertion
  • Confirm the assertion fails if the subject is built from the UID (regression guard works)

Refs #286, datum-cloud/infra#3444.

@ecv

ecv commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

e2e verified — both directions

Ran E2E Tests on the fix branch and on a throwaway control branch (this fix's hardened e2e applied on top of the pre-fix VRL):

Branch billing-http-metering
fix/billing-usage-project-subject (this PR) — run PASS (84.6s)
test/e2e-catches-regression (pre-fix VRL) — run FAIL (61.6s)

So the fix makes the billing test pass, and the hardened subject assertion fails against the old VRL — it genuinely catches the attribution regression.

Note

The fix-branch run is overall red only because of an unrelated test, gateway-invalid-certificate, which passed in the control run — it's flaky, not caused by this change. Billing is green.

Control branch deleted (was verification-only).

@ecv
ecv marked this pull request as ready for review July 16, 2026 17:40
@ecv
ecv requested review from mattdjenkinson and scotwells July 16, 2026 17:40

@scotwells scotwells left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't attribute projects by UID. It's supposed to be the project name

@ecv
ecv marked this pull request as draft July 16, 2026 18:24
The billing consumer (milo-os/billing) attributes usage by PROJECT NAME:
it strips "projects/" from the CloudEvent subject and matches the
remainder against BillingAccountBinding.spec.projectRef.name. The subject
must therefore be projects/<project-name>; a subject built from the
route_name namespace UID never resolves.

The billing e2e previously accepted any single subject carrying the four
CloudEvents, so a subject built from the wrong identifier passed
undetected. Pin the assertion to projects/<project_name> and guard that
project_name differs from the namespace UID, so a UID-based subject
regression fails the test.

Also correct the HTTP metering enhancement doc, which described
project_name as merely a "dimension" — it is the attribution subject.
Document the consumer contract (subject -> projectRef.name) so future
changes don't repeat the confusion.

No VRL behavior change. Refs #286, datum-cloud/infra#3444.
@ecv
ecv force-pushed the fix/billing-usage-project-subject branch from 6a0a801 to 11d14c3 Compare July 16, 2026 20:14
@ecv ecv changed the title fix(billing): attribute usage to project UID, not display name test(billing): pin usage subject to project name + fix metering doc Jul 16, 2026

@scotwells scotwells left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is leaking a lot of implementation details in the doc. The NSO repo shouldn't know about what the billing repo does internally with usage events because that information may go stale over time.

@ecv ecv closed this Jul 16, 2026
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.

2 participants