feat(platform): time-based usage analytics in governance#1575
Conversation
Replaces the monthly per-user UsageDashboard in Governance → Security & Monitoring → Usage with a time-series analytics page. Extends usageLedger with agentSlug / model / provider / granularity (additive schema, no renames), fixes an ISO-8601 weekly period-key bug at year boundaries, and adds a paginated migration that backfills granularity for legacy rows. The new page supports 7/30/90 day presets, daily/weekly/monthly granularity, a Requests/Tokens/Cost metric toggle, Top Assistants, Top Models (with provider badge), and a full per-user table (team + input/output tokens + cost + requests). Admin-only, scoped to the active org via existing RLS guards.
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis pull request introduces a comprehensive usage analytics feature across the platform. It adds multiple new React components for rendering usage metrics (TopAgentsTable, TopModelsTable, UsageTrendChart, UsageSummaryCards, UsersTable) and a main UsageMetricsPage that orchestrates these components with filtering by period, granularity, and metric type. On the backend, it adds a new Convex query Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
UsageDashboardunder Governance → Security & Monitoring → Usage with a time-series analytics page (7/30/90-day presets, daily/weekly/monthly granularity, Requests/Tokens/Cost metric toggle, Top Assistants, Top Models with provider badge, full Per-User table).usageLedgerwith optionalagentSlug/model/providerand requiredgranularity; additive indexes only (no renames). All threeincrementUsageLedgercallsites updated atomically (chat, workflow LLM steps, openai-compat).granularity.readonorgSettings); per-org scope via the existing RLS guard + org switcher. en + de i18n.Test plan
npx tsc --noEmitandnpm run lint --workspace=@tale/platformboth cleannpx vitest run convex/governance/__tests__/helpers.test.ts— ISO-week boundary cases pass (2023-01-01 → 2022-W52, 2024-12-31 → 2025-W01, 2025-12-29 → 2026-W01)backfill_ledger_granularityon a deploy with legacy rows; confirm all rows gain a non-nullgranularityand no duplicates are introducedusageLedgerhas distinct rows per(userId, agentSlug, model)andprovideris populated(agent, model, user, period)— exactly one merged row (race-merge filters work)AccessDenied; member of org A withorganizationId: B→ server-sideisAdmin/org-membership guard rejectsde; all strings render, currency formats locale-awareSummary by CodeRabbit
Release Notes
New Features