Skip to content

feat(sharing-server): admin token usage dashboard#694

Merged
rajbos merged 2 commits intomainfrom
rajbos/admin-token-usage-dashboard
Apr 29, 2026
Merged

feat(sharing-server): admin token usage dashboard#694
rajbos merged 2 commits intomainfrom
rajbos/admin-token-usage-dashboard

Conversation

@rajbos
Copy link
Copy Markdown
Owner

@rajbos rajbos commented Apr 29, 2026

Summary

Adds a dedicated /admin page to the sharing server so admins can see token usage across all registered users with trend and average views.

What's new

/admin page (admin-only)

  • Overview stat cards — Total users, active users, total tokens, avg tokens per active user, interactions. Three pre-rendered periods (7d / 30d / 90d) toggled with a tab bar.
  • Usage trend chart — Stacked bar chart showing daily token usage, colored by user (top 10 + "Others"). Period toggle: 7d / 30d / 90d. Mode toggle:
    • Total — Stacked bars per user
    • Per-User Average — Single-series bar showing total tokens that day ÷ active users that day
  • Users table — All users with 30d input tokens, output tokens, interactions, days active, all-time last upload, and admin flag.

User dashboard

  • Admin users see a 👑 Admin link in the header pointing to /admin.

DB changes

  • getAdminUserSummaries(days) — LEFT JOIN users ↔ uploads so zero-upload users always appear in the table. Computes aggregated stats per user for the selected period.
  • getAdminDailyTotals(days) — Per-day per-user totals for the trend chart.
  • New idx_uploads_day index for efficient admin-wide day-range queries.

Testing

  • TypeScript compiles with npm run check-types
  • esbuild bundle builds successfully ✅

- New /admin route (admin-only, redirects non-admins to /dashboard)
- Per-user summary table showing 30d input/output tokens, interactions,
  days active and last upload date
- Overview stat cards for 7d / 30d / 90d with period toggle:
  total users, active users, total tokens, avg tokens per active user,
  interactions
- Stacked trend chart (top-10 users + Others) with period toggle
  (7d / 30d / 90d) and mode toggle (Total / Per-User Average)
  Per-User Average mode shows a single-series bar: total tokens that
  day divided by the number of active users that day
- Admin Panel link in the user dashboard header for admin users
- New DB functions getAdminUserSummaries() and getAdminDailyTotals()
  using LEFT JOIN so zero-upload users still appear in the table
- New idx_uploads_day index for efficient admin-wide day-range queries

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Custom domain managed certificates are only meaningful on stable,
long-lived environments (production). Each testing branch gets a unique
ACA FQDN (sharing-test-<slug>.azurecontainerapps.io) that already has
Azure TLS — no custom cert needed.

Setting SHARING_CUSTOM_DOMAIN on the testing GitHub environment caused
every new branch deploy to provision a fresh cert via CNAME validation,
which takes up to 60 minutes and fails if the CNAME points to a different
ACA environment (as it always does for per-branch deploys).

Changes:
- Gate the Reconcile custom domain workflow step on is_prod == 'true'
  so it is skipped for all non-main branch deploys even if
  SHARING_CUSTOM_DOMAIN is accidentally set on the testing environment
- Add a comment to main.tf explaining the custom_domain var is
  production-only

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rajbos rajbos merged commit 3023dc1 into main Apr 29, 2026
22 checks passed
@rajbos rajbos deleted the rajbos/admin-token-usage-dashboard branch April 29, 2026 11:12
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