Skip to content

feat(admin): add monthly gateway model usage report - #5837

Open
chrarnoldus wants to merge 3 commits into
mainfrom
feat/gateway-monthly-model-usage
Open

feat(admin): add monthly gateway model usage report#5837
chrarnoldus wants to merge 3 commits into
mainfrom
feat/gateway-monthly-model-usage

Conversation

@chrarnoldus

@chrarnoldus chrarnoldus commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a Monthly Usage tab to Gateway admin with a UTC year/month picker and requested-model input, including current-model suggestions and historical IDs.
  • Query the PostgreSQL read replica through readDb, joining microdollar_usage to microdollar_usage_metadata by ID and grouping by provider and is_byok.
  • Filter requested_model and is_user_byok = false exactly; use half-open UTC created_at bounds and case-insensitive anonymous-user exclusion for logged-in counts.
  • Include input/output/cache-read/cache-write totals, cost, and market cost. Cast aggregate values to text to preserve precision; costs are explicitly labeled microdollars.
  • Display and copy header-bearing TSV for spreadsheets, with a selectable-text fallback and formula-safe provider fields.
  • Set a transaction-local statement_timeout of at least ten minutes, respecting larger configured admin timeouts. Refuse production fallback to the primary database.
  • Removed all Snowflake-specific changes from this PR.

Validation

  • Formatting and git diff --check passed; changed UI lint passed.
  • Updated backend lint/typecheck were attempted but exceeded this container's two-minute limit. Local Node is 22; repository requires 24.
  • Added replica transaction, timeout, input/auth, precision, and real PostgreSQL aggregation regression coverage. Tests run in CI as requested.
  • UI retains the Kilo Cloud overlay and tabs recipe.

Runtime note

  • Existing tRPC maxDuration is 800 seconds; larger configured statement timeouts remain subject to this hosting limit.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
@chrarnoldus chrarnoldus self-assigned this Sep 2, 2026
@kilo-code-bot

kilo-code-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (7 files)
  • apps/web/src/app/admin/gateway/MonthlyUsageContent.tsx
  • apps/web/src/app/admin/gateway/monthly-usage-export.test.ts
  • apps/web/src/app/admin/gateway/monthly-usage-export.ts
  • apps/web/src/app/admin/gateway/page.tsx
  • apps/web/src/routers/admin-router.ts
  • apps/web/src/routers/admin/gateway-usage-router.test.ts
  • apps/web/src/routers/admin/gateway-usage-router.ts
Previous Review Summary (commit ad69910)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit ad69910)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (9 files)
  • apps/web/src/app/admin/gateway/MonthlyUsageContent.tsx
  • apps/web/src/app/admin/gateway/monthly-usage-export.test.ts
  • apps/web/src/app/admin/gateway/monthly-usage-export.ts
  • apps/web/src/app/admin/gateway/page.tsx
  • apps/web/src/lib/snowflake.test.ts
  • apps/web/src/lib/snowflake.ts
  • apps/web/src/routers/admin-router.ts
  • apps/web/src/routers/admin/gateway-usage-router.test.ts
  • apps/web/src/routers/admin/gateway-usage-router.ts

Reviewed by grok-4.6 · Input: 115.3K · Output: 16K · Cached: 615.8K

Review guidance: REVIEW.md from base branch main

chrarnoldus and others added 2 commits September 2, 2026 21:14
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
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