feat(phase-4): WS6 — Billing & Usage Metering (Stripe, free tier enforcement)

- DB migration 023: tenant_subscriptions and usage_events tables
- UsageMeteringMiddleware: in-memory counters, 60s flush to DB via UPSERT
- FreeTierEnforcementMiddleware: 10 agents / 1,000 calls/day limits, Redis cache
- UsageService: getDailyUsage and getActiveAgentCount
- BillingService: Stripe checkout sessions, webhook verification, subscription status
- POST /billing/checkout, POST /billing/webhook, GET /billing/usage endpoints
- BILLING_ENABLED=false disables enforcement without breaking metering
- Dashboard: Usage tab with Free Tier/Pro badges and metric cards
- 19 unit tests passing across billing services and middleware

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
SentryAgent.ai Developer
2026-04-02 10:51:36 +00:00
parent fefbf1e3ea
commit 26a56f84e1
18 changed files with 1647 additions and 17 deletions

View File

@@ -159,3 +159,16 @@ export const tenantApiCallsTotal = new Counter({
labelNames: ['tenant_id'] as const,
registers: [metricsRegistry],
});
/**
* Total number of requests rejected due to free tier billing limits.
* Labels: tenant_id, limit_type ('agent_limit' | 'api_limit')
*
* WS6 — Billing & Usage Metering.
*/
export const billingLimitRejectionsTotal = new Counter({
name: 'agentidp_billing_limit_rejections_total',
help: 'Total number of requests rejected due to free tier billing limits.',
labelNames: ['tenant_id', 'limit_type'] as const,
registers: [metricsRegistry],
});