Skip to content

feat(billing): Deploy spend-cap detection and budget alerts (ENG-2904)#6486

Draft
Flo4604 wants to merge 1 commit into
eng-2908-build-go-email-sending-package-resendfrom
eng-2904-deploy-spend-cap-alerts
Draft

feat(billing): Deploy spend-cap detection and budget alerts (ENG-2904)#6486
Flo4604 wants to merge 1 commit into
eng-2908-build-go-email-sending-package-resendfrom
eng-2904-deploy-spend-cap-alerts

Conversation

@Flo4604

@Flo4604 Flo4604 commented Jun 18, 2026

Copy link
Copy Markdown
Member

Emails workspace admins at 50/75/100% of Compute spend budget. ENG-2869 stored the settings. This PR reads them and sends alerts. Enforcement (stopping compute at 100%) is ENG-2923. deploy_spend_budget_stop is carried through and only logged here.

A deploy-spend-check cron fires CronService.RunDeploySpendCheck. Local dev runs every minute (dev/k8s/charts/restate-cronjobs/values.yaml). Production cadence (15 minutes) lands in the infra repo.

The orchestrator lists workspaces with a budget, prices month-to-date usage from one grouped ClickHouse scan, computes overage = max(0, gross − included credit), and fans out DeploySpendCheckService.CheckWorkspaceSpend for workspaces at or past the lowest alert threshold. Included credit comes from deploy_included_credit_cents (dashboard webhook on invoice.payment_succeeded).

Also adds dashboard deployPricing.ts, deployCredits tests, and orchestrator integration coverage. The full suspend/resume integration test (deploy_spend_check_test) needs DeployTeardownService and lands on ENG-2923 (#6542), not this PR.

Closes ENG-2904. Stacked on ENG-2908 (#6456).

Local setup

mise run dev
stripe login

Optional alert emails: dev/.env.workos, dev/.env.resend.

stripe listen --forward-to http://localhost:3000/api/webhooks/stripe

Test plan

mise exec -- bazel test //svc/ctrl/worker/cron/deployspendcheck:deployspendcheck_test
mise exec -- bazel test //svc/ctrl/worker/cron:cron_test --test_filter=RunDeploySpendCheck
mise exec -- pnpm --dir=web/apps/dashboard vitest run lib/stripe/deployCredits.test.ts lib/stripe/deployPricing.test.ts
mise exec -- bazel build --nobuild //svc/ctrl/worker/cron:cron //svc/ctrl/worker/cron/deployspendcheck:deployspendcheck

Trigger spend check without waiting for cron:

curl -X POST "http://localhost:8080/hydra.v1.CronService/$(date -u +%Y-%m)/RunDeploySpendCheck/send"

End-to-end: subscribe to Deploy, set a spend budget, drive usage past 50% beyond included credit, wait ~1 minute or curl above, confirm alert email if Resend/WorkOS configured.

mise run unkey -- dev stripe grants --customer cus_...

@linear-code

linear-code Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

ENG-2904

@vercel

vercel Bot commented Jun 18, 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 Jul 3, 2026 6:02pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
design Ignored Ignored Preview Jul 3, 2026 6:02pm

Request Review

@Flo4604

Flo4604 commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

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

@Flo4604 Flo4604 force-pushed the eng-2908-build-go-email-sending-package-resend branch from 7de9c43 to 0d1dceb Compare June 24, 2026 18:43
@Flo4604 Flo4604 force-pushed the eng-2904-deploy-spend-cap-alerts branch from 46cb18d to 5d9c0c3 Compare June 24, 2026 18:43
@Flo4604 Flo4604 force-pushed the eng-2908-build-go-email-sending-package-resend branch from 0d1dceb to 61a1310 Compare June 26, 2026 13:35
@Flo4604 Flo4604 force-pushed the eng-2904-deploy-spend-cap-alerts branch from 5d9c0c3 to 60536d9 Compare June 26, 2026 13:35
@Flo4604 Flo4604 force-pushed the eng-2908-build-go-email-sending-package-resend branch from 61a1310 to 676ae6a Compare June 26, 2026 14:31
@Flo4604 Flo4604 force-pushed the eng-2904-deploy-spend-cap-alerts branch from 60536d9 to b8cef3f Compare June 26, 2026 14:31
@Flo4604 Flo4604 force-pushed the eng-2908-build-go-email-sending-package-resend branch from 676ae6a to ecead5f Compare June 26, 2026 15:19
@Flo4604 Flo4604 force-pushed the eng-2904-deploy-spend-cap-alerts branch from b8cef3f to c963735 Compare June 26, 2026 15:19
@Flo4604 Flo4604 force-pushed the eng-2908-build-go-email-sending-package-resend branch from ecead5f to 6bc0aad Compare June 26, 2026 15:28
@Flo4604 Flo4604 force-pushed the eng-2904-deploy-spend-cap-alerts branch from c963735 to edea2d1 Compare June 26, 2026 15:28
@Flo4604 Flo4604 force-pushed the eng-2908-build-go-email-sending-package-resend branch from 6bc0aad to dbea64a Compare June 29, 2026 12:34
@Flo4604 Flo4604 force-pushed the eng-2904-deploy-spend-cap-alerts branch from edea2d1 to c2fb151 Compare June 29, 2026 12:34
@Flo4604 Flo4604 force-pushed the eng-2908-build-go-email-sending-package-resend branch from dbea64a to 39ef825 Compare June 29, 2026 20:03
@Flo4604 Flo4604 force-pushed the eng-2904-deploy-spend-cap-alerts branch from c2fb151 to b7d22e7 Compare June 29, 2026 20:03
@Flo4604 Flo4604 force-pushed the eng-2908-build-go-email-sending-package-resend branch from 39ef825 to 5abc9c8 Compare June 30, 2026 19:14
@Flo4604 Flo4604 force-pushed the eng-2904-deploy-spend-cap-alerts branch from b7d22e7 to dd7c886 Compare June 30, 2026 19:14
@Flo4604 Flo4604 force-pushed the eng-2908-build-go-email-sending-package-resend branch from 5abc9c8 to 53a4868 Compare June 30, 2026 19:55
@Flo4604 Flo4604 force-pushed the eng-2904-deploy-spend-cap-alerts branch from dd7c886 to 393c67f Compare June 30, 2026 19:55
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