mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(webui): redesign the admin dashboard around admin tasks
A sidebar replaces the flat tabs with seven pages, and one filter bar sets the time range, comparison period and scope for all of them. - Home: spend against budget, forecast, request rate, error rate, open breakers, top users and models, recent events and warnings. - Spend: spend over time with comparison, budget burn-down, an attribution drill-down from group to user to model, pricing health and cost avoided by free models. - Consumers: a directory with last seen and limit bars, an access matrix, and a detail page per user. - Models: the catalog with billing prices, fleet latency and error rates, and provider health. - Reliability: error, timeout, failover, 429 and 402 trends, events, and latency per provider. - Config: the redacted config and a change helper that emits YAML or users.json snippets to paste into git. - MCP & Agents: callers per target. Page state lives in the URL hash, and old tab links map to the new pages. The replaced views are removed. admin_assets_gen.go is regenerated. Claude-Session: https://claude.ai/code/session_01V5jYJNxpDFdJkyyExpADrv
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { modelDetailCsv, modelRankingCsv, usageCsv } from './usage-csv'
|
||||
import type { AdminUsageEntryView, AdminUsageModelEntry } from '@/types/api'
|
||||
import { usageCsv } from './usage-csv'
|
||||
import type { AdminUsageEntryView } from '@/types/api'
|
||||
|
||||
function testEntry(overrides: Partial<AdminUsageEntryView> = {}): AdminUsageEntryView {
|
||||
return {
|
||||
@@ -28,7 +28,7 @@ const NOW = new Date(Date.UTC(2026, 3, 16, 0, 0, 0))
|
||||
|
||||
describe('usageCsv', () => {
|
||||
const HEADER =
|
||||
'Name,Group,Limits,req/min,req/day,rejected/day,tokIn/day,tokOut/day,tokIn/month,tokOut/month,cost/day (USD),cost/month (USD),"cost/month (proj., USD)"'
|
||||
'Name,Group,Limits,req/min,req/day,rejected/day,tokIn/day,tokOut/day,tokIn/month,tokOut/month,cost/day (USD),cost/month (USD),"cost/month (proj., USD)",last seen (unix seconds)'
|
||||
|
||||
it('renders the Users header row with "Group" as the secondary column', () => {
|
||||
const csv = usageCsv([], 'users', () => '', NOW)
|
||||
@@ -43,21 +43,26 @@ describe('usageCsv', () => {
|
||||
// P6 review fix: every numeric cell is now a PLAIN machine-readable
|
||||
// number — no thousands separators (formatExactInt) and no "$" prefix
|
||||
// (formatCost) — and the trailing cost/month (proj.) column is present.
|
||||
it('renders one data row per entry, as plain numbers (no locale grouping, no currency symbol), including the projected month-end cost', () => {
|
||||
const entries = [testEntry({ id: 'alice' }), testEntry({ id: 'bob' })]
|
||||
it('renders one data row per entry, as plain numbers (no locale grouping, no currency symbol), including the projected month-end cost and last-seen unix seconds', () => {
|
||||
const entries = [testEntry({ id: 'alice', lastSeen: 1_700_000_000 }), testEntry({ id: 'bob' })]
|
||||
const csv = usageCsv(entries, 'users', (e) => `group-of-${e.id}`, NOW)
|
||||
const lines = csv.split('\r\n')
|
||||
// costPerDayMicroUsd 1_234_500 -> 1.234500 USD; costPerMonthMicroUsd
|
||||
// 12_345_000 -> 12.345000 USD; projected = 12_345_000 / 0.5 = 24_690_000
|
||||
// micro-USD -> 24.690000 USD.
|
||||
expect(lines[1]).toBe('alice,group-of-alice,none,1,2,7,3,4,5,6,1.234500,12.345000,24.690000')
|
||||
expect(lines[2]).toBe('bob,group-of-bob,none,1,2,7,3,4,5,6,1.234500,12.345000,24.690000')
|
||||
// micro-USD -> 24.690000 USD. bob has no lastSeen -> 0.
|
||||
expect(lines[1]).toBe('alice,group-of-alice,none,1,2,7,3,4,5,6,1.234500,12.345000,24.690000,1700000000')
|
||||
expect(lines[2]).toBe('bob,group-of-bob,none,1,2,7,3,4,5,6,1.234500,12.345000,24.690000,0')
|
||||
})
|
||||
|
||||
it('renders "not enough data yet" for the proj. column when too little of the month has elapsed', () => {
|
||||
const earlyInMonth = new Date(Date.UTC(2026, 3, 1, 0, 5, 0))
|
||||
const csv = usageCsv([testEntry()], 'users', () => 'g', earlyInMonth)
|
||||
expect(csv.split('\r\n')[1]).toBe('alice,g,none,1,2,7,3,4,5,6,1.234500,12.345000,not enough data yet')
|
||||
expect(csv.split('\r\n')[1]).toBe('alice,g,none,1,2,7,3,4,5,6,1.234500,12.345000,not enough data yet,0')
|
||||
})
|
||||
|
||||
it('never masks last-seen as "?" for a storeDown entry — it is its own counter family, independent of the counters storeDown guards', () => {
|
||||
const csv = usageCsv([testEntry({ storeDown: true, lastSeen: 1_700_000_000 })], 'users', () => 'g', NOW)
|
||||
expect(csv.split('\r\n')[1]).toBe('alice,g,none,?,?,?,?,?,?,?,?,?,?,1700000000')
|
||||
})
|
||||
|
||||
it('formats Limits via formatLimits, matching the on-screen table', () => {
|
||||
@@ -68,7 +73,7 @@ describe('usageCsv', () => {
|
||||
it('masks every counter as "?" for a storeDown entry, never a stale number', () => {
|
||||
const csv = usageCsv([testEntry({ storeDown: true })], 'users', () => 'g', NOW)
|
||||
const dataLine = csv.split('\r\n')[1]
|
||||
expect(dataLine).toBe('alice,g,none,?,?,?,?,?,?,?,?,?,?')
|
||||
expect(dataLine).toBe('alice,g,none,?,?,?,?,?,?,?,?,?,?,0')
|
||||
})
|
||||
|
||||
it('quotes a field that needs it (e.g. a secondaryValue containing a comma)', () => {
|
||||
@@ -81,77 +86,10 @@ describe('usageCsv', () => {
|
||||
// exact projected value depends on the real clock, covered precisely
|
||||
// by the explicit-`now` tests above.
|
||||
const csv = usageCsv([testEntry()], 'users', () => 'g')
|
||||
expect(csv.split('\r\n')[1].split(',')).toHaveLength(13)
|
||||
expect(csv.split('\r\n')[1].split(',')).toHaveLength(14)
|
||||
})
|
||||
})
|
||||
|
||||
describe('modelRankingCsv', () => {
|
||||
const models: AdminUsageModelEntry[] = [
|
||||
{ id: 'openai/gpt-4', value: 100 },
|
||||
{ id: 'anthropic/claude', value: 50 },
|
||||
]
|
||||
|
||||
it('renders a header naming the ranked metric, window, and span (quoted — the label itself contains a comma)', () => {
|
||||
const csv = modelRankingCsv(models, 'Cost', '24h', 24)
|
||||
expect(csv.split('\r\n')[0]).toBe('Model,"Cost (24h, span 24)"')
|
||||
})
|
||||
|
||||
it('renders one row per model with its raw value when isCostMetric is omitted/false', () => {
|
||||
const csv = modelRankingCsv(models, 'Requests', '30d', 30)
|
||||
const lines = csv.split('\r\n')
|
||||
expect(lines[1]).toBe('openai/gpt-4,100')
|
||||
expect(lines[2]).toBe('anthropic/claude,50')
|
||||
})
|
||||
|
||||
it('renders just the header for an empty ranking', () => {
|
||||
expect(modelRankingCsv([], 'Cost', '24h', 24)).toBe('Model,"Cost (24h, span 24)"\r\n')
|
||||
})
|
||||
|
||||
// P6 review fix: a cost-metric ranking's `value` is raw micro-USD with no
|
||||
// unit stated anywhere — isCostMetric:true states the unit in the header
|
||||
// and converts each value to a plain decimal USD number.
|
||||
it('states the USD unit in the header and converts raw micro-USD values to plain decimal USD when isCostMetric is true', () => {
|
||||
const costModels: AdminUsageModelEntry[] = [{ id: 'openai/gpt-4', value: 1_234_500 }]
|
||||
const csv = modelRankingCsv(costModels, 'Cost', '24h', 24, true)
|
||||
const lines = csv.split('\r\n')
|
||||
expect(lines[0]).toBe('Model,"Cost (USD) (24h, span 24)"')
|
||||
expect(lines[1]).toBe('openai/gpt-4,1.234500')
|
||||
})
|
||||
})
|
||||
|
||||
// free-models-plan.md: the Models tab's CSV export now includes every
|
||||
// detail=1 figure per row (Requests/Tokens in/Tokens out/Cost), plus a
|
||||
// separate Free flag column — not just the single ranked metric
|
||||
// modelRankingCsv above exports.
|
||||
describe('modelDetailCsv', () => {
|
||||
it('renders a header naming every detail column, with window/span folded into Requests only', () => {
|
||||
const csv = modelDetailCsv([], '24h', 24)
|
||||
expect(csv).toBe('Model,"Requests (24h, span 24)",Tokens in,Tokens out,Cost (USD),Free\r\n')
|
||||
})
|
||||
|
||||
it('renders one row per model with every detail figure as a plain machine-readable number', () => {
|
||||
const models: AdminUsageModelEntry[] = [
|
||||
{ id: 'openai/gpt-4', value: 100, requests: 10, tokensIn: 1000, tokensOut: 2000, costMicroUsd: 1_234_500, free: false },
|
||||
]
|
||||
const csv = modelDetailCsv(models, '24h', 24)
|
||||
expect(csv.split('\r\n')[1]).toBe('openai/gpt-4,10,1000,2000,1.234500,false')
|
||||
})
|
||||
|
||||
it('exports the real 0 cost (never the string "free") in the Cost column, with Free as its own "true" column', () => {
|
||||
const models: AdminUsageModelEntry[] = [
|
||||
{ id: 'uni/free-model', value: 0, requests: 5, tokensIn: 50, tokensOut: 75, costMicroUsd: 0, free: true },
|
||||
]
|
||||
const csv = modelDetailCsv(models, '24h', 24)
|
||||
expect(csv.split('\r\n')[1]).toBe('uni/free-model,5,50,75,0.000000,true')
|
||||
})
|
||||
|
||||
it('falls back every missing detail field to 0/false when detail was not actually requested (defensive)', () => {
|
||||
const models: AdminUsageModelEntry[] = [{ id: 'openai/gpt-4', value: 100 }]
|
||||
const csv = modelDetailCsv(models, '24h', 24)
|
||||
expect(csv.split('\r\n')[1]).toBe('openai/gpt-4,0,0,0,0.000000,false')
|
||||
})
|
||||
|
||||
it('renders just the header for an empty ranking', () => {
|
||||
expect(modelDetailCsv([], '30d', 30)).toBe('Model,"Requests (30d, span 30)",Tokens in,Tokens out,Cost (USD),Free\r\n')
|
||||
})
|
||||
})
|
||||
// modelRankingCsv/modelDetailCsv (and their own describe blocks here)
|
||||
// were removed with the functions themselves (P3 item 25, dead code) —
|
||||
// see usage-csv.ts's own doc comment.
|
||||
|
||||
Reference in New Issue
Block a user