Skip to content

test(billing): shadow-mode meter validation (ENG-2879)#6451

Draft
Flo4604 wants to merge 1 commit into
eng-2897-implement-billing-for-active-keysfrom
eng-2879-validate-meter-query-in-shadow-mode
Draft

test(billing): shadow-mode meter validation (ENG-2879)#6451
Flo4604 wants to merge 1 commit into
eng-2897-implement-billing-for-active-keysfrom
eng-2879-validate-meter-query-in-shadow-mode

Conversation

@Flo4604

@Flo4604 Flo4604 commented Jun 13, 2026

Copy link
Copy Markdown
Member

Validates the Deploy meter query before anyone is billed (ENG-2879), the gate in front of ENG-2880. Two halves: fixture tests that prove the query maps to a known dollar bill, and a shadow command that diffs live ClickHouse usage against what Stripe actually holds.

Fixtures (pkg/clickhouse)

  • TestMeterUsageHandComputedBill: seeds a workload whose bill is known by arithmetic, not history — one container at exactly 1 vCPU, 2 GiB memory, 10 GiB disk steady for one hour, plus 240 MiB egress. Runs the production GetInstanceMeterUsage, asserts the natural units (3600 CPU-s, 2 GiB-hours, 10 GiB-hours, 240 MiB), then converts through the worker's unit path and the Terraform catalog rates to a hand-computed $0.06387555. If the query drifts, the dollar figure moves and the test fails.
  • TestMeterUsageStraddlesWindow: a container's life crosses both window edges; only intervals with both endpoints in-window are billed, so the last in-window sample contributes no delta. Documents the month-boundary rule: at most one ~15s sub-sample interval is dropped at the edge (under-count, never over-charge).

These join the existing meter mechanics tests (clean series, 2-min gap drop, restart boundary, multi-workspace, window exclusion).

Shadow command (dev stripe shadow)

mise run unkey -- dev stripe shadow --workspace ws_... --customer cus_... [--month YYYY-MM] recomputes a workspace's month-to-date usage straight from ClickHouse (the same queries + unit conversions the worker uses) and diffs it per meter against the value Stripe is holding (the "last"-aggregated meter event summary = the latest MTD value the hourly push delivered). Prints a per-meter clickhouse-vs-stripe table with a verdict and exits non-zero on structural drift.

Tolerance is 0.1%: the hourly push lags the live query by up to an hour, so small gaps are expected staleness, not bugs. For a zero-drift check, run the push (or trigger the restate handler) immediately before.

How to validate end to end (the operator's pre-launch check)

  1. unkey dev seed checkpoints for a workspace into local ClickHouse.
  2. Let the hourly push fire (or trigger it) so meter events land on the test-clock customer.
  3. dev stripe shadow --workspace ... --customer ... -> every meter "ok".
  4. dev stripe clock advance to roll the month and confirm the close stamps and finalizes correctly.

Verified: bazel test //pkg/clickhouse:clickhouse_test //cmd/dev/stripe:stripe_test, full build, fmt.

@linear-code

linear-code Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

ENG-2879

@vercel

vercel Bot commented Jun 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview, Comment Jun 19, 2026 9:22am
design Ready Ready Preview, Comment Jun 19, 2026 9:22am

Request Review

@Flo4604

Flo4604 commented Jun 13, 2026

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by jj-ryu.

@Flo4604 Flo4604 force-pushed the eng-2879-validate-meter-query-in-shadow-mode branch from 3fd3e35 to 410cf69 Compare June 16, 2026 16:49
@Flo4604 Flo4604 force-pushed the eng-2897-implement-billing-for-active-keys branch from 952a8eb to 83862e9 Compare June 16, 2026 17:38
@Flo4604 Flo4604 force-pushed the eng-2879-validate-meter-query-in-shadow-mode branch from 410cf69 to 6d1d000 Compare June 16, 2026 17:38
@Flo4604 Flo4604 force-pushed the eng-2897-implement-billing-for-active-keys branch from 83862e9 to 30a90e0 Compare June 16, 2026 18:17
@Flo4604 Flo4604 force-pushed the eng-2879-validate-meter-query-in-shadow-mode branch from 6d1d000 to bcae9fb Compare June 16, 2026 18:17
@Flo4604 Flo4604 force-pushed the eng-2897-implement-billing-for-active-keys branch from 30a90e0 to f9a8821 Compare June 16, 2026 18:38
@Flo4604 Flo4604 force-pushed the eng-2879-validate-meter-query-in-shadow-mode branch from bcae9fb to e7688d4 Compare June 16, 2026 18:39
@Flo4604 Flo4604 force-pushed the eng-2897-implement-billing-for-active-keys branch from f9a8821 to 65eeadb Compare June 17, 2026 17:43
@Flo4604 Flo4604 force-pushed the eng-2879-validate-meter-query-in-shadow-mode branch from e7688d4 to f1298d4 Compare June 17, 2026 17:43
@Flo4604 Flo4604 force-pushed the eng-2897-implement-billing-for-active-keys branch from 65eeadb to 85b64ed Compare June 17, 2026 18:45
@Flo4604 Flo4604 force-pushed the eng-2879-validate-meter-query-in-shadow-mode branch from f1298d4 to e4c9ed4 Compare June 17, 2026 18:45
@Flo4604 Flo4604 force-pushed the eng-2897-implement-billing-for-active-keys branch from 85b64ed to c048de0 Compare June 17, 2026 19:00
@Flo4604 Flo4604 force-pushed the eng-2879-validate-meter-query-in-shadow-mode branch from e4c9ed4 to 090e8b9 Compare June 17, 2026 19:00
@Flo4604 Flo4604 force-pushed the eng-2897-implement-billing-for-active-keys branch from c048de0 to 4409850 Compare June 17, 2026 20:57
Fixture tests proving the meter query maps to known dollar bills, plus a
'dev stripe shadow' command that diffs a workspace's live ClickHouse usage
against the values Stripe is holding for its meters.
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