mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
feat(webui): reliability page
This commit is contained in:
+1
-1
@@ -51,7 +51,7 @@ const PAGES: Record<PageId, Component> = {
|
||||
models: lazyPage(() => import('@/pages/ModelsPage.vue')),
|
||||
routers: lazyPage(() => import('@/pages/ModelsPage.vue')),
|
||||
targets: lazyPage(() => import('@/pages/TargetsPage.vue')),
|
||||
events: lazyPage(() => import('@/pages/ReliabilityPage.vue')),
|
||||
events: lazyPage(() => import('@/pages/LegacyReliabilityPage.vue')),
|
||||
config: lazyPage(() => import('@/pages/ConfigPage.vue')),
|
||||
}
|
||||
|
||||
|
||||
@@ -211,6 +211,8 @@
|
||||
/* Phone cards layout: drop the share bar from compact top lists. */
|
||||
@media (max-width: 639px) { .wb-hide-share-sm .wb-share { display: none; } }
|
||||
@media (min-width: 640px) { .wb-clip td.wb-text { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }
|
||||
/* Breaker lastErr: one clamped line, full text in the title. */
|
||||
.wb-err { display: block; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
|
||||
/* Model id cell: provider as a muted prefix, model name ellipsized at its end; the column takes the free width. */
|
||||
.wb-model { display: inline-flex; align-items: baseline; gap: 1px; max-width: 100%; min-width: 0; vertical-align: bottom; }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import {
|
||||
breakerRows,
|
||||
dayRateTitle,
|
||||
formatErrorRatePercent,
|
||||
formatRatePercent,
|
||||
@@ -182,3 +183,35 @@ describe('formatErrorRatePercent', () => {
|
||||
expect(formatErrorRatePercent(null, 'no traffic')).toBe('no traffic')
|
||||
})
|
||||
})
|
||||
|
||||
describe('breakerRows', () => {
|
||||
const p = (name: string, healthState: 'closed' | 'open' | 'half-open', extra: { openUntil?: string; lastErr?: string } = {}) => ({
|
||||
name,
|
||||
healthState,
|
||||
openUntil: extra.openUntil ?? '0001-01-01T00:00:00Z',
|
||||
lastErr: extra.lastErr,
|
||||
})
|
||||
|
||||
it('open and half-open sorted first', () => {
|
||||
const rows = breakerRows({
|
||||
providers: [p('a-closed', 'closed'), p('b-half', 'half-open'), p('c-closed', 'closed'), p('d-open', 'open', { openUntil: '2026-01-01T00:00:00Z' })],
|
||||
})
|
||||
expect(rows.map((r) => r.provider)).toEqual(['d-open', 'b-half', 'a-closed', 'c-closed'])
|
||||
expect(rows.map((r) => r.state)).toEqual(['open', 'half-open', 'closed', 'closed'])
|
||||
})
|
||||
|
||||
it('sorts by name within the same state', () => {
|
||||
const rows = breakerRows({ providers: [p('z', 'open'), p('m', 'open')] })
|
||||
expect(rows.map((r) => r.provider)).toEqual(['m', 'z'])
|
||||
})
|
||||
|
||||
it('carries openUntil and lastErr, blank when unset', () => {
|
||||
const [row] = breakerRows({ providers: [p('x', 'open', { openUntil: '2026-01-01T00:00:00Z', lastErr: 'boom' })] })
|
||||
expect(row).toEqual({ provider: 'x', state: 'open', openUntil: '2026-01-01T00:00:00Z', lastErr: 'boom' })
|
||||
expect(breakerRows({ providers: [p('y', 'closed')] })[0]!.lastErr).toBe('')
|
||||
})
|
||||
|
||||
it('returns nothing without an overview', () => {
|
||||
expect(breakerRows(null)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// ts's `test` block) exercise the threshold math directly, with no
|
||||
// component mount required.
|
||||
|
||||
import type { AdminProviderView, ProviderHealthState } from '@/types/api'
|
||||
|
||||
/**
|
||||
* PROVIDER_RATE_AMBER_THRESHOLD is the day-window success-rate fraction
|
||||
* (0-1) at and above which a provider or model reads as healthy ("muted"
|
||||
@@ -172,3 +174,20 @@ export function dayRateTitle(attemptsDay: number, failuresDay: number): string {
|
||||
const pct = rate === null ? '' : ` (${formatRatePercent(rate)})`
|
||||
return `${attemptsDay} ${countWord(attemptsDay, 'attempt', 'attempts')}, ${failuresDay} ${countWord(failuresDay, 'failure', 'failures')} today${pct}`
|
||||
}
|
||||
|
||||
export interface BreakerRow {
|
||||
provider: string
|
||||
state: ProviderHealthState
|
||||
openUntil: string
|
||||
lastErr: string
|
||||
}
|
||||
|
||||
const BREAKER_STATE_ORDER: Record<ProviderHealthState, number> = { open: 0, 'half-open': 1, closed: 2 }
|
||||
|
||||
/** One row per provider, open then half-open breakers first, ties by name. */
|
||||
export function breakerRows(
|
||||
overview: { providers: ReadonlyArray<Pick<AdminProviderView, 'name' | 'healthState' | 'openUntil' | 'lastErr'>> } | null,
|
||||
): BreakerRow[] {
|
||||
const rows = (overview?.providers ?? []).map((p) => ({ provider: p.name, state: p.healthState, openUntil: p.openUntil, lastErr: p.lastErr ?? '' }))
|
||||
return rows.sort((a, b) => BREAKER_STATE_ORDER[a.state] - BREAKER_STATE_ORDER[b.state] || a.provider.localeCompare(b.provider))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,425 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, watch } from 'vue'
|
||||
|
||||
import ChartCard from '@/components/ChartCard.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import EventsView from '@/components/EventsView.vue'
|
||||
import LabeledSelect from '@/components/LabeledSelect.vue'
|
||||
import SkeletonChart from '@/components/SkeletonChart.vue'
|
||||
import SkeletonList from '@/components/SkeletonList.vue'
|
||||
import StatDisabledAlert from '@/components/StatDisabledAlert.vue'
|
||||
import TimeSeriesChart from '@/components/TimeSeriesChart.vue'
|
||||
import type { TimeSeriesDataset } from '@/components/TimeSeriesChart.vue'
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { seriesColor } from '@/lib/chart-palette'
|
||||
import { formatBucketLabel, formatPercentAxis } from '@/lib/format'
|
||||
import { emptyWhenAllZero, loadState } from '@/lib/load-state'
|
||||
import type { LoadState } from '@/lib/load-state'
|
||||
import { formatErrorRatePercent } from '@/lib/provider-rate'
|
||||
import { scopeId } from '@/lib/scope'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
import { useEventsStore } from '@/stores/events'
|
||||
import { useFiltersStore } from '@/stores/filters'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
import { useReliabilityStore } from '@/stores/reliability'
|
||||
import type { CountSeries, ProviderRatioSeries } from '@/stores/reliability'
|
||||
|
||||
/**
|
||||
* ReliabilityPage (redesign-plan.md section 3.4) — error-rate/failover/
|
||||
* timeout/429/402 series, plus the pre-redesign Events view reused as a
|
||||
* section. Every chart is an on-demand fetch (useReliabilityStore.fetch),
|
||||
* not part of the 5s dashboard poll — refetched on mount and whenever the
|
||||
* global range changes (Q12 DECISIONS).
|
||||
*
|
||||
* Page params (redesign-plan.md section 3.1): `provider` narrows every
|
||||
* per-provider chart to one provider's own line ('' / absent means every
|
||||
* configured provider, overlaid); `kind`/`user` seed the embedded Events
|
||||
* section's own filters (stores/events.ts's initFromParams). All three
|
||||
* round-trip through the URL hash the same way EntityLink.vue's params do
|
||||
* — nav.goTo on every local change, read back via nav.params on mount.
|
||||
*/
|
||||
const dashboard = useDashboardStore()
|
||||
const events = useEventsStore()
|
||||
const filters = useFiltersStore()
|
||||
const nav = useNavStore()
|
||||
const reliability = useReliabilityStore()
|
||||
|
||||
const selectedProvider = computed<string>(() => nav.params.provider ?? '')
|
||||
/** providerOptions feeds LabeledSelect's own options list — LabeledSelect owns the "All providers" -> '' sentinel mapping itself (reuse-audit.md F11), so this page no longer needs its own ALL_PROVIDERS_OPTION constant. */
|
||||
const providerOptions = computed(() => (dashboard.overview?.providers ?? []).map((p) => ({ value: p.name, label: p.name })))
|
||||
|
||||
function onProviderChange(value: string): void {
|
||||
nav.goTo('reliability', { ...nav.params, provider: value })
|
||||
}
|
||||
|
||||
/** providerLabel strips the "provider:" scope prefix every reliability series carries (lib/scope.ts's shared scopeId, reuse-audit.md F5) — the display label is just the provider name. */
|
||||
function providerLabel(scope: string): string {
|
||||
return scopeId(scope)
|
||||
}
|
||||
|
||||
function filterSelected<T extends { scope: string }>(series: T[]): T[] {
|
||||
if (!selectedProvider.value) return series
|
||||
return series.filter((s) => providerLabel(s.scope) === selectedProvider.value)
|
||||
}
|
||||
|
||||
/**
|
||||
* NaN, not 0, marks a bucket with no attempts (errorRateSeries' own "null
|
||||
* means no traffic" convention) — chart.js draws a gap at a NaN point
|
||||
* rather than a misleading flat 0%, and NaN is still a plain `number`, so
|
||||
* TimeSeriesDataset's `data: number[]` needs no cast here.
|
||||
*/
|
||||
function toChartPoints(points: (number | null)[]): number[] {
|
||||
return points.map((p) => (p === null ? Number.NaN : p))
|
||||
}
|
||||
|
||||
const errorRateDatasets = computed<TimeSeriesDataset[]>(() =>
|
||||
filterSelected<ProviderRatioSeries>(reliability.errorRate).map((s, i) => ({
|
||||
label: providerLabel(s.scope),
|
||||
data: toChartPoints(s.points),
|
||||
color: seriesColor(i),
|
||||
})),
|
||||
)
|
||||
|
||||
function countDatasets(series: CountSeries[]): TimeSeriesDataset[] {
|
||||
return filterSelected(series).map((s, i) => ({ label: providerLabel(s.scope), data: s.points, color: seriesColor(i) }))
|
||||
}
|
||||
|
||||
const timeoutDatasets = computed(() => countDatasets(reliability.timeouts))
|
||||
const failoverDatasets = computed(() => countDatasets(reliability.failovers))
|
||||
|
||||
const rejectionDatasets = computed<TimeSeriesDataset[]>(() => [
|
||||
{ label: '429 rejections', data: reliability.rejections, color: '--destructive' },
|
||||
])
|
||||
const unpricedDatasets = computed<TimeSeriesDataset[]>(() => [
|
||||
{ label: '402 unpriced refusals', data: reliability.unpriced, color: '--status-warn' },
|
||||
])
|
||||
|
||||
const bucketLabels = computed<string[]>(() => reliability.buckets.map((b) => formatBucketLabel(b, reliability.windowUsed)))
|
||||
|
||||
/**
|
||||
* errorRatePercent adapts TimeSeriesChart's plain `number` valueFormatter
|
||||
* contract (NaN marks a no-attempts bucket, toChartPoints' own doc
|
||||
* comment) to lib/provider-rate.ts's shared formatErrorRatePercent, which
|
||||
* takes `null` for the identical "nothing to report" case — the actual
|
||||
* ceiling-percent/"no data" wording lives in exactly one place, shared
|
||||
* with lib/model-table-columns.ts's per-model error-rate column.
|
||||
*/
|
||||
function errorRatePercent(value: number): string {
|
||||
return formatErrorRatePercent(Number.isNaN(value) ? null : value)
|
||||
}
|
||||
|
||||
const hasProviders = computed(() => (dashboard.overview?.providers.length ?? 0) > 0)
|
||||
const noFailoverConfigured = computed(() => dashboard.overview !== null && dashboard.overview.features.failover === false)
|
||||
|
||||
/**
|
||||
* dashboardLoadState (live-preview fix, same class as verify-ui-states.md
|
||||
* #3): `hasProviders` alone reads false BOTH when the fleet genuinely has
|
||||
* no configured providers AND before the polled dashboard.overview has
|
||||
* ever landed (or after it failed to) — "No providers configured." used
|
||||
* to render as a false fleet fact on a deep link straight to this page,
|
||||
* before the 5s dashboard poll's first response arrives. Every OTHER page
|
||||
* already reads dashboard.overview after it has settled at least once
|
||||
* (they mount later in a typical session); this page can be the very
|
||||
* first thing mounted on a cold reload.
|
||||
*/
|
||||
const dashboardLoadState = computed(() => loadState({ loading: !dashboard.lastUpdated, hasData: dashboard.overview !== null, error: dashboard.error }))
|
||||
|
||||
/**
|
||||
* providersState (live-preview fix: "per-provider charts briefly render an
|
||||
* empty grid before providers are known") gates the FOUR per-provider chart
|
||||
* cards below (error rate, selected provider performance, timeouts,
|
||||
* failovers) — the same three-way split lib/access-matrix.ts's
|
||||
* matrixColumnsState makes for AccessMatrix.vue's own columns: 'skeleton'
|
||||
* while dashboard.overview has not loaded yet (dashboardLoadState itself
|
||||
* still unsettled — this page is often the very first thing mounted on a
|
||||
* cold reload), 'error' forwarded from that same first-load failure,
|
||||
* 'empty' once overview has genuinely loaded with zero configured
|
||||
* providers (a real fleet fact, not a loading artifact), 'ready' once it
|
||||
* has loaded with at least one provider to chart.
|
||||
*/
|
||||
const providersState = computed<LoadState>(() => {
|
||||
if (dashboardLoadState.value !== 'ready') return dashboardLoadState.value
|
||||
return hasProviders.value ? 'ready' : 'empty'
|
||||
})
|
||||
|
||||
// --- selected-provider performance (N3 fix, redesign-plan.md section
|
||||
// 3.3: "performance series=1 for the selected provider") ---
|
||||
const latencyStatsEnabled = computed(() => dashboard.overview?.features.latencyStats ?? false)
|
||||
/** providerPerfAvailable gates the whole selected-provider chart section — both conditions the task names ("when a provider is selected and latency stats are enabled"), mirroring reliability.fetchProviderPerf's own short-circuit so the fetch and the render never disagree about when there is data to show. */
|
||||
const providerPerfAvailable = computed(() => selectedProvider.value !== '' && latencyStatsEnabled.value)
|
||||
|
||||
const providerPerfBucketLabels = computed<string[]>(() =>
|
||||
reliability.providerPerfBuckets.map((b) => formatBucketLabel(b, reliability.providerPerfWindowUsed)),
|
||||
)
|
||||
/** p50/p95 read as NaN (a chart.js gap, toChartPoints' own convention above) for a bucket with no observations — AdminPerfRow's own doc comment: undefined never means 0ms. */
|
||||
const providerLatencyDatasets = computed<TimeSeriesDataset[]>(() => [
|
||||
{ label: 'p50', data: reliability.providerPerfPoints.map((p) => p.p50Ms ?? Number.NaN), color: '--chart-requests' },
|
||||
{ label: 'p95', data: reliability.providerPerfPoints.map((p) => p.p95Ms ?? Number.NaN), color: '--chart-tokens-in' },
|
||||
])
|
||||
const providerFailureDatasets = computed<TimeSeriesDataset[]>(() => [
|
||||
{ label: 'failures', data: reliability.providerPerfPoints.map((p) => p.failures), color: '--destructive' },
|
||||
])
|
||||
|
||||
watch(
|
||||
() => [selectedProvider.value, filters.range] as const,
|
||||
([provider]) => void reliability.fetchProviderPerf(provider),
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
/**
|
||||
* monthRangeClamped is true whenever the global range is a month preset
|
||||
* (3mo/6mo/12mo) — stores/reliability.ts's own hourOrDayWindow has NO
|
||||
* month bucket at all for any reliability metric (its own doc comment:
|
||||
* "neither family has a month bucket at all, matching their own 48h/35d
|
||||
* TTLs"), so it substitutes a fixed 30-day day-window instead. Every
|
||||
* chart below silently shows that 30-day window regardless of which
|
||||
* month preset is selected — this note (P3 item 20) says so, rather than
|
||||
* letting a reader believe a "12mo" label over a chart that is actually
|
||||
* showing the most recent 30 days.
|
||||
*/
|
||||
const monthRangeClamped = computed(() => filters.window === 'month')
|
||||
|
||||
// --- skeleton/error states (verify-ui-states.md #7: "Spend and
|
||||
// Reliability pages got no skeletons or ErrorState") -----------------------
|
||||
|
||||
/**
|
||||
* reliabilityState (lib/load-state.ts) gates every fleet-wide chart on this
|
||||
* page (error rate, timeouts, failovers, rejections, unpriced) — all five
|
||||
* are populated by the ONE reliability.fetch() call, so one shared state is
|
||||
* correct rather than each chart re-deriving its own from the same three
|
||||
* underlying signals. Checked FIRST: dashboardLoadState — reliability.fetch
|
||||
* (stores/reliability.ts) now no-ops while dashboard.overview has not
|
||||
* loaded yet, rather than resolving as "loaded, empty" (the live-preview
|
||||
* fix this composition closes), so reliability.loading/buckets/error alone
|
||||
* can no longer be trusted to read 'skeleton' during that window; once
|
||||
* dashboardLoadState settles 'ready', this falls through to reliability's
|
||||
* own loading/buckets/error exactly as before.
|
||||
*/
|
||||
const reliabilityState = computed<LoadState>(() => {
|
||||
if (dashboardLoadState.value !== 'ready') return dashboardLoadState.value
|
||||
return loadState({ loading: reliability.loading, hasData: reliability.buckets.length > 0, error: reliability.error })
|
||||
})
|
||||
|
||||
/** Count charts with nothing to plot show a message instead of an empty 0-1 axis. */
|
||||
const timeoutState = computed<LoadState>(() => emptyWhenAllZero(reliabilityState.value, timeoutDatasets.value))
|
||||
const failoverState = computed<LoadState>(() => emptyWhenAllZero(reliabilityState.value, failoverDatasets.value))
|
||||
/** providerPerfState mirrors reliabilityState for the "Selected provider performance" chart pair — reliability.fetchProviderPerf runs independently of fetch() (its own doc comment), so it needs its own loading/error signal, only reachable once providerPerfAvailable is already true. */
|
||||
const providerPerfState = computed(() =>
|
||||
loadState({ loading: reliability.providerPerfLoading, hasData: reliability.providerPerfPoints.length > 0, error: reliability.providerPerfError }),
|
||||
)
|
||||
|
||||
// Refetch whenever the global range changes (Q12 DECISIONS: "new endpoints
|
||||
// on demand or 60s" — this is the "on demand" case, driven by the reader's
|
||||
// own range choice rather than a timer) or once the dashboard's 5s poll
|
||||
// first discovers which providers are configured (a page that mounts
|
||||
// before the first overview poll lands would otherwise see hasProviders
|
||||
// flip true with no series fetched yet to back it).
|
||||
watch(
|
||||
() => [filters.range, dashboard.overview?.providers.length ?? 0],
|
||||
() => void reliability.fetch(),
|
||||
)
|
||||
|
||||
// kind/user round-trip back into the URL hash (redesign-plan.md section
|
||||
// 3.1's Reliability page params) whenever the reader changes the embedded
|
||||
// Events section's own filters — mirrors `provider`'s own onProviderChange
|
||||
// above, one nav.goTo call merging every current page param so neither
|
||||
// write clobbers the other.
|
||||
watch(
|
||||
() => [events.kindFilter, events.userFilter],
|
||||
([kind, user]) => {
|
||||
nav.goTo('reliability', { ...nav.params, kind, user })
|
||||
},
|
||||
)
|
||||
|
||||
// nav.params.kind/user react to a hash change this page's own Select/
|
||||
// SearchInput did NOT originate — browser back/forward, a hand-edited URL,
|
||||
// or returning here via the sidebar with the param cleared (P2 item 10:
|
||||
// stores/events.ts's own initFromParams applies a param only when it is
|
||||
// PRESENT, by design, for a one-shot seed — but called only on mount, that
|
||||
// left a kind/user filter set on an earlier visit stuck in place when the
|
||||
// reader returned with an empty hash). `immediate: true` covers the
|
||||
// initial mount too, so this replaces that one-shot call outright.
|
||||
// Undefined always resolves to '' ("no filter"), and this never loops
|
||||
// against the watch above: assigning a store field its OWN current value
|
||||
// is a same-value write, which Vue's reactivity does not re-trigger a
|
||||
// dependent watch for.
|
||||
watch(
|
||||
() => [nav.params.kind, nav.params.user] as const,
|
||||
([kind, user]) => {
|
||||
events.setKindFilter(kind ?? '')
|
||||
events.setUserFilter(user ?? '')
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
onMounted(() => void reliability.fetch())
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-6">
|
||||
<Card>
|
||||
<CardHeader class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<CardTitle>Reliability</CardTitle>
|
||||
<CardDescription>Provider error rate, failovers, timeouts, rate-limit rejections, and 402 refusals.</CardDescription>
|
||||
</div>
|
||||
<LabeledSelect
|
||||
label="Provider"
|
||||
:model-value="selectedProvider"
|
||||
:options="providerOptions"
|
||||
all-label="All providers"
|
||||
trigger-class="w-48"
|
||||
@update:model-value="onProviderChange"
|
||||
/>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<SkeletonList v-if="dashboardLoadState === 'skeleton'" :rows="2" />
|
||||
<ErrorState v-else-if="dashboardLoadState === 'error'" :message="dashboard.error" :on-retry="dashboard.refresh" />
|
||||
<p v-else-if="reliability.error" class="text-sm break-words text-destructive">{{ reliability.error }}</p>
|
||||
<EmptyState v-else-if="!hasProviders" title="No providers configured." />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Alert v-if="monthRangeClamped" variant="warn">
|
||||
<AlertDescription>
|
||||
Reliability data has no monthly retention — every chart below shows the most recent 30 days, not the full
|
||||
{{ filters.range }} range selected above.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
<!--
|
||||
providersState (live-preview fix: "per-provider charts briefly render
|
||||
an empty grid before providers are known") gates this whole group of
|
||||
FOUR per-provider cards as one unit — 'skeleton' while
|
||||
dashboard.overview has not loaded, 'empty' once it has loaded with
|
||||
zero configured providers (a real fleet fact, shown once via a single
|
||||
EmptyState rather than four repeated ones), 'ready' to render the
|
||||
actual charts below exactly as before.
|
||||
-->
|
||||
<template v-if="providersState === 'skeleton'">
|
||||
<ChartCard title="Error rate by provider" state="skeleton" />
|
||||
<ChartCard title="Selected provider performance" state="skeleton" />
|
||||
<ChartCard title="Timeouts by provider" state="skeleton" />
|
||||
<ChartCard title="Failovers by provider" state="skeleton" />
|
||||
</template>
|
||||
<Card v-else-if="providersState === 'empty'">
|
||||
<CardContent>
|
||||
<EmptyState
|
||||
title="No providers configured."
|
||||
description="Add a providers entry to the middleware config to see per-provider reliability charts here."
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<template v-else-if="providersState === 'ready'">
|
||||
<ChartCard
|
||||
title="Error rate by provider"
|
||||
description="Failed attempts / total attempts per bucket. A gap means no attempts in that bucket."
|
||||
:state="reliabilityState"
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="errorRateDatasets"
|
||||
:value-formatter="errorRatePercent"
|
||||
:axis-formatter="formatPercentAxis"
|
||||
aria-label="Error rate by provider over time"
|
||||
/>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Selected provider performance</CardTitle>
|
||||
<CardDescription>Latency (p50/p95) and failures per bucket for one provider.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-4">
|
||||
<p v-if="selectedProvider === ''" class="text-sm text-muted-foreground">
|
||||
Select a provider above to see its latency and failure breakdown per bucket.
|
||||
</p>
|
||||
<StatDisabledAlert
|
||||
v-else-if="!latencyStatsEnabled"
|
||||
title="Latency statistics are off"
|
||||
config-key="admin.stats.latency"
|
||||
:purpose="`to see per-bucket latency for ${selectedProvider}.`"
|
||||
/>
|
||||
<template v-else-if="providerPerfAvailable">
|
||||
<SkeletonChart v-if="providerPerfState === 'skeleton'" />
|
||||
<ErrorState
|
||||
v-else-if="providerPerfState === 'error'"
|
||||
:message="reliability.providerPerfError"
|
||||
:on-retry="() => reliability.fetchProviderPerf(selectedProvider)"
|
||||
/>
|
||||
<div v-else class="grid gap-6 lg:grid-cols-2">
|
||||
<div>
|
||||
<p class="mb-2 text-sm font-medium text-muted-foreground">Latency (ms)</p>
|
||||
<TimeSeriesChart
|
||||
:labels="providerPerfBucketLabels"
|
||||
:datasets="providerLatencyDatasets"
|
||||
:ariaLabel="`p50/p95 latency for ${selectedProvider} over time`"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<p class="mb-2 text-sm font-medium text-muted-foreground">Failures</p>
|
||||
<TimeSeriesChart
|
||||
:labels="providerPerfBucketLabels"
|
||||
:datasets="providerFailureDatasets"
|
||||
:ariaLabel="`Failures for ${selectedProvider} over time`"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<ChartCard
|
||||
title="Timeouts by provider"
|
||||
:state="timeoutState"
|
||||
show-empty
|
||||
empty-title="No timeouts in this range."
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="timeoutDatasets"
|
||||
aria-label="Timeouts by provider over time"
|
||||
/>
|
||||
|
||||
<ChartCard
|
||||
title="Failovers by provider"
|
||||
:description="noFailoverConfigured ? 'This deployment has no failover chains configured.' : undefined"
|
||||
:state="failoverState"
|
||||
show-empty
|
||||
empty-title="No failovers in this range."
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="failoverDatasets"
|
||||
aria-label="Failovers by provider over time"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<div class="grid gap-6 lg:grid-cols-2">
|
||||
<ChartCard
|
||||
title="Rate-limit rejections (429)"
|
||||
description="Fleet-wide, every scope combined."
|
||||
:state="reliabilityState"
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="rejectionDatasets"
|
||||
aria-label="Rate-limit rejections over time, fleet-wide"
|
||||
/>
|
||||
|
||||
<ChartCard
|
||||
title="Unpriced refusals (402)"
|
||||
description="Fleet-wide requests refused for having no resolvable price."
|
||||
:state="reliabilityState"
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="unpricedDatasets"
|
||||
aria-label="Unpriced refusals (402) over time, fleet-wide"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<EventsView />
|
||||
</div>
|
||||
</template>
|
||||
+243
-377
@@ -1,425 +1,291 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, watch } from 'vue'
|
||||
import { Button, Card, CardAction, CardContent, CardHeader, CardTitle, LineChart, NativeSelect, Pagination, SegmentedControl, StatusBadge } from '@perfect-design/ui'
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
|
||||
import ChartCard from '@/components/ChartCard.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import ErrorState from '@/components/ErrorState.vue'
|
||||
import EventsView from '@/components/EventsView.vue'
|
||||
import LabeledSelect from '@/components/LabeledSelect.vue'
|
||||
import SkeletonChart from '@/components/SkeletonChart.vue'
|
||||
import SkeletonList from '@/components/SkeletonList.vue'
|
||||
import StatDisabledAlert from '@/components/StatDisabledAlert.vue'
|
||||
import TimeSeriesChart from '@/components/TimeSeriesChart.vue'
|
||||
import type { TimeSeriesDataset } from '@/components/TimeSeriesChart.vue'
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { seriesColor } from '@/lib/chart-palette'
|
||||
import { formatBucketLabel, formatPercentAxis } from '@/lib/format'
|
||||
import { emptyWhenAllZero, loadState } from '@/lib/load-state'
|
||||
import type { LoadState } from '@/lib/load-state'
|
||||
import { formatErrorRatePercent } from '@/lib/provider-rate'
|
||||
import { useNow } from '@/composables/useNow'
|
||||
import { thinLabels } from '@/lib/chart-labels'
|
||||
import { formatBucketLabel, formatCompactCount, formatUntil } from '@/lib/format'
|
||||
import { loadState } from '@/lib/load-state'
|
||||
import { pageWindow } from '@/lib/paging'
|
||||
import { breakerRows } from '@/lib/provider-rate'
|
||||
import type { BreakerRow } from '@/lib/provider-rate'
|
||||
import { scopeId } from '@/lib/scope'
|
||||
import { wbColumns } from '@/lib/wb-columns'
|
||||
import { useDashboardStore } from '@/stores/dashboard'
|
||||
import { useEventsStore } from '@/stores/events'
|
||||
import { useFiltersStore } from '@/stores/filters'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
import { useReliabilityStore } from '@/stores/reliability'
|
||||
import type { CountSeries, ProviderRatioSeries } from '@/stores/reliability'
|
||||
import { hourOrDayWindow, useReliabilityStore } from '@/stores/reliability'
|
||||
import type { CountSeries } from '@/stores/reliability'
|
||||
import StateView from '@/widgets/StateView.vue'
|
||||
import type { ViewState } from '@/widgets/StateView.vue'
|
||||
import WbTable from '@/widgets/WbTable.vue'
|
||||
|
||||
const SEGMENTED_MAX = 4
|
||||
const BREAKER_PAGE_SIZE = 10
|
||||
const MAX_AXIS_LABELS = 6
|
||||
|
||||
interface BreakerView extends BreakerRow {
|
||||
until: string
|
||||
}
|
||||
|
||||
/**
|
||||
* ReliabilityPage (redesign-plan.md section 3.4) — error-rate/failover/
|
||||
* timeout/429/402 series, plus the pre-redesign Events view reused as a
|
||||
* section. Every chart is an on-demand fetch (useReliabilityStore.fetch),
|
||||
* not part of the 5s dashboard poll — refetched on mount and whenever the
|
||||
* global range changes (Q12 DECISIONS).
|
||||
*
|
||||
* Page params (redesign-plan.md section 3.1): `provider` narrows every
|
||||
* per-provider chart to one provider's own line ('' / absent means every
|
||||
* configured provider, overlaid); `kind`/`user` seed the embedded Events
|
||||
* section's own filters (stores/events.ts's initFromParams). All three
|
||||
* round-trip through the URL hash the same way EntityLink.vue's params do
|
||||
* — nav.goTo on every local change, read back via nav.params on mount.
|
||||
*/
|
||||
const dashboard = useDashboardStore()
|
||||
const events = useEventsStore()
|
||||
const filters = useFiltersStore()
|
||||
const nav = useNavStore()
|
||||
const reliability = useReliabilityStore()
|
||||
const { now, start: startClock, stop: stopClock } = useNow()
|
||||
|
||||
const selectedProvider = computed<string>(() => nav.params.provider ?? '')
|
||||
/** providerOptions feeds LabeledSelect's own options list — LabeledSelect owns the "All providers" -> '' sentinel mapping itself (reuse-audit.md F11), so this page no longer needs its own ALL_PROVIDERS_OPTION constant. */
|
||||
const providerOptions = computed(() => (dashboard.overview?.providers ?? []).map((p) => ({ value: p.name, label: p.name })))
|
||||
const overview = computed(() => dashboard.overview)
|
||||
const providers = computed(() => overview.value?.providers ?? [])
|
||||
const latencyEnabled = computed(() => overview.value?.features.latencyStats ?? false)
|
||||
|
||||
function onProviderChange(value: string): void {
|
||||
nav.goTo('reliability', { ...nav.params, provider: value })
|
||||
}
|
||||
|
||||
/** providerLabel strips the "provider:" scope prefix every reliability series carries (lib/scope.ts's shared scopeId, reuse-audit.md F5) — the display label is just the provider name. */
|
||||
function providerLabel(scope: string): string {
|
||||
return scopeId(scope)
|
||||
}
|
||||
|
||||
function filterSelected<T extends { scope: string }>(series: T[]): T[] {
|
||||
if (!selectedProvider.value) return series
|
||||
return series.filter((s) => providerLabel(s.scope) === selectedProvider.value)
|
||||
}
|
||||
|
||||
/**
|
||||
* NaN, not 0, marks a bucket with no attempts (errorRateSeries' own "null
|
||||
* means no traffic" convention) — chart.js draws a gap at a NaN point
|
||||
* rather than a misleading flat 0%, and NaN is still a plain `number`, so
|
||||
* TimeSeriesDataset's `data: number[]` needs no cast here.
|
||||
*/
|
||||
function toChartPoints(points: (number | null)[]): number[] {
|
||||
return points.map((p) => (p === null ? Number.NaN : p))
|
||||
}
|
||||
|
||||
const errorRateDatasets = computed<TimeSeriesDataset[]>(() =>
|
||||
filterSelected<ProviderRatioSeries>(reliability.errorRate).map((s, i) => ({
|
||||
label: providerLabel(s.scope),
|
||||
data: toChartPoints(s.points),
|
||||
color: seriesColor(i),
|
||||
})),
|
||||
const clampedNote = computed(() =>
|
||||
filters.window === 'month' ? `Reliability data is kept for 30 days. Showing the last 30 days, not ${filters.range}.` : null,
|
||||
)
|
||||
|
||||
function countDatasets(series: CountSeries[]): TimeSeriesDataset[] {
|
||||
return filterSelected(series).map((s, i) => ({ label: providerLabel(s.scope), data: s.points, color: seriesColor(i) }))
|
||||
// --- Provider picker --------------------------------------------------------
|
||||
|
||||
function total(series: CountSeries | undefined): number {
|
||||
return series ? series.points.reduce((a, b) => a + b, 0) : 0
|
||||
}
|
||||
|
||||
const timeoutDatasets = computed(() => countDatasets(reliability.timeouts))
|
||||
const failoverDatasets = computed(() => countDatasets(reliability.failovers))
|
||||
const defaultProvider = computed<string>(() => {
|
||||
const busiest = [...reliability.attempts].sort((a, b) => total(b) - total(a))[0]
|
||||
if (busiest && total(busiest) > 0) return scopeId(busiest.scope)
|
||||
const open = breakerRows(overview.value).find((r) => r.state !== 'closed')
|
||||
return open ? open.provider : (providers.value[0]?.name ?? '')
|
||||
})
|
||||
const selected = computed<string>(() => {
|
||||
const asked = nav.params.provider
|
||||
return asked && providers.value.some((p) => p.name === asked) ? asked : defaultProvider.value
|
||||
})
|
||||
const providerOptions = computed(() => providers.value.map((p) => ({ value: p.name, label: p.name })))
|
||||
|
||||
const rejectionDatasets = computed<TimeSeriesDataset[]>(() => [
|
||||
{ label: '429 rejections', data: reliability.rejections, color: '--destructive' },
|
||||
])
|
||||
const unpricedDatasets = computed<TimeSeriesDataset[]>(() => [
|
||||
{ label: '402 unpriced refusals', data: reliability.unpriced, color: '--status-warn' },
|
||||
])
|
||||
|
||||
const bucketLabels = computed<string[]>(() => reliability.buckets.map((b) => formatBucketLabel(b, reliability.windowUsed)))
|
||||
|
||||
/**
|
||||
* errorRatePercent adapts TimeSeriesChart's plain `number` valueFormatter
|
||||
* contract (NaN marks a no-attempts bucket, toChartPoints' own doc
|
||||
* comment) to lib/provider-rate.ts's shared formatErrorRatePercent, which
|
||||
* takes `null` for the identical "nothing to report" case — the actual
|
||||
* ceiling-percent/"no data" wording lives in exactly one place, shared
|
||||
* with lib/model-table-columns.ts's per-model error-rate column.
|
||||
*/
|
||||
function errorRatePercent(value: number): string {
|
||||
return formatErrorRatePercent(Number.isNaN(value) ? null : value)
|
||||
function pick(name: string): void {
|
||||
nav.goTo('reliability', { ...nav.params, provider: name })
|
||||
}
|
||||
|
||||
const hasProviders = computed(() => (dashboard.overview?.providers.length ?? 0) > 0)
|
||||
const noFailoverConfigured = computed(() => dashboard.overview !== null && dashboard.overview.features.failover === false)
|
||||
// --- Charts -----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* dashboardLoadState (live-preview fix, same class as verify-ui-states.md
|
||||
* #3): `hasProviders` alone reads false BOTH when the fleet genuinely has
|
||||
* no configured providers AND before the polled dashboard.overview has
|
||||
* ever landed (or after it failed to) — "No providers configured." used
|
||||
* to render as a false fleet fact on a deep link straight to this page,
|
||||
* before the 5s dashboard poll's first response arrives. Every OTHER page
|
||||
* already reads dashboard.overview after it has settled at least once
|
||||
* (they mount later in a typical session); this page can be the very
|
||||
* first thing mounted on a cold reload.
|
||||
*/
|
||||
const dashboardLoadState = computed(() => loadState({ loading: !dashboard.lastUpdated, hasData: dashboard.overview !== null, error: dashboard.error }))
|
||||
const bucketLabels = computed(() => thinLabels(reliability.buckets.map((b) => formatBucketLabel(b, reliability.windowUsed)), MAX_AXIS_LABELS))
|
||||
const perfLabels = computed(() =>
|
||||
thinLabels(reliability.providerPerfBuckets.map((b) => formatBucketLabel(b, reliability.providerPerfWindowUsed)), MAX_AXIS_LABELS),
|
||||
)
|
||||
|
||||
/**
|
||||
* providersState (live-preview fix: "per-provider charts briefly render an
|
||||
* empty grid before providers are known") gates the FOUR per-provider chart
|
||||
* cards below (error rate, selected provider performance, timeouts,
|
||||
* failovers) — the same three-way split lib/access-matrix.ts's
|
||||
* matrixColumnsState makes for AccessMatrix.vue's own columns: 'skeleton'
|
||||
* while dashboard.overview has not loaded yet (dashboardLoadState itself
|
||||
* still unsettled — this page is often the very first thing mounted on a
|
||||
* cold reload), 'error' forwarded from that same first-load failure,
|
||||
* 'empty' once overview has genuinely loaded with zero configured
|
||||
* providers (a real fleet fact, not a loading artifact), 'ready' once it
|
||||
* has loaded with at least one provider to chart.
|
||||
*/
|
||||
const providersState = computed<LoadState>(() => {
|
||||
if (dashboardLoadState.value !== 'ready') return dashboardLoadState.value
|
||||
return hasProviders.value ? 'ready' : 'empty'
|
||||
function pointsFor(series: CountSeries[], provider: string): number[] {
|
||||
const hit = series.find((s) => scopeId(s.scope) === provider)
|
||||
return hit ? hit.points : reliability.buckets.map(() => 0)
|
||||
}
|
||||
|
||||
const activityLines = computed(() => [
|
||||
{ name: 'Attempts', data: pointsFor(reliability.attempts, selected.value), tone: 'muted' as const },
|
||||
{ name: 'Failures', data: pointsFor(reliability.failures, selected.value), tone: 'danger' as const },
|
||||
{ name: 'Timeouts', data: pointsFor(reliability.timeouts, selected.value), tone: 'warning' as const },
|
||||
{ name: 'Failovers', data: pointsFor(reliability.failovers, selected.value), tone: 'info' as const },
|
||||
])
|
||||
const ttfbLines = computed(() => [
|
||||
{ name: 'TTFB p50', data: reliability.providerPerfPoints.map((p) => p.ttfbP50Ms ?? Number.NaN), tone: 'primary' as const },
|
||||
{ name: 'TTFB p95', data: reliability.providerPerfPoints.map((p) => p.ttfbP95Ms ?? Number.NaN), tone: 'warning' as const },
|
||||
])
|
||||
const rejectionLines = computed(() => [
|
||||
{ name: '429 rate limited', data: reliability.rejections, tone: 'danger' as const },
|
||||
{ name: '402 unpriced', data: reliability.unpriced, tone: 'warning' as const },
|
||||
])
|
||||
|
||||
const formatMs = (n: number): string => `${Math.round(n).toLocaleString('en-US')} ms`
|
||||
|
||||
const seriesState = computed<ViewState>(() => {
|
||||
if (providers.value.length === 0 && overview.value !== null) return 'empty'
|
||||
const s = loadState({ loading: reliability.loading || reliability.lastUpdated === null, hasData: reliability.lastUpdated !== null, error: reliability.error })
|
||||
return s === 'skeleton' ? 'loading' : s === 'error' ? 'error' : 'ready'
|
||||
})
|
||||
const activityState = computed<ViewState>(() => (seriesState.value === 'ready' && activityLines.value.every((l) => l.data.every((v) => v === 0)) ? 'empty' : seriesState.value))
|
||||
const rejectionState = computed<ViewState>(() => (seriesState.value === 'ready' && reliability.buckets.length === 0 ? 'empty' : seriesState.value))
|
||||
const ttfbState = computed<ViewState>(() => {
|
||||
if (!latencyEnabled.value) return 'empty'
|
||||
const s = loadState({ loading: reliability.providerPerfLoading, hasData: reliability.providerPerfPoints.length > 0, error: reliability.providerPerfError })
|
||||
if (s === 'skeleton') return 'loading'
|
||||
if (s === 'error') return 'error'
|
||||
return ttfbLines.value.every((l) => l.data.every((v) => Number.isNaN(v))) ? 'empty' : 'ready'
|
||||
})
|
||||
|
||||
// --- selected-provider performance (N3 fix, redesign-plan.md section
|
||||
// 3.3: "performance series=1 for the selected provider") ---
|
||||
const latencyStatsEnabled = computed(() => dashboard.overview?.features.latencyStats ?? false)
|
||||
/** providerPerfAvailable gates the whole selected-provider chart section — both conditions the task names ("when a provider is selected and latency stats are enabled"), mirroring reliability.fetchProviderPerf's own short-circuit so the fetch and the render never disagree about when there is data to show. */
|
||||
const providerPerfAvailable = computed(() => selectedProvider.value !== '' && latencyStatsEnabled.value)
|
||||
// --- Breaker table ----------------------------------------------------------
|
||||
|
||||
const providerPerfBucketLabels = computed<string[]>(() =>
|
||||
reliability.providerPerfBuckets.map((b) => formatBucketLabel(b, reliability.providerPerfWindowUsed)),
|
||||
)
|
||||
/** p50/p95 read as NaN (a chart.js gap, toChartPoints' own convention above) for a bucket with no observations — AdminPerfRow's own doc comment: undefined never means 0ms. */
|
||||
const providerLatencyDatasets = computed<TimeSeriesDataset[]>(() => [
|
||||
{ label: 'p50', data: reliability.providerPerfPoints.map((p) => p.p50Ms ?? Number.NaN), color: '--chart-requests' },
|
||||
{ label: 'p95', data: reliability.providerPerfPoints.map((p) => p.p95Ms ?? Number.NaN), color: '--chart-tokens-in' },
|
||||
])
|
||||
const providerFailureDatasets = computed<TimeSeriesDataset[]>(() => [
|
||||
{ label: 'failures', data: reliability.providerPerfPoints.map((p) => p.failures), color: '--destructive' },
|
||||
const breakerColumns = wbColumns<BreakerView>([
|
||||
{ key: 'provider', header: 'Provider', kind: 'text', sortable: false },
|
||||
{ key: 'state', header: 'State', kind: 'status', sortable: false },
|
||||
{ key: 'until', header: 'Opens until', kind: 'time', sortable: false },
|
||||
{ key: 'lastErr', header: 'Last error', kind: 'text', sortable: false },
|
||||
])
|
||||
|
||||
const STATE_TONE = { closed: 'success', open: 'danger', 'half-open': 'warning' } as const
|
||||
|
||||
const breakers = computed<BreakerView[]>(() => {
|
||||
void now.value
|
||||
return breakerRows(overview.value).map((r) => ({ ...r, until: r.state === 'open' ? formatUntil(r.openUntil) || 'due' : '' }))
|
||||
})
|
||||
const breakerPage = ref(1)
|
||||
const breakerWindow = computed(() => pageWindow(breakers.value.length, BREAKER_PAGE_SIZE, breakerPage.value - 1))
|
||||
const breakerPaged = computed(() => breakers.value.slice(breakerWindow.value.from, breakerWindow.value.to))
|
||||
const breakerState = computed<ViewState>(() => (overview.value === null ? 'loading' : breakers.value.length === 0 ? 'empty' : 'ready'))
|
||||
const openCount = computed(() => breakers.value.filter((r) => r.state !== 'closed').length)
|
||||
|
||||
// --- Lifecycle --------------------------------------------------------------
|
||||
|
||||
watch(
|
||||
() => [selectedProvider.value, filters.range] as const,
|
||||
() => [filters.range, providers.value.length],
|
||||
() => void reliability.fetch(),
|
||||
)
|
||||
watch(
|
||||
() => [selected.value, filters.range, latencyEnabled.value] as const,
|
||||
([provider]) => void reliability.fetchProviderPerf(provider),
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
/**
|
||||
* monthRangeClamped is true whenever the global range is a month preset
|
||||
* (3mo/6mo/12mo) — stores/reliability.ts's own hourOrDayWindow has NO
|
||||
* month bucket at all for any reliability metric (its own doc comment:
|
||||
* "neither family has a month bucket at all, matching their own 48h/35d
|
||||
* TTLs"), so it substitutes a fixed 30-day day-window instead. Every
|
||||
* chart below silently shows that 30-day window regardless of which
|
||||
* month preset is selected — this note (P3 item 20) says so, rather than
|
||||
* letting a reader believe a "12mo" label over a chart that is actually
|
||||
* showing the most recent 30 days.
|
||||
*/
|
||||
const monthRangeClamped = computed(() => filters.window === 'month')
|
||||
|
||||
// --- skeleton/error states (verify-ui-states.md #7: "Spend and
|
||||
// Reliability pages got no skeletons or ErrorState") -----------------------
|
||||
|
||||
/**
|
||||
* reliabilityState (lib/load-state.ts) gates every fleet-wide chart on this
|
||||
* page (error rate, timeouts, failovers, rejections, unpriced) — all five
|
||||
* are populated by the ONE reliability.fetch() call, so one shared state is
|
||||
* correct rather than each chart re-deriving its own from the same three
|
||||
* underlying signals. Checked FIRST: dashboardLoadState — reliability.fetch
|
||||
* (stores/reliability.ts) now no-ops while dashboard.overview has not
|
||||
* loaded yet, rather than resolving as "loaded, empty" (the live-preview
|
||||
* fix this composition closes), so reliability.loading/buckets/error alone
|
||||
* can no longer be trusted to read 'skeleton' during that window; once
|
||||
* dashboardLoadState settles 'ready', this falls through to reliability's
|
||||
* own loading/buckets/error exactly as before.
|
||||
*/
|
||||
const reliabilityState = computed<LoadState>(() => {
|
||||
if (dashboardLoadState.value !== 'ready') return dashboardLoadState.value
|
||||
return loadState({ loading: reliability.loading, hasData: reliability.buckets.length > 0, error: reliability.error })
|
||||
onMounted(() => {
|
||||
startClock()
|
||||
void reliability.fetch()
|
||||
})
|
||||
onUnmounted(stopClock)
|
||||
|
||||
/** Count charts with nothing to plot show a message instead of an empty 0-1 axis. */
|
||||
const timeoutState = computed<LoadState>(() => emptyWhenAllZero(reliabilityState.value, timeoutDatasets.value))
|
||||
const failoverState = computed<LoadState>(() => emptyWhenAllZero(reliabilityState.value, failoverDatasets.value))
|
||||
/** providerPerfState mirrors reliabilityState for the "Selected provider performance" chart pair — reliability.fetchProviderPerf runs independently of fetch() (its own doc comment), so it needs its own loading/error signal, only reachable once providerPerfAvailable is already true. */
|
||||
const providerPerfState = computed(() =>
|
||||
loadState({ loading: reliability.providerPerfLoading, hasData: reliability.providerPerfPoints.length > 0, error: reliability.providerPerfError }),
|
||||
)
|
||||
|
||||
// Refetch whenever the global range changes (Q12 DECISIONS: "new endpoints
|
||||
// on demand or 60s" — this is the "on demand" case, driven by the reader's
|
||||
// own range choice rather than a timer) or once the dashboard's 5s poll
|
||||
// first discovers which providers are configured (a page that mounts
|
||||
// before the first overview poll lands would otherwise see hasProviders
|
||||
// flip true with no series fetched yet to back it).
|
||||
watch(
|
||||
() => [filters.range, dashboard.overview?.providers.length ?? 0],
|
||||
() => void reliability.fetch(),
|
||||
)
|
||||
|
||||
// kind/user round-trip back into the URL hash (redesign-plan.md section
|
||||
// 3.1's Reliability page params) whenever the reader changes the embedded
|
||||
// Events section's own filters — mirrors `provider`'s own onProviderChange
|
||||
// above, one nav.goTo call merging every current page param so neither
|
||||
// write clobbers the other.
|
||||
watch(
|
||||
() => [events.kindFilter, events.userFilter],
|
||||
([kind, user]) => {
|
||||
nav.goTo('reliability', { ...nav.params, kind, user })
|
||||
},
|
||||
)
|
||||
|
||||
// nav.params.kind/user react to a hash change this page's own Select/
|
||||
// SearchInput did NOT originate — browser back/forward, a hand-edited URL,
|
||||
// or returning here via the sidebar with the param cleared (P2 item 10:
|
||||
// stores/events.ts's own initFromParams applies a param only when it is
|
||||
// PRESENT, by design, for a one-shot seed — but called only on mount, that
|
||||
// left a kind/user filter set on an earlier visit stuck in place when the
|
||||
// reader returned with an empty hash). `immediate: true` covers the
|
||||
// initial mount too, so this replaces that one-shot call outright.
|
||||
// Undefined always resolves to '' ("no filter"), and this never loops
|
||||
// against the watch above: assigning a store field its OWN current value
|
||||
// is a same-value write, which Vue's reactivity does not re-trigger a
|
||||
// dependent watch for.
|
||||
watch(
|
||||
() => [nav.params.kind, nav.params.user] as const,
|
||||
([kind, user]) => {
|
||||
events.setKindFilter(kind ?? '')
|
||||
events.setUserFilter(user ?? '')
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
onMounted(() => void reliability.fetch())
|
||||
const windowUsed = computed(() => hourOrDayWindow(filters.window, filters.span))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-6">
|
||||
<Card>
|
||||
<CardHeader class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<CardTitle>Reliability</CardTitle>
|
||||
<CardDescription>Provider error rate, failovers, timeouts, rate-limit rejections, and 402 refusals.</CardDescription>
|
||||
</div>
|
||||
<LabeledSelect
|
||||
label="Provider"
|
||||
:model-value="selectedProvider"
|
||||
<div class="flex flex-col gap-4">
|
||||
<div
|
||||
v-if="clampedNote"
|
||||
role="note"
|
||||
class="border-border bg-card text-muted-foreground rounded-md border px-3 py-2 text-sm"
|
||||
data-testid="clamped-range"
|
||||
>
|
||||
{{ clampedNote }}
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div class="flex min-w-0 flex-wrap items-center gap-3">
|
||||
<span class="text-muted-foreground text-xs">Provider</span>
|
||||
<SegmentedControl
|
||||
v-if="providerOptions.length > 0 && providerOptions.length <= SEGMENTED_MAX"
|
||||
:model-value="selected"
|
||||
:options="providerOptions"
|
||||
all-label="All providers"
|
||||
trigger-class="w-48"
|
||||
@update:model-value="onProviderChange"
|
||||
size="sm"
|
||||
aria-label="Provider"
|
||||
@update:model-value="pick"
|
||||
/>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<SkeletonList v-if="dashboardLoadState === 'skeleton'" :rows="2" />
|
||||
<ErrorState v-else-if="dashboardLoadState === 'error'" :message="dashboard.error" :on-retry="dashboard.refresh" />
|
||||
<p v-else-if="reliability.error" class="text-sm break-words text-destructive">{{ reliability.error }}</p>
|
||||
<EmptyState v-else-if="!hasProviders" title="No providers configured." />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Alert v-if="monthRangeClamped" variant="warn">
|
||||
<AlertDescription>
|
||||
Reliability data has no monthly retention — every chart below shows the most recent 30 days, not the full
|
||||
{{ filters.range }} range selected above.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
<!--
|
||||
providersState (live-preview fix: "per-provider charts briefly render
|
||||
an empty grid before providers are known") gates this whole group of
|
||||
FOUR per-provider cards as one unit — 'skeleton' while
|
||||
dashboard.overview has not loaded, 'empty' once it has loaded with
|
||||
zero configured providers (a real fleet fact, shown once via a single
|
||||
EmptyState rather than four repeated ones), 'ready' to render the
|
||||
actual charts below exactly as before.
|
||||
-->
|
||||
<template v-if="providersState === 'skeleton'">
|
||||
<ChartCard title="Error rate by provider" state="skeleton" />
|
||||
<ChartCard title="Selected provider performance" state="skeleton" />
|
||||
<ChartCard title="Timeouts by provider" state="skeleton" />
|
||||
<ChartCard title="Failovers by provider" state="skeleton" />
|
||||
</template>
|
||||
<Card v-else-if="providersState === 'empty'">
|
||||
<CardContent>
|
||||
<EmptyState
|
||||
title="No providers configured."
|
||||
description="Add a providers entry to the middleware config to see per-provider reliability charts here."
|
||||
<NativeSelect
|
||||
v-else-if="providerOptions.length > SEGMENTED_MAX"
|
||||
class="max-w-56"
|
||||
:model-value="selected"
|
||||
:options="providerOptions"
|
||||
size="sm"
|
||||
aria-label="Provider"
|
||||
@update:model-value="pick"
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<template v-else-if="providersState === 'ready'">
|
||||
<ChartCard
|
||||
title="Error rate by provider"
|
||||
description="Failed attempts / total attempts per bucket. A gap means no attempts in that bucket."
|
||||
:state="reliabilityState"
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="errorRateDatasets"
|
||||
:value-formatter="errorRatePercent"
|
||||
:axis-formatter="formatPercentAxis"
|
||||
aria-label="Error rate by provider over time"
|
||||
/>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" :disabled="!selected" @click="nav.goTo('events', { provider: selected }, { replace: false })">
|
||||
Events for {{ selected || 'provider' }}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Selected provider performance</CardTitle>
|
||||
<CardDescription>Latency (p50/p95) and failures per bucket for one provider.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-4">
|
||||
<p v-if="selectedProvider === ''" class="text-sm text-muted-foreground">
|
||||
Select a provider above to see its latency and failure breakdown per bucket.
|
||||
</p>
|
||||
<StatDisabledAlert
|
||||
v-else-if="!latencyStatsEnabled"
|
||||
title="Latency statistics are off"
|
||||
config-key="admin.stats.latency"
|
||||
:purpose="`to see per-bucket latency for ${selectedProvider}.`"
|
||||
/>
|
||||
<template v-else-if="providerPerfAvailable">
|
||||
<SkeletonChart v-if="providerPerfState === 'skeleton'" />
|
||||
<ErrorState
|
||||
v-else-if="providerPerfState === 'error'"
|
||||
:message="reliability.providerPerfError"
|
||||
:on-retry="() => reliability.fetchProviderPerf(selectedProvider)"
|
||||
/>
|
||||
<div v-else class="grid gap-6 lg:grid-cols-2">
|
||||
<div>
|
||||
<p class="mb-2 text-sm font-medium text-muted-foreground">Latency (ms)</p>
|
||||
<TimeSeriesChart
|
||||
:labels="providerPerfBucketLabels"
|
||||
:datasets="providerLatencyDatasets"
|
||||
:ariaLabel="`p50/p95 latency for ${selectedProvider} over time`"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<p class="mb-2 text-sm font-medium text-muted-foreground">Failures</p>
|
||||
<TimeSeriesChart
|
||||
:labels="providerPerfBucketLabels"
|
||||
:datasets="providerFailureDatasets"
|
||||
:ariaLabel="`Failures for ${selectedProvider} over time`"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
<Card size="sm">
|
||||
<CardHeader><CardTitle>Attempts, failures, timeouts, failovers</CardTitle></CardHeader>
|
||||
<CardContent>
|
||||
<StateView
|
||||
:state="activityState"
|
||||
empty-title="No attempts in this range"
|
||||
:error-message="reliability.error"
|
||||
@retry="reliability.fetch()"
|
||||
>
|
||||
<div data-wb-ignore-numeric>
|
||||
<LineChart
|
||||
:labels="bucketLabels"
|
||||
:series="activityLines"
|
||||
:height="220"
|
||||
:value-formatter="formatCompactCount"
|
||||
:label="`Attempts, failures, timeouts and failovers for ${selected} per ${windowUsed.window}`"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</StateView>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<ChartCard
|
||||
title="Timeouts by provider"
|
||||
:state="timeoutState"
|
||||
show-empty
|
||||
empty-title="No timeouts in this range."
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="timeoutDatasets"
|
||||
aria-label="Timeouts by provider over time"
|
||||
/>
|
||||
|
||||
<ChartCard
|
||||
title="Failovers by provider"
|
||||
:description="noFailoverConfigured ? 'This deployment has no failover chains configured.' : undefined"
|
||||
:state="failoverState"
|
||||
show-empty
|
||||
empty-title="No failovers in this range."
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="failoverDatasets"
|
||||
aria-label="Failovers by provider over time"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<div class="grid gap-6 lg:grid-cols-2">
|
||||
<ChartCard
|
||||
title="Rate-limit rejections (429)"
|
||||
description="Fleet-wide, every scope combined."
|
||||
:state="reliabilityState"
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="rejectionDatasets"
|
||||
aria-label="Rate-limit rejections over time, fleet-wide"
|
||||
/>
|
||||
|
||||
<ChartCard
|
||||
title="Unpriced refusals (402)"
|
||||
description="Fleet-wide requests refused for having no resolvable price."
|
||||
:state="reliabilityState"
|
||||
:error="reliability.error"
|
||||
:on-retry="reliability.fetch"
|
||||
:labels="bucketLabels"
|
||||
:datasets="unpricedDatasets"
|
||||
aria-label="Unpriced refusals (402) over time, fleet-wide"
|
||||
/>
|
||||
<Card size="sm">
|
||||
<CardHeader><CardTitle>Time to first byte</CardTitle></CardHeader>
|
||||
<CardContent>
|
||||
<StateView
|
||||
:state="ttfbState"
|
||||
:empty-title="latencyEnabled ? 'No latency samples in this range' : 'Latency statistics are off'"
|
||||
:empty-description="latencyEnabled ? undefined : 'Enable admin.stats.latency to chart time to first byte.'"
|
||||
:error-message="reliability.providerPerfError"
|
||||
@retry="reliability.fetchProviderPerf(selected)"
|
||||
>
|
||||
<div data-wb-ignore-numeric>
|
||||
<LineChart
|
||||
:labels="perfLabels"
|
||||
:series="ttfbLines"
|
||||
:height="220"
|
||||
:value-formatter="formatMs"
|
||||
:label="`Time to first byte p50 and p95 for ${selected}`"
|
||||
/>
|
||||
</div>
|
||||
</StateView>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<EventsView />
|
||||
<div class="grid grid-cols-1 items-start gap-4 lg:grid-cols-2">
|
||||
<Card size="sm">
|
||||
<CardHeader class="items-center">
|
||||
<CardTitle>Circuit breakers</CardTitle>
|
||||
<CardAction class="text-muted-foreground self-center text-xs">{{ openCount }} not closed</CardAction>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-2">
|
||||
<StateView :state="breakerState" empty-title="No providers configured" :error-message="dashboard.error" @retry="dashboard.refresh()">
|
||||
<WbTable
|
||||
class="wb-clip"
|
||||
:columns="breakerColumns"
|
||||
:rows="breakerPaged"
|
||||
row-key="provider"
|
||||
label="Provider circuit breakers"
|
||||
@row-activate="(row: BreakerView) => nav.openPanel('provider', row.provider)"
|
||||
>
|
||||
<template #cell-state="{ value }">
|
||||
<StatusBadge :status="value as string" :tones="STATE_TONE" size="sm" />
|
||||
</template>
|
||||
<template #cell-until="{ value }">{{ value || '—' }}</template>
|
||||
<template #cell-lastErr="{ value }">
|
||||
<span class="wb-err" :title="(value as string) || undefined">{{ value || '—' }}</span>
|
||||
</template>
|
||||
</WbTable>
|
||||
<div v-if="breakers.length > BREAKER_PAGE_SIZE" class="flex items-center justify-between gap-2">
|
||||
<span class="text-muted-foreground text-xs">{{ breakers.length.toLocaleString('en-US') }} providers</span>
|
||||
<Pagination v-model:page="breakerPage" :total="breakers.length" :page-size="BREAKER_PAGE_SIZE" variant="compact" size="sm" />
|
||||
</div>
|
||||
</StateView>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card size="sm">
|
||||
<CardHeader><CardTitle>Rejections</CardTitle></CardHeader>
|
||||
<CardContent>
|
||||
<StateView
|
||||
:state="rejectionState"
|
||||
empty-title="No rejections in this range"
|
||||
:error-message="reliability.error"
|
||||
@retry="reliability.fetch()"
|
||||
>
|
||||
<div data-wb-ignore-numeric>
|
||||
<LineChart
|
||||
:labels="bucketLabels"
|
||||
:series="rejectionLines"
|
||||
:height="220"
|
||||
:value-formatter="formatCompactCount"
|
||||
label="Rejections by 429 rate limit and 402 unpriced refusal, fleet-wide"
|
||||
/>
|
||||
</div>
|
||||
</StateView>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -74,6 +74,10 @@ export const useReliabilityStore = defineStore('reliability', {
|
||||
windowUsed: 'day' as Extract<HistoryWindow, 'hour' | 'day'>,
|
||||
/** Per-provider fail/attempt ratio, one entry per configured provider. */
|
||||
errorRate: [] as ProviderRatioSeries[],
|
||||
/** Per-provider attempt count series (metric `attempt`). */
|
||||
attempts: [] as CountSeries[],
|
||||
/** Per-provider failure count series (metric `fail`). */
|
||||
failures: [] as CountSeries[],
|
||||
/** Per-provider timeout count series (metric `timeout`). */
|
||||
timeouts: [] as CountSeries[],
|
||||
/** Per-provider failover count series (metric `fover`) — a provider's OWN candidates that were failed away FROM, per accountExtras.failoverFrom's own doc comment (redesign-plan.md section 2b). */
|
||||
@@ -131,6 +135,8 @@ export const useReliabilityStore = defineStore('reliability', {
|
||||
this.buckets = []
|
||||
this.windowUsed = hourOrDayWindow(filters.window, filters.span).window
|
||||
this.errorRate = []
|
||||
this.attempts = []
|
||||
this.failures = []
|
||||
this.timeouts = []
|
||||
this.failovers = []
|
||||
this.rejections = []
|
||||
@@ -158,6 +164,8 @@ export const useReliabilityStore = defineStore('reliability', {
|
||||
// A provider with no attempts in the window is idle, not healthy: keep it out of every legend.
|
||||
const active = activeScopes(attemptRes.series)
|
||||
this.errorRate = errorRateSeries(attemptRes, failRes).filter((s) => active.has(s.scope))
|
||||
this.attempts = attemptRes.series.filter((s) => active.has(s.scope))
|
||||
this.failures = failRes.series.filter((s) => active.has(s.scope))
|
||||
this.timeouts = timeoutRes.series.filter((s) => active.has(s.scope))
|
||||
this.failovers = foverRes.series.filter((s) => active.has(s.scope))
|
||||
this.rejections = rejRes.series[0]?.points ?? []
|
||||
|
||||
Reference in New Issue
Block a user