mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(admin): show target health in the dashboard
Add a Health column to the MCP servers and A2A agents tables in TargetsView. An unhealthy target renders a destructive badge with the age of its last check and carries the failure count, source, and scrubbed last error in the title. An unknown target renders an outline badge and, when it has failed but never succeeded, the same failure details in its title. A healthy target renders muted text with its last observed latency and no badge, matching the providers' convention. Add AdminTargetHealthView to the API types with the wire contract the Go side emits, a bare formatElapsedAgo helper next to formatAgo, and column-cell tests for all three states. Regenerate the baked admin assets. Claude-Session: https://claude.ai/code/session_01EebV5jyWvYocByNQ3oss1w
This commit is contained in:
+34
-5
@@ -162,13 +162,42 @@ export function formatLatencyMs(ms: number): string {
|
||||
return `${(ms / 1000).toFixed(1)}s`
|
||||
}
|
||||
|
||||
/**
|
||||
* elapsedSecondsSince computes whole seconds between `iso` and `now`, or
|
||||
* null for the unset zero-time sentinel or an unparseable value — the
|
||||
* shared guard formatAgo and formatElapsedAgo below both build on, so
|
||||
* neither duplicates the sentinel/NaN check.
|
||||
*/
|
||||
function elapsedSecondsSince(iso: string | undefined, now: number): number | null {
|
||||
if (!iso || iso === ZERO_TIME) return null
|
||||
const then = new Date(iso).getTime()
|
||||
if (Number.isNaN(then)) return null
|
||||
return Math.max(0, Math.round((now - then) / 1000))
|
||||
}
|
||||
|
||||
/** formatAgo renders an ISO timestamp as "(Ns ago)", or "" for the unset zero-time sentinel. */
|
||||
export function formatAgo(iso: string | undefined): string {
|
||||
if (!iso || iso === ZERO_TIME) return ''
|
||||
const then = new Date(iso).getTime()
|
||||
if (Number.isNaN(then)) return ''
|
||||
const secs = Math.max(0, Math.round((Date.now() - then) / 1000))
|
||||
return ` (${secs}s ago)`
|
||||
const secs = elapsedSecondsSince(iso, Date.now())
|
||||
return secs === null ? '' : ` (${secs}s ago)`
|
||||
}
|
||||
|
||||
/**
|
||||
* formatElapsedAgo renders elapsed time since an ISO timestamp as a bare
|
||||
* "Ns ago" string — no surrounding parentheses, unlike formatAgo above
|
||||
* (every existing formatAgo caller depends on its own " (Ns ago)" shape
|
||||
* unchanged, so that convention stays untouched here). Target health
|
||||
* badges (AdminTargetHealthView, TargetsView's health column — feat/
|
||||
* target-health) are the only caller today: a target's `lastCheck` needs
|
||||
* this bare form both standalone ("unhealthy (Ns ago)", parenthesized by
|
||||
* the caller) and inline ("Ns ago via probe"). The optional `now`
|
||||
* parameter (default Date.now()) makes the elapsed-time math
|
||||
* deterministic under test. "" for the unset zero-time sentinel or an
|
||||
* unparseable timestamp, mirroring formatAgo's own "nothing to show"
|
||||
* convention.
|
||||
*/
|
||||
export function formatElapsedAgo(iso: string | undefined, now = Date.now()): string {
|
||||
const secs = elapsedSecondsSince(iso, now)
|
||||
return secs === null ? '' : `${secs}s ago`
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user