mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-30 01:32:00 +01:00
Show when TrueNAS protection readings are stale (#5289)
**Show when TrueNAS protection readings are stale** Pass the already-hydrated TrueNAS system resources from TrueNASPageSurface into TrueNASProtectionTable so /truenas/protection surfaces backend-owned TrueNAS collection errors, telemetry_stale health, and offline systems truthfully instead of leaving cached ZFS snapshots and replication tasks green Healthy or pulsing Running. - Match each TrueNAS recovery point to its owning TrueNAS system by connectionId/providerScope first (preserving DR-clone isolation across shared hostnames), then unambiguous hostname, then all-stale fallback when host metadata is absent. - Exclude stale healthy and running points from Healthy and Running filter counts, surface a dynamic amber Stale filter chip alongside Attention, rank stale events above fresh ones, and index stale details in search. - Render amber Stale data badges for stale healthy points (Stale on phone), preserve red Failed / Warning / non-pulsing muted Running / Unknown badges with an amber Stale data cue beneath the dataset name, and show an amber InlineNotice plus Status and Last reported rows inside the expanded detail drawer that clear reactively on live WebSocket recovery. Contract-Neutral: UI freshness presentation using existing TrueNAS system resources and /api/recovery/points fields without changing API payloads, polling, alerts, telemetry, or routes. **Call getRecoveryOutcomeBadgeClass directly in TrueNASProtectionTable** Inline the canonical getRecoveryOutcomeBadgeClass call so canonical-platform-audit passes with no local recovery outcome badge helper. Contract-Neutral: presentation-only helper cleanup with no API, schema, or subsystem contract delta. **Format TrueNAS protection freshness files with Prettier** Apply Prettier 100-column line wrapping to truenasPageModel.ts, TrueNASProtectionTable.tsx, and TrueNASProtectionTable.freshness.test.tsx so format:check passes cleanly. Contract-Neutral: formatting only with no runtime, API, schema, or subsystem contract delta. **Format TrueNAS protection freshness test with Prettier** Apply Prettier formatting to TrueNASProtectionTable.freshness.test.tsx so format:check passes on every touched file. Contract-Neutral: test formatting only with no runtime or contract delta. **Use canonicalIdentity, update copy punctuation, and align posture tests** Read system.canonicalIdentity on Resource in truenasPageModel.ts for TypeScript strictness, replace the semicolon in the stale protection drawer notice with a sentence boundary for copy-style-audit, and update TrueNAS protection posture tests for the stale count field. Contract-Neutral: type-safety, user-copy punctuation, and unit-test alignment with no API, schema, or subsystem contract delta. **Record browser verification for TrueNAS protection stale readings** Records paired production-build Playwright verification (desktop Chromium 1440x940 light stale + live WebSocket recovery and touch phone WebKit 360x820 dark collapsed + expanded drawer) for TrueNASPageSurface.tsx, TrueNASProtectionTable.tsx, TrueNASTableFrame.tsx, and truenasPageModel.ts. Contract-Neutral: browser verification receipt only; no runtime or contract change. --- Fleet candidate `20261127T144329Z-web-product` from the `web-product` lane. Reviewed tip `fdbc37ef9a2fa348b13e242cc12f3e9513c811e6` on `main`. [How Pulse handles triage](https://github.com/rcourtman/Pulse/blob/main/docs/AI_TRANSPARENCY.md)
This commit is contained in:
42
frontend-modern/browser-verification/b297813a5866ffe6.json
Normal file
42
frontend-modern/browser-verification/b297813a5866ffe6.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"version": 1,
|
||||
"base_sha": "732a43fc7490502f500f0536c3cea881149df8e0",
|
||||
"verified_at": "2026-11-27T15:52:12Z",
|
||||
"result": "passed",
|
||||
"changed_paths": [
|
||||
"frontend-modern/src/features/truenas/TrueNASPageSurface.tsx",
|
||||
"frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx",
|
||||
"frontend-modern/src/features/truenas/TrueNASTableFrame.tsx",
|
||||
"frontend-modern/src/features/truenas/truenasPageModel.ts"
|
||||
],
|
||||
"content_sha256": {
|
||||
"frontend-modern/src/features/truenas/TrueNASPageSurface.tsx": "2607c299c5581f8a5e9b1370e8a6df9786c2e66d26a17d4e3f2c72084f0082a7",
|
||||
"frontend-modern/src/features/truenas/TrueNASProtectionTable.tsx": "4dcaf4998deafe4cb2febaf2f3953baf0046ef881d5246e855ae28de2560c3ad",
|
||||
"frontend-modern/src/features/truenas/TrueNASTableFrame.tsx": "dac0de9ae517f8e1fac4ccf9f0205c81268210a955cd5ba584b421be9ddac785",
|
||||
"frontend-modern/src/features/truenas/truenasPageModel.ts": "cef8ff4b77c9be5dba3fa14b043ebd94f89f02e90a09379eb98d455e05ad5f23"
|
||||
},
|
||||
"routes": [
|
||||
"/truenas/protection"
|
||||
],
|
||||
"viewports": [
|
||||
{
|
||||
"width": 1440,
|
||||
"height": 940
|
||||
},
|
||||
{
|
||||
"width": 360,
|
||||
"height": 820
|
||||
}
|
||||
],
|
||||
"states": [
|
||||
"Playwright 1.56.1 paired production builds (before a366d7c0a708 vs after 732a43fc7490) on desktop Chromium 141.0.7390.37 (1440x940 light) and touch WebKit 26.0 (360x820 dark); all 8 paired screenshots visually inspected with 0 console errors, 0 page errors, 0 failed requests, 0 off-origin requests, and 0px horizontal overflow.",
|
||||
"/truenas/protection stale appliance nas-east (18m telemetry_stale, API connection timed out) alongside fresh nas-west: chips shift from false All 4 / Attention 1 / Healthy 2 / Failed 1 / Running 1 to All 4 / Attention 3 / Stale 3 / Healthy 1 / Failed 1 / Running 0; tank/billing moves from false green Healthy to amber Stale data (compact Stale on 360px phone) above fresh vault/docs; tank/archive preserves red Failed pill and tank/media preserves non-pulsing muted Running pill alongside amber Stale data cue beneath dataset name; expanded tank/billing drawer renders amber warning banner, amber Status: Stale data, and preserved green Last reported: Healthy.",
|
||||
"/truenas/protection live WebSocket rawData recovery frame (top-level sourceStatus.truenas online and health.verdict ok while platformData.sourceStatus remains stale) without reload: immediately clears all Stale data cues, Stale filter chip, and open drawer warning banner, restores green Healthy on tank/billing and pulsing blue Running on tank/media, and restores All 4 / Attention 1 / Healthy 2 / Failed 1 / Running 1.",
|
||||
"/truenas/protection touch WebKit phone (360x820 dark): exact 32px row height on all 4 rows, 0px horizontal overflow in both collapsed list and expanded stale drawer, clean wrapped dark-amber warning notice."
|
||||
],
|
||||
"interactions": [
|
||||
"Loaded /truenas/protection on desktop light (1440x940) and touch phone dark (360x820), verifying filter chip counts, row ordering, stale cues, non-pulsing stale running state, exact 32px phone row height, and 0px overflow.",
|
||||
"Clicked/tapped tank/billing row on desktop and phone to expand its inline detail drawer and verified the amber stale warning banner, Status: Stale data, Last reported: Healthy, and preserved snapshot/target metadata.",
|
||||
"Delivered live WebSocket rawData recovery frame on desktop while tank/billing drawer remained open and verified immediate clearance of stale cues, Stale filter chip, and open drawer banner without reload."
|
||||
]
|
||||
}
|
||||
@@ -252,7 +252,11 @@ export function TrueNASPageSurface() {
|
||||
/>
|
||||
</Show>
|
||||
<Show when={activeTab() === 'protection'}>
|
||||
<TrueNASProtection recoveryPoints={protection} {...tableSearch} />
|
||||
<TrueNASProtection
|
||||
recoveryPoints={protection}
|
||||
systems={model().systems}
|
||||
{...tableSearch}
|
||||
/>
|
||||
</Show>
|
||||
</Show>
|
||||
</Show>
|
||||
@@ -289,13 +293,17 @@ function TrueNASStorage(props: TrueNASStorageProps) {
|
||||
}
|
||||
|
||||
function TrueNASProtection(
|
||||
props: { recoveryPoints: ReturnType<typeof useRecoveryPoints> } & TrueNASTableSearchProps,
|
||||
props: {
|
||||
recoveryPoints: ReturnType<typeof useRecoveryPoints>;
|
||||
systems: Resource[];
|
||||
} & TrueNASTableSearchProps,
|
||||
) {
|
||||
return (
|
||||
<TrueNASProtectionTable
|
||||
search={props.search}
|
||||
onSearchChange={props.onSearchChange}
|
||||
points={props.recoveryPoints.points()}
|
||||
systems={props.systems}
|
||||
loading={props.recoveryPoints.response.loading}
|
||||
error={props.recoveryPoints.response.error}
|
||||
onRefresh={() => void props.recoveryPoints.refetch()}
|
||||
|
||||
@@ -26,16 +26,24 @@ import {
|
||||
type PlatformTableFilterOption,
|
||||
type PlatformTableSortValue,
|
||||
} from '@/features/platformPage/sharedPlatformPage';
|
||||
import { TrueNASRowLead, TrueNASTableFrame, createTrueNASDetailState } from './TrueNASTableFrame';
|
||||
import {
|
||||
TrueNASRowLead,
|
||||
TrueNASStaleBadge,
|
||||
TrueNASTableFrame,
|
||||
createTrueNASDetailState,
|
||||
} from './TrueNASTableFrame';
|
||||
import { getPlatformResourceDetailRowClass } from '@/features/platformPage/PlatformResourceDetailTableRow';
|
||||
import type { RecoveryPoint } from '@/types/recovery';
|
||||
import type { Resource } from '@/types/resource';
|
||||
import {
|
||||
filterTrueNASProtectionPoints,
|
||||
buildTrueNASProtectionPosture,
|
||||
buildTrueNASProtectionStaleNoticeMap,
|
||||
filterTrueNASProtectionPoints,
|
||||
mapTrueNASProtectionKind,
|
||||
mapTrueNASProtectionStatus,
|
||||
sortTrueNASProtectionPoints,
|
||||
type TrueNASProtectionKind,
|
||||
type TrueNASProtectionStaleNotice,
|
||||
type TrueNASProtectionStatusBucket,
|
||||
type TrueNASProtectionStatusFilter,
|
||||
} from './truenasPageModel';
|
||||
@@ -49,6 +57,13 @@ import {
|
||||
} from '@/components/shared/DetailSectionTable';
|
||||
import { RecordOwnerLink } from '@/features/platformPage/RecordOwnerLink';
|
||||
|
||||
const TRUENAS_PROTECTION_STALE_OPTION: PlatformTableFilterOption<TrueNASProtectionStatusFilter> = {
|
||||
value: 'stale',
|
||||
label: 'Stale',
|
||||
compactLabel: 'Stale',
|
||||
tone: 'warning',
|
||||
};
|
||||
|
||||
const TRUENAS_PROTECTION_STATUS_OPTIONS: PlatformTableFilterOption<TrueNASProtectionStatusFilter>[] =
|
||||
[
|
||||
{ value: 'all', label: 'All' },
|
||||
@@ -191,6 +206,7 @@ type TrueNASProtectionSortKey = (typeof TRUENAS_PROTECTION_SORT_KEYS)[number];
|
||||
const getTrueNASProtectionSortValue = (
|
||||
point: RecoveryPoint,
|
||||
key: TrueNASProtectionSortKey,
|
||||
staleNotice?: TrueNASProtectionStaleNotice,
|
||||
): PlatformTableSortValue => {
|
||||
switch (key) {
|
||||
case 'dataset':
|
||||
@@ -207,8 +223,12 @@ const getTrueNASProtectionSortValue = (
|
||||
return typeof point.sizeBytes === 'number' && Number.isFinite(point.sizeBytes)
|
||||
? point.sizeBytes
|
||||
: null;
|
||||
case 'outcome':
|
||||
return getRecoveryOutcomeLabel(normalizeRecoveryOutcome(point.outcome));
|
||||
case 'outcome': {
|
||||
const outcome = normalizeRecoveryOutcome(point.outcome);
|
||||
return staleNotice && outcome === 'success'
|
||||
? staleNotice.badge
|
||||
: getRecoveryOutcomeLabel(outcome);
|
||||
}
|
||||
default:
|
||||
key satisfies never;
|
||||
return null;
|
||||
@@ -255,15 +275,23 @@ const sourceDatasetsLabel = (point: RecoveryPoint): string | null => {
|
||||
return datasets.length > 0 ? datasets.join(', ') : null;
|
||||
};
|
||||
|
||||
const buildProtectionDetailSections = (point: RecoveryPoint): ProtectionDetailSection[] => {
|
||||
const buildProtectionDetailSections = (
|
||||
point: RecoveryPoint,
|
||||
staleNotice?: TrueNASProtectionStaleNotice | null,
|
||||
): ProtectionDetailSection[] => {
|
||||
const kind = mapTrueNASProtectionKind(point);
|
||||
const outcome = normalizeRecoveryOutcome(point.outcome);
|
||||
const outcomeLabel = getRecoveryOutcomeLabel(outcome);
|
||||
const target = targetLabel(point);
|
||||
const targetSecondary = targetSecondaryLabel(point);
|
||||
const summaryRows = compactDetailRows([
|
||||
detailRow('Kind', kindLabel(kind)),
|
||||
detailRow('Outcome', getRecoveryOutcomeLabel(normalizeRecoveryOutcome(point.outcome)), {
|
||||
tone: outcomeTone(point),
|
||||
}),
|
||||
...(staleNotice
|
||||
? [
|
||||
detailRow('Status', staleNotice.badge, { tone: 'warning' }),
|
||||
detailRow('Last reported', outcomeLabel, { tone: outcomeTone(point) }),
|
||||
]
|
||||
: [detailRow('Outcome', outcomeLabel, { tone: outcomeTone(point) })]),
|
||||
detailRow('Dataset', datasetLabel(point)),
|
||||
detailRow('Host', hostLabel(point)),
|
||||
detailRow('Started', detailDateTime(point.startedAt)),
|
||||
@@ -305,6 +333,7 @@ const buildProtectionDetailSections = (point: RecoveryPoint): ProtectionDetailSe
|
||||
|
||||
export const TrueNASProtectionTable: Component<{
|
||||
points: RecoveryPoint[];
|
||||
systems?: Resource[];
|
||||
loading?: boolean;
|
||||
error?: unknown;
|
||||
onRefresh?: () => void;
|
||||
@@ -316,29 +345,43 @@ export const TrueNASProtectionTable: Component<{
|
||||
search?: () => string;
|
||||
onSearchChange?: (value: string) => void;
|
||||
}> = (props) => {
|
||||
const rows = createMemo(() => sortTrueNASProtectionPoints(props.points));
|
||||
const posture = createMemo(() => buildTrueNASProtectionPosture(rows()));
|
||||
const staleNoticeByPointId = createMemo(() =>
|
||||
buildTrueNASProtectionStaleNoticeMap(props.points, props.systems ?? []),
|
||||
);
|
||||
const rows = createMemo(() => sortTrueNASProtectionPoints(props.points, staleNoticeByPointId()));
|
||||
const posture = createMemo(() => buildTrueNASProtectionPosture(rows(), staleNoticeByPointId()));
|
||||
const detail = createTrueNASDetailState('truenas-protection-detail');
|
||||
const tableState = createPlatformTableFilterState({
|
||||
resources: rows,
|
||||
initialStatus: 'all' as TrueNASProtectionStatusFilter,
|
||||
filter: filterTrueNASProtectionPoints,
|
||||
filter: (items, search, status) =>
|
||||
filterTrueNASProtectionPoints(items, search, status, staleNoticeByPointId()),
|
||||
externalSearch: props.search,
|
||||
onExternalSearchChange: props.onSearchChange,
|
||||
});
|
||||
const statusOptions = createMemo(() =>
|
||||
withPlatformStatusCounts(TRUENAS_PROTECTION_STATUS_OPTIONS, tableState.countForStatus, {
|
||||
const statusOptions = createMemo(() => {
|
||||
const showStaleFilter = posture().stale > 0 || tableState.status() === 'stale';
|
||||
const baseOptions = showStaleFilter
|
||||
? [
|
||||
...TRUENAS_PROTECTION_STATUS_OPTIONS.slice(0, 2),
|
||||
TRUENAS_PROTECTION_STALE_OPTION,
|
||||
...TRUENAS_PROTECTION_STATUS_OPTIONS.slice(2),
|
||||
]
|
||||
: TRUENAS_PROTECTION_STATUS_OPTIONS;
|
||||
return withPlatformStatusCounts(baseOptions, tableState.countForStatus, {
|
||||
value: 'attention',
|
||||
tone: posture().failed > 0 ? 'danger' : 'warning',
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
const sort = createPlatformTableSortState({
|
||||
storageKey: 'truenasProtection',
|
||||
sortKeys: TRUENAS_PROTECTION_SORT_KEYS,
|
||||
descendingFirst: ['completed', 'size'],
|
||||
});
|
||||
const sortedRows = createMemo(() =>
|
||||
sort.sortRows(tableState.filtered(), getTrueNASProtectionSortValue),
|
||||
sort.sortRows(tableState.filtered(), (point, key) =>
|
||||
getTrueNASProtectionSortValue(point, key, staleNoticeByPointId().get(point.id)),
|
||||
),
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -459,6 +502,40 @@ export const TrueNASProtectionTable: Component<{
|
||||
<PlatformWindowedRows items={sortedRows} estimatedRowHeight={32}>
|
||||
{(point) => {
|
||||
const outcome = () => normalizeRecoveryOutcome(point.outcome);
|
||||
const statusBucket = () => mapTrueNASProtectionStatus(point);
|
||||
const staleNotice = () => staleNoticeByPointId().get(point.id) ?? null;
|
||||
const isStaleHealthy = () => Boolean(staleNotice()) && outcome() === 'success';
|
||||
const rowVariant = (): StatusIndicatorVariant => {
|
||||
const stale = staleNotice();
|
||||
if (!stale) return protectionVariant(statusBucket());
|
||||
return outcome() === 'failed' ? 'danger' : 'warning';
|
||||
};
|
||||
const rowDotTitle = () => {
|
||||
const stale = staleNotice();
|
||||
const outcomeLabel = getRecoveryOutcomeLabel(outcome());
|
||||
if (!stale) return outcomeLabel;
|
||||
return isStaleHealthy()
|
||||
? `${stale.badge} · Last reported ${outcomeLabel} · ${stale.detail}`
|
||||
: `${outcomeLabel} · ${stale.badge} · ${stale.detail}`;
|
||||
};
|
||||
const effectiveOutcome = () => {
|
||||
const stale = staleNotice();
|
||||
if (!stale) return outcome();
|
||||
if (outcome() === 'success') return 'warning';
|
||||
if (outcome() === 'running') return 'unknown';
|
||||
return outcome();
|
||||
};
|
||||
const detailStatus = () => {
|
||||
const stale = staleNotice();
|
||||
const outcomeLabel = getRecoveryOutcomeLabel(outcome());
|
||||
if (!stale) {
|
||||
return { variant: protectionVariant(statusBucket()), label: outcomeLabel };
|
||||
}
|
||||
return {
|
||||
variant: rowVariant(),
|
||||
label: isStaleHealthy() ? stale.badge : `${outcomeLabel} · ${stale.badge}`,
|
||||
};
|
||||
};
|
||||
const artifact = () => artifactLabel(point);
|
||||
const artifactSecondary = () => artifactSecondaryLabel(point);
|
||||
const target = () => targetLabel(point);
|
||||
@@ -471,7 +548,8 @@ export const TrueNASProtectionTable: Component<{
|
||||
class={`${getPlatformResourceDetailRowClass(isExpanded())} text-[11px] sm:text-xs`}
|
||||
data-truenas-protection-row={point.id}
|
||||
data-truenas-protection-kind={mapTrueNASProtectionKind(point)}
|
||||
data-truenas-protection-outcome={mapTrueNASProtectionStatus(point)}
|
||||
data-truenas-protection-outcome={statusBucket()}
|
||||
data-truenas-protection-stale={staleNotice() ? 'true' : undefined}
|
||||
onClick={() => detail.toggle(point)}
|
||||
>
|
||||
<TableCell class={getPlatformTableCellClassForKind('name')}>
|
||||
@@ -479,9 +557,9 @@ export const TrueNASProtectionTable: Component<{
|
||||
item={point}
|
||||
drawer={detail}
|
||||
label={datasetLabel(point)}
|
||||
variant={protectionVariant(mapTrueNASProtectionStatus(point))}
|
||||
pulse={mapTrueNASProtectionStatus(point) === 'running'}
|
||||
dotTitle={getRecoveryOutcomeLabel(outcome())}
|
||||
variant={rowVariant()}
|
||||
pulse={!staleNotice() && statusBucket() === 'running'}
|
||||
dotTitle={rowDotTitle()}
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<div
|
||||
@@ -495,6 +573,10 @@ export const TrueNASProtectionTable: Component<{
|
||||
>
|
||||
{datasetLabel(point)}
|
||||
</div>
|
||||
<TrueNASStaleBadge
|
||||
notice={isStaleHealthy() ? null : staleNotice()}
|
||||
attr="protection"
|
||||
/>
|
||||
</div>
|
||||
</TrueNASRowLead>
|
||||
</TableCell>
|
||||
@@ -532,8 +614,19 @@ export const TrueNASProtectionTable: Component<{
|
||||
{sizeLabel(point)}
|
||||
</TableCell>
|
||||
<TableCell class={getPlatformTableCellClassForKind('badge')}>
|
||||
<span class={getRecoveryOutcomeBadgeClass(outcome())}>
|
||||
{getRecoveryOutcomeLabel(outcome())}
|
||||
<span
|
||||
class={getRecoveryOutcomeBadgeClass(effectiveOutcome())}
|
||||
title={staleNotice() ? rowDotTitle() : undefined}
|
||||
data-truenas-protection-stale-badge={
|
||||
isStaleHealthy() ? 'true' : undefined
|
||||
}
|
||||
>
|
||||
<Show
|
||||
when={isStaleHealthy()}
|
||||
fallback={getRecoveryOutcomeLabel(outcome())}
|
||||
>
|
||||
<PlatformResponsiveTableLabel compact="Stale" full="Stale data" />
|
||||
</Show>
|
||||
</span>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -548,10 +641,7 @@ export const TrueNASProtectionTable: Component<{
|
||||
testId="truenas-protection-detail"
|
||||
detailFor={point.id}
|
||||
title={datasetLabel(point)}
|
||||
status={{
|
||||
variant: protectionVariant(mapTrueNASProtectionStatus(point)),
|
||||
label: getRecoveryOutcomeLabel(outcome()),
|
||||
}}
|
||||
status={detailStatus()}
|
||||
summary={`${kindLabel(mapTrueNASProtectionKind(point))} on ${hostLabel(point)}`}
|
||||
actions={
|
||||
<RecordOwnerLink
|
||||
@@ -562,10 +652,29 @@ export const TrueNASProtectionTable: Component<{
|
||||
}}
|
||||
/>
|
||||
}
|
||||
sections={buildProtectionDetailSections(point)}
|
||||
sections={buildProtectionDetailSections(point, staleNotice())}
|
||||
detailAttributes={{ 'data-truenas-protection-detail-for': point.id }}
|
||||
onClose={() => detail.close(point)}
|
||||
/>
|
||||
>
|
||||
<Show when={staleNotice()}>
|
||||
{(notice) => (
|
||||
<InlineNotice
|
||||
role="status"
|
||||
tone="warning"
|
||||
data-testid="truenas-protection-stale-notice"
|
||||
aria-label="TrueNAS protection readings may be stale"
|
||||
>
|
||||
<p class="font-medium">
|
||||
Readings from {notice().systemName} may be out of date.
|
||||
</p>
|
||||
<p>
|
||||
{notice().detail}. Showing the last reported protection event.
|
||||
Newer snapshots, replication runs, or failures may be missing.
|
||||
</p>
|
||||
</InlineNotice>
|
||||
)}
|
||||
</Show>
|
||||
</InlineDetailPanel>
|
||||
</InlineDetailTableRow>
|
||||
</Show>
|
||||
</>
|
||||
|
||||
@@ -109,7 +109,7 @@ export type TrueNASCommonTableProps = {
|
||||
|
||||
export function TrueNASStaleBadge(props: {
|
||||
notice: TrueNASStaleNotice | null;
|
||||
attr: 'system' | 'storage';
|
||||
attr: 'system' | 'storage' | 'protection';
|
||||
}) {
|
||||
return (
|
||||
<Show when={props.notice}>
|
||||
@@ -119,6 +119,7 @@ export function TrueNASStaleBadge(props: {
|
||||
title={notice().detail}
|
||||
data-truenas-system-stale={props.attr === 'system' ? 'true' : undefined}
|
||||
data-truenas-storage-stale={props.attr === 'storage' ? 'true' : undefined}
|
||||
data-truenas-protection-stale-cue={props.attr === 'protection' ? 'true' : undefined}
|
||||
>
|
||||
{notice().badge}
|
||||
</span>
|
||||
|
||||
@@ -90,8 +90,12 @@ vi.mock('../TrueNASNetworkSharesTable', () => ({
|
||||
}));
|
||||
|
||||
vi.mock('../TrueNASProtectionTable', () => ({
|
||||
TrueNASProtectionTable: (props: { points: unknown[] }) => (
|
||||
<div data-testid="protection-table" data-rows={props.points.length} />
|
||||
TrueNASProtectionTable: (props: { points: unknown[]; systems?: Resource[] }) => (
|
||||
<div
|
||||
data-testid="protection-table"
|
||||
data-rows={props.points.length}
|
||||
data-systems={props.systems?.length ?? 0}
|
||||
/>
|
||||
),
|
||||
}));
|
||||
|
||||
@@ -210,6 +214,7 @@ describe('TrueNASPageSurface contract', () => {
|
||||
'protection',
|
||||
);
|
||||
expect(screen.getByTestId('protection-table')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('protection-table')).toHaveAttribute('data-systems', '1');
|
||||
});
|
||||
|
||||
it('hydrates only the active TrueNAS workflow resource family', () => {
|
||||
|
||||
@@ -0,0 +1,449 @@
|
||||
import { cleanup, fireEvent, render, screen, within } from '@solidjs/testing-library';
|
||||
import { Route, Router } from '@solidjs/router';
|
||||
import { createSignal, type JSX } from 'solid-js';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import { TrueNASProtectionTable } from '@/features/truenas/TrueNASProtectionTable';
|
||||
import {
|
||||
buildTrueNASProtectionPosture,
|
||||
buildTrueNASProtectionStaleNoticeMap,
|
||||
filterTrueNASProtectionPoints,
|
||||
getTrueNASProtectionStaleNotice,
|
||||
sortTrueNASProtectionPoints,
|
||||
} from '@/features/truenas/truenasPageModel';
|
||||
import type { RecoveryPoint } from '@/types/recovery';
|
||||
import type { Resource } from '@/types/resource';
|
||||
|
||||
const renderInRouter = (component: () => JSX.Element) =>
|
||||
render(() => (
|
||||
<Router>
|
||||
<Route path="/*" component={component} />
|
||||
</Router>
|
||||
));
|
||||
|
||||
const makeSystem = (overrides: Partial<Resource> & Pick<Resource, 'id'>): Resource =>
|
||||
({
|
||||
type: 'agent',
|
||||
name: overrides.id,
|
||||
displayName: overrides.name ?? overrides.id,
|
||||
status: 'online',
|
||||
platformId: 'truenas-primary',
|
||||
platformType: 'truenas',
|
||||
platformScopes: ['truenas'],
|
||||
sourceType: 'agent',
|
||||
sources: ['agent', 'truenas'],
|
||||
lastSeen: 1_700_000_000_000,
|
||||
...overrides,
|
||||
}) as Resource;
|
||||
|
||||
const makePoint = (
|
||||
point: Partial<RecoveryPoint> & Pick<RecoveryPoint, 'id' | 'kind' | 'mode'>,
|
||||
): RecoveryPoint => ({
|
||||
outcome: 'success',
|
||||
platform: 'truenas',
|
||||
startedAt: '2026-11-27T12:00:00Z',
|
||||
completedAt: '2026-11-27T12:05:00Z',
|
||||
...point,
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
describe('TrueNAS protection freshness model', () => {
|
||||
it('isolates DR clones sharing a hostname by connectionId', () => {
|
||||
const stalePrimary = makeSystem({
|
||||
id: 'truenas:agent:system:conn-primary',
|
||||
name: 'truenas',
|
||||
displayName: 'truenas-primary',
|
||||
platformId: 'conn-primary',
|
||||
agent: { agentId: 'conn-primary', hostname: 'truenas' },
|
||||
truenas: { hostname: 'truenas' },
|
||||
sourceStatus: {
|
||||
truenas: { status: 'error', error: 'websocket read timeout' },
|
||||
},
|
||||
health: {
|
||||
verdict: 'stale',
|
||||
reasons: [{ code: 'telemetry_stale', detail: '18m' }],
|
||||
},
|
||||
});
|
||||
const healthyDr = makeSystem({
|
||||
id: 'truenas:agent:system:conn-dr',
|
||||
name: 'truenas',
|
||||
displayName: 'truenas-dr',
|
||||
platformId: 'conn-dr',
|
||||
agent: { agentId: 'conn-dr', hostname: 'truenas' },
|
||||
truenas: { hostname: 'truenas' },
|
||||
sourceStatus: {
|
||||
truenas: { status: 'online' },
|
||||
},
|
||||
});
|
||||
|
||||
const primarySnap = makePoint({
|
||||
id: 'snap-primary',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
details: { connectionId: 'conn-primary', hostname: 'truenas', dataset: 'tank/apps' },
|
||||
});
|
||||
const drSnap = makePoint({
|
||||
id: 'snap-dr',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
details: { connectionId: 'conn-dr', hostname: 'truenas', dataset: 'vault/apps' },
|
||||
});
|
||||
const unknownConnSnap = makePoint({
|
||||
id: 'snap-unknown',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
details: { connectionId: 'conn-other', hostname: 'truenas', dataset: 'other/apps' },
|
||||
});
|
||||
|
||||
const primaryNotice = getTrueNASProtectionStaleNotice(primarySnap, [stalePrimary, healthyDr]);
|
||||
expect(primaryNotice).toEqual(
|
||||
expect.objectContaining({
|
||||
badge: 'Stale data',
|
||||
systemName: 'truenas-primary',
|
||||
age: '18m',
|
||||
detail: 'TrueNAS collection error: websocket read timeout (last report 18m ago)',
|
||||
}),
|
||||
);
|
||||
expect(getTrueNASProtectionStaleNotice(drSnap, [stalePrimary, healthyDr])).toBeNull();
|
||||
expect(getTrueNASProtectionStaleNotice(unknownConnSnap, [stalePrimary, healthyDr])).toBeNull();
|
||||
});
|
||||
|
||||
it('does not treat a live degraded ZFS pool as stale when TrueNAS polling is healthy', () => {
|
||||
const degradedLiveSystem = makeSystem({
|
||||
id: 'truenas:agent:system:conn-live',
|
||||
name: 'nas-live',
|
||||
status: 'degraded',
|
||||
agent: { agentId: 'conn-live', hostname: 'nas-live' },
|
||||
truenas: { hostname: 'nas-live' },
|
||||
sourceStatus: { truenas: { status: 'online' } },
|
||||
});
|
||||
const snap = makePoint({
|
||||
id: 'snap-live',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
details: { connectionId: 'conn-live', hostname: 'nas-live', dataset: 'tank/media' },
|
||||
});
|
||||
|
||||
expect(getTrueNASProtectionStaleNotice(snap, [degradedLiveSystem])).toBeNull();
|
||||
});
|
||||
|
||||
it('detects backend telemetry_stale and offline systems even when sourceStatus is absent', () => {
|
||||
const telemetryStale = makeSystem({
|
||||
id: 'agent:nas-telemetry',
|
||||
name: 'nas-telemetry',
|
||||
truenas: { hostname: 'nas-telemetry' },
|
||||
health: {
|
||||
verdict: 'stale',
|
||||
reasons: [{ code: 'telemetry_stale', detail: '24m' }],
|
||||
},
|
||||
});
|
||||
const offlineSystem = makeSystem({
|
||||
id: 'agent:nas-offline',
|
||||
name: 'nas-offline',
|
||||
status: 'offline',
|
||||
truenas: { hostname: 'nas-offline' },
|
||||
});
|
||||
|
||||
const telemetryPoint = makePoint({
|
||||
id: 'pt-telemetry',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
display: { nodeHostLabel: 'nas-telemetry', itemLabel: 'tank/db' },
|
||||
});
|
||||
const offlinePoint = makePoint({
|
||||
id: 'pt-offline',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
details: { hostname: 'nas-offline', dataset: 'tank/backups' },
|
||||
});
|
||||
|
||||
expect(
|
||||
getTrueNASProtectionStaleNotice(telemetryPoint, [telemetryStale, offlineSystem]),
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
badge: 'Stale data',
|
||||
systemName: 'nas-telemetry',
|
||||
age: '24m',
|
||||
detail: 'No TrueNAS report from nas-telemetry for 24m',
|
||||
}),
|
||||
);
|
||||
expect(getTrueNASProtectionStaleNotice(offlinePoint, [telemetryStale, offlineSystem])).toEqual(
|
||||
expect.objectContaining({
|
||||
badge: 'Stale data',
|
||||
systemName: 'nas-offline',
|
||||
detail: 'TrueNAS system nas-offline is offline in Pulse',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('excludes stale success/running from Healthy/Running and ranks stale first', () => {
|
||||
const staleNas = makeSystem({
|
||||
id: 'truenas:agent:system:conn-stale',
|
||||
name: 'nas-east',
|
||||
agent: { agentId: 'conn-stale', hostname: 'nas-east' },
|
||||
truenas: { hostname: 'nas-east' },
|
||||
sourceStatus: { truenas: { status: 'error', error: 'dial tcp timeout' } },
|
||||
});
|
||||
const freshNas = makeSystem({
|
||||
id: 'truenas:agent:system:conn-fresh',
|
||||
name: 'nas-west',
|
||||
agent: { agentId: 'conn-fresh', hostname: 'nas-west' },
|
||||
truenas: { hostname: 'nas-west' },
|
||||
sourceStatus: { truenas: { status: 'online' } },
|
||||
});
|
||||
|
||||
const freshOk = makePoint({
|
||||
id: 'fresh-ok',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
completedAt: '2026-11-27T13:00:00Z',
|
||||
details: { connectionId: 'conn-fresh', hostname: 'nas-west', dataset: 'west/ok' },
|
||||
});
|
||||
const staleOk = makePoint({
|
||||
id: 'stale-ok',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
completedAt: '2026-11-27T11:00:00Z',
|
||||
details: { connectionId: 'conn-stale', hostname: 'nas-east', dataset: 'east/ok' },
|
||||
});
|
||||
const staleRunning = makePoint({
|
||||
id: 'stale-running',
|
||||
kind: 'backup',
|
||||
mode: 'remote',
|
||||
outcome: 'running',
|
||||
startedAt: '2026-11-27T10:30:00Z',
|
||||
completedAt: undefined,
|
||||
details: { connectionId: 'conn-stale', hostname: 'nas-east', taskName: 'rep-east' },
|
||||
});
|
||||
const staleFailed = makePoint({
|
||||
id: 'stale-failed',
|
||||
kind: 'backup',
|
||||
mode: 'remote',
|
||||
outcome: 'failed',
|
||||
completedAt: '2026-11-27T10:00:00Z',
|
||||
details: { connectionId: 'conn-stale', hostname: 'nas-east', taskName: 'rep-fail' },
|
||||
});
|
||||
|
||||
const points = [freshOk, staleOk, staleRunning, staleFailed];
|
||||
const staleMap = buildTrueNASProtectionStaleNoticeMap(points, [staleNas, freshNas]);
|
||||
const posture = buildTrueNASProtectionPosture(points, staleMap);
|
||||
|
||||
expect(posture).toEqual({
|
||||
healthy: 1,
|
||||
stale: 3,
|
||||
warning: 0,
|
||||
failed: 1,
|
||||
running: 0,
|
||||
unknown: 0,
|
||||
attention: 3,
|
||||
});
|
||||
|
||||
const sorted = sortTrueNASProtectionPoints(points, staleMap);
|
||||
expect(sorted.map((p) => p.id)).toEqual([
|
||||
'stale-failed',
|
||||
'stale-ok',
|
||||
'stale-running',
|
||||
'fresh-ok',
|
||||
]);
|
||||
|
||||
expect(filterTrueNASProtectionPoints(points, '', 'success', staleMap).map((p) => p.id)).toEqual(
|
||||
['fresh-ok'],
|
||||
);
|
||||
expect(filterTrueNASProtectionPoints(points, '', 'running', staleMap)).toEqual([]);
|
||||
expect(filterTrueNASProtectionPoints(points, '', 'stale', staleMap).map((p) => p.id)).toEqual([
|
||||
'stale-ok',
|
||||
'stale-running',
|
||||
'stale-failed',
|
||||
]);
|
||||
expect(
|
||||
filterTrueNASProtectionPoints(points, '', 'attention', staleMap).map((p) => p.id),
|
||||
).toEqual(['stale-ok', 'stale-running', 'stale-failed']);
|
||||
expect(filterTrueNASProtectionPoints(points, '', 'failed', staleMap).map((p) => p.id)).toEqual([
|
||||
'stale-failed',
|
||||
]);
|
||||
expect(
|
||||
filterTrueNASProtectionPoints(points, 'dial tcp timeout', 'all', staleMap).map((p) => p.id),
|
||||
).toEqual(['stale-ok', 'stale-running', 'stale-failed']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('TrueNASProtectionTable stale-reading UI', () => {
|
||||
it('surfaces stale events truthfully and clears them on live recovery', async () => {
|
||||
const staleNas = makeSystem({
|
||||
id: 'truenas:agent:system:conn-east',
|
||||
name: 'nas-east',
|
||||
displayName: 'nas-east',
|
||||
agent: { agentId: 'conn-east', hostname: 'nas-east' },
|
||||
truenas: { hostname: 'nas-east' },
|
||||
sourceStatus: { truenas: { status: 'error', error: 'API connection refused' } },
|
||||
health: {
|
||||
verdict: 'stale',
|
||||
reasons: [{ code: 'telemetry_stale', detail: '14m' }],
|
||||
},
|
||||
});
|
||||
const freshNas = makeSystem({
|
||||
id: 'truenas:agent:system:conn-west',
|
||||
name: 'nas-west',
|
||||
displayName: 'nas-west',
|
||||
agent: { agentId: 'conn-west', hostname: 'nas-west' },
|
||||
truenas: { hostname: 'nas-west' },
|
||||
sourceStatus: { truenas: { status: 'online' } },
|
||||
});
|
||||
|
||||
const points: RecoveryPoint[] = [
|
||||
makePoint({
|
||||
id: 'snap-east-ok',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
outcome: 'success',
|
||||
display: { itemLabel: 'tank/billing', nodeHostLabel: 'nas-east' },
|
||||
details: {
|
||||
connectionId: 'conn-east',
|
||||
hostname: 'nas-east',
|
||||
dataset: 'tank/billing',
|
||||
snapshot: 'auto-20261127-1200',
|
||||
},
|
||||
}),
|
||||
makePoint({
|
||||
id: 'rep-east-running',
|
||||
kind: 'backup',
|
||||
mode: 'remote',
|
||||
outcome: 'running',
|
||||
completedAt: undefined,
|
||||
display: { itemLabel: 'tank/media', nodeHostLabel: 'nas-east' },
|
||||
details: {
|
||||
connectionId: 'conn-east',
|
||||
hostname: 'nas-east',
|
||||
taskName: 'replicate-media',
|
||||
lastState: 'RUNNING',
|
||||
},
|
||||
}),
|
||||
makePoint({
|
||||
id: 'rep-east-failed',
|
||||
kind: 'backup',
|
||||
mode: 'remote',
|
||||
outcome: 'failed',
|
||||
display: { itemLabel: 'tank/archive', nodeHostLabel: 'nas-east' },
|
||||
details: {
|
||||
connectionId: 'conn-east',
|
||||
hostname: 'nas-east',
|
||||
taskName: 'replicate-archive',
|
||||
lastState: 'FAILED',
|
||||
},
|
||||
}),
|
||||
makePoint({
|
||||
id: 'snap-west-ok',
|
||||
kind: 'snapshot',
|
||||
mode: 'snapshot',
|
||||
outcome: 'success',
|
||||
display: { itemLabel: 'vault/docs', nodeHostLabel: 'nas-west' },
|
||||
details: {
|
||||
connectionId: 'conn-west',
|
||||
hostname: 'nas-west',
|
||||
dataset: 'vault/docs',
|
||||
snapshot: 'auto-20261127-1205',
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
const [systems, setSystems] = createSignal<Resource[]>([staleNas, freshNas]);
|
||||
|
||||
renderInRouter(() => (
|
||||
<TrueNASProtectionTable
|
||||
points={points}
|
||||
systems={systems()}
|
||||
emptyIcon={<span />}
|
||||
emptyTitle="No protection"
|
||||
emptyDescription="No protection"
|
||||
/>
|
||||
));
|
||||
|
||||
// Filter chips: 1 fresh Healthy, 3 Stale, 3 Attention, 1 Failed, 0 Running
|
||||
expect(screen.getByRole('button', { name: 'All, 4' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Attention, 3' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Stale, 3' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Healthy, 1' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Failed, 1' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Running, 0' })).toBeInTheDocument();
|
||||
|
||||
// Stale healthy row shows amber Stale data badge in Outcome and no redundant cue under Dataset
|
||||
const staleOkRow = document.querySelector('[data-truenas-protection-row="snap-east-ok"]')!;
|
||||
expect(staleOkRow).toHaveAttribute('data-truenas-protection-stale', 'true');
|
||||
expect(
|
||||
staleOkRow.querySelector('[data-truenas-protection-stale-badge="true"]'),
|
||||
).toHaveTextContent('Stale data');
|
||||
expect(staleOkRow.querySelector('[data-truenas-protection-stale-cue="true"]')).toBeNull();
|
||||
|
||||
// Stale failed row preserves red Failed badge AND shows amber Stale data cue under Dataset
|
||||
const staleFailedRow = document.querySelector(
|
||||
'[data-truenas-protection-row="rep-east-failed"]',
|
||||
)!;
|
||||
expect(staleFailedRow).toHaveAttribute('data-truenas-protection-stale', 'true');
|
||||
expect(
|
||||
staleFailedRow.querySelector('[data-truenas-protection-stale-cue="true"]'),
|
||||
).toHaveTextContent('Stale data');
|
||||
expect(staleFailedRow.querySelectorAll('td')[5]).toHaveTextContent('Failed');
|
||||
|
||||
// Stale running row preserves Running text without pulsing dot and shows amber Stale data cue
|
||||
const staleRunningRow = document.querySelector(
|
||||
'[data-truenas-protection-row="rep-east-running"]',
|
||||
)!;
|
||||
expect(staleRunningRow).toHaveAttribute('data-truenas-protection-stale', 'true');
|
||||
expect(
|
||||
staleRunningRow.querySelector('[data-truenas-protection-stale-cue="true"]'),
|
||||
).toHaveTextContent('Stale data');
|
||||
expect(staleRunningRow.querySelector('.animate-pulse')).toBeNull();
|
||||
|
||||
// Fresh row stays Healthy without stale cues
|
||||
const freshRow = document.querySelector('[data-truenas-protection-row="snap-west-ok"]')!;
|
||||
expect(freshRow).not.toHaveAttribute('data-truenas-protection-stale');
|
||||
expect(freshRow.querySelectorAll('td')[5]).toHaveTextContent('Healthy');
|
||||
|
||||
// Open stale healthy detail drawer: shows amber InlineNotice, Status: Stale data, Last reported: Healthy
|
||||
await fireEvent.click(staleOkRow);
|
||||
const detail = within(screen.getByTestId('truenas-protection-detail'));
|
||||
const staleNotice = detail.getByTestId('truenas-protection-stale-notice');
|
||||
expect(staleNotice).toHaveTextContent('Readings from nas-east may be out of date.');
|
||||
expect(staleNotice).toHaveTextContent(
|
||||
'TrueNAS collection error: API connection refused (last report 14m ago)',
|
||||
);
|
||||
expect(detail.getByText('Status', { exact: true }).closest('tr')).toHaveTextContent(
|
||||
'Stale data',
|
||||
);
|
||||
expect(detail.getByText('Last reported', { exact: true }).closest('tr')).toHaveTextContent(
|
||||
'Healthy',
|
||||
);
|
||||
|
||||
// Filter to Stale then recover live over WebSocket: Stale chip stays visible at 0 while active
|
||||
await fireEvent.click(screen.getByRole('button', { name: 'Stale, 3' }));
|
||||
expect(document.querySelectorAll('[data-truenas-protection-row]')).toHaveLength(3);
|
||||
|
||||
setSystems([
|
||||
makeSystem({
|
||||
...staleNas,
|
||||
sourceStatus: { truenas: { status: 'online' } },
|
||||
health: { verdict: 'ok', reasons: [] },
|
||||
}),
|
||||
freshNas,
|
||||
]);
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Stale, 0' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Healthy, 2' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Running, 1' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Attention, 1' })).toBeInTheDocument();
|
||||
|
||||
// Switching back to All removes the Stale chip and clears the open drawer stale banner
|
||||
await fireEvent.click(screen.getByRole('button', { name: 'All, 4' }));
|
||||
expect(screen.queryByRole('button', { name: /^Stale,/ })).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('truenas-protection-stale-notice')).not.toBeInTheDocument();
|
||||
expect(
|
||||
within(screen.getByTestId('truenas-protection-detail'))
|
||||
.getByText('Outcome', { exact: true })
|
||||
.closest('tr'),
|
||||
).toHaveTextContent('Healthy');
|
||||
});
|
||||
});
|
||||
@@ -274,6 +274,7 @@ describe('truenasPageModel coverage', () => {
|
||||
]);
|
||||
expect(posture).toEqual({
|
||||
healthy: 1,
|
||||
stale: 0,
|
||||
warning: 0,
|
||||
failed: 1,
|
||||
running: 0,
|
||||
@@ -285,6 +286,7 @@ describe('truenasPageModel coverage', () => {
|
||||
it('returns a fully zeroed posture for an empty recovery-point array', () => {
|
||||
expect(buildTrueNASProtectionPosture([])).toEqual({
|
||||
healthy: 0,
|
||||
stale: 0,
|
||||
warning: 0,
|
||||
failed: 0,
|
||||
running: 0,
|
||||
|
||||
@@ -1275,6 +1275,7 @@ describe('truenasPageModel', () => {
|
||||
expect(mapTrueNASProtectionStatus(legacyReplication)).toBe('warning');
|
||||
expect(buildTrueNASProtectionPosture([snapshot, replication, legacyReplication])).toEqual({
|
||||
healthy: 1,
|
||||
stale: 0,
|
||||
warning: 1,
|
||||
failed: 0,
|
||||
running: 1,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { resolveResourcePlatformType } from '@/utils/sourcePlatforms';
|
||||
import { asTrimmedString } from '@/utils/stringUtils';
|
||||
import { parseBackupTimestampMs } from '@/utils/backupTimestamp';
|
||||
import { getResourceStaleness } from '@/features/platformPage/resourceStaleness';
|
||||
import {
|
||||
getTrueNASDatasetStateSummary,
|
||||
getTrueNASStaleNotice,
|
||||
@@ -32,10 +33,10 @@ export type TrueNASIncidentSeverityFilter = 'all' | 'critical' | 'warning' | 'in
|
||||
export type TrueNASStorageStatusFilter = 'all' | 'healthy' | 'attention' | 'offline';
|
||||
export type TrueNASStorageKindFilter = 'all' | 'volumes' | 'disks';
|
||||
export type TrueNASProtectionStatusFilter =
|
||||
'all' | 'attention' | 'success' | 'warning' | 'failed' | 'running' | 'unknown';
|
||||
'all' | 'attention' | 'stale' | 'success' | 'warning' | 'failed' | 'running' | 'unknown';
|
||||
export type TrueNASProtectionStatusBucket = Exclude<
|
||||
TrueNASProtectionStatusFilter,
|
||||
'all' | 'attention'
|
||||
'all' | 'attention' | 'stale'
|
||||
>;
|
||||
export type TrueNASProtectionKind = 'snapshot' | 'replication' | 'other';
|
||||
|
||||
@@ -900,12 +901,195 @@ export function getTrueNASStorageIssue(
|
||||
return { status, label: TRUENAS_STORAGE_ISSUE_LABELS[status], reasons };
|
||||
}
|
||||
|
||||
export type TrueNASProtectionStaleNotice = TrueNASStaleNotice & {
|
||||
systemName: string;
|
||||
age?: string;
|
||||
};
|
||||
|
||||
const addConnectionTokens = (target: Set<string>, value: unknown) => {
|
||||
const normalized = normalize(value);
|
||||
if (!normalized) return;
|
||||
target.add(normalized);
|
||||
const systemIndex = normalized.lastIndexOf('system:');
|
||||
if (systemIndex >= 0) {
|
||||
const suffix = normalized.slice(systemIndex + 'system:'.length).trim();
|
||||
if (suffix) target.add(suffix);
|
||||
}
|
||||
if (normalized.startsWith('agent:')) {
|
||||
const suffix = normalized.slice('agent:'.length).trim();
|
||||
if (suffix) target.add(suffix);
|
||||
}
|
||||
};
|
||||
|
||||
const buildTrueNASSystemStaleNotice = (system: Resource): TrueNASProtectionStaleNotice | null => {
|
||||
const systemName =
|
||||
asTrimmedString(system.displayName) ||
|
||||
asTrimmedString(system.name) ||
|
||||
asTrimmedString(system.truenas?.hostname) ||
|
||||
system.id;
|
||||
const baseNotice = getTrueNASStaleNotice(system);
|
||||
const staleness = getResourceStaleness(system);
|
||||
const age = staleness?.age ?? undefined;
|
||||
const ageSuffix = age ? ` (last report ${age} ago)` : '';
|
||||
if (baseNotice) {
|
||||
const detail =
|
||||
age && !baseNotice.detail.includes(age)
|
||||
? `${baseNotice.detail}${ageSuffix}`
|
||||
: baseNotice.detail;
|
||||
return {
|
||||
...baseNotice,
|
||||
detail,
|
||||
systemName,
|
||||
...(age ? { age } : {}),
|
||||
};
|
||||
}
|
||||
if (staleness) {
|
||||
return {
|
||||
badge: 'Stale data',
|
||||
detail: age
|
||||
? `No TrueNAS report from ${systemName} for ${age}`
|
||||
: `TrueNAS has not updated ${systemName} recently`,
|
||||
systemName,
|
||||
...(age ? { age } : {}),
|
||||
};
|
||||
}
|
||||
if (!system.sourceStatus?.truenas && normalize(system.status) === 'offline') {
|
||||
return {
|
||||
badge: 'Stale data',
|
||||
detail: `TrueNAS system ${systemName} is offline in Pulse`,
|
||||
systemName,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
type IndexedTrueNASSystem = {
|
||||
notice: TrueNASProtectionStaleNotice | null;
|
||||
connectionIds: Set<string>;
|
||||
hasExplicitConnectionId: boolean;
|
||||
hostnames: Set<string>;
|
||||
};
|
||||
|
||||
const indexTrueNASSystemsForProtection = (systems: readonly Resource[]): IndexedTrueNASSystem[] =>
|
||||
systems.map((system) => {
|
||||
const connectionIds = new Set<string>();
|
||||
const explicitAgentId = normalize(system.agent?.agentId);
|
||||
const explicitMetricId = normalize(system.metricsTarget?.resourceId);
|
||||
addConnectionTokens(connectionIds, system.agent?.agentId);
|
||||
addConnectionTokens(connectionIds, system.metricsTarget?.resourceId);
|
||||
addConnectionTokens(connectionIds, system.platformId);
|
||||
addConnectionTokens(connectionIds, system.canonicalIdentity?.platformId);
|
||||
addConnectionTokens(connectionIds, system.id);
|
||||
for (const alias of system.canonicalIdentity?.aliases ?? []) {
|
||||
addConnectionTokens(connectionIds, alias);
|
||||
}
|
||||
const hostnames = new Set<string>();
|
||||
for (const value of [
|
||||
system.truenas?.hostname,
|
||||
system.agent?.hostname,
|
||||
system.canonicalIdentity?.hostname,
|
||||
system.name,
|
||||
system.displayName,
|
||||
]) {
|
||||
const normalized = normalize(value);
|
||||
if (normalized) hostnames.add(normalized);
|
||||
}
|
||||
return {
|
||||
notice: buildTrueNASSystemStaleNotice(system),
|
||||
connectionIds,
|
||||
hasExplicitConnectionId: Boolean(explicitAgentId || explicitMetricId),
|
||||
hostnames,
|
||||
};
|
||||
});
|
||||
|
||||
const resolveStaleNoticeFromCandidates = (
|
||||
candidates: readonly IndexedTrueNASSystem[],
|
||||
): TrueNASProtectionStaleNotice | null => {
|
||||
if (candidates.length === 0) return null;
|
||||
return candidates.every((entry) => entry.notice !== null) ? candidates[0].notice : null;
|
||||
};
|
||||
|
||||
const resolveProtectionStaleNotice = (
|
||||
point: RecoveryPoint,
|
||||
indexedSystems: readonly IndexedTrueNASSystem[],
|
||||
): TrueNASProtectionStaleNotice | null => {
|
||||
if (indexedSystems.length === 0) return null;
|
||||
|
||||
const pointConnIds = [
|
||||
normalize(point.details?.connectionId),
|
||||
(() => {
|
||||
const scope = normalize(point.providerScope);
|
||||
return scope && scope !== 'provider-default' ? scope : '';
|
||||
})(),
|
||||
].filter(Boolean);
|
||||
|
||||
const pointHostnames = [
|
||||
normalize(point.details?.hostname),
|
||||
normalize(point.display?.nodeHostLabel),
|
||||
normalize(point.display?.nodeAgentLabel),
|
||||
normalize(point.display?.clusterLabel),
|
||||
normalize(point.node),
|
||||
normalize(point.cluster),
|
||||
].filter(Boolean);
|
||||
|
||||
if (pointConnIds.length > 0) {
|
||||
const connMatches = indexedSystems.filter((entry) =>
|
||||
pointConnIds.some((id) => entry.connectionIds.has(id)),
|
||||
);
|
||||
if (connMatches.length > 0) {
|
||||
return resolveStaleNoticeFromCandidates(connMatches);
|
||||
}
|
||||
if (pointHostnames.length > 0) {
|
||||
const hostMatches = indexedSystems.filter(
|
||||
(entry) =>
|
||||
!entry.hasExplicitConnectionId &&
|
||||
pointHostnames.some((host) => entry.hostnames.has(host)),
|
||||
);
|
||||
return resolveStaleNoticeFromCandidates(hostMatches);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (pointHostnames.length > 0) {
|
||||
const hostMatches = indexedSystems.filter((entry) =>
|
||||
pointHostnames.some((host) => entry.hostnames.has(host)),
|
||||
);
|
||||
return resolveStaleNoticeFromCandidates(hostMatches);
|
||||
}
|
||||
|
||||
return resolveStaleNoticeFromCandidates(indexedSystems);
|
||||
};
|
||||
|
||||
export function getTrueNASProtectionStaleNotice(
|
||||
point: RecoveryPoint,
|
||||
systems: readonly Resource[],
|
||||
): TrueNASProtectionStaleNotice | null {
|
||||
if (systems.length === 0) return null;
|
||||
return resolveProtectionStaleNotice(point, indexTrueNASSystemsForProtection(systems));
|
||||
}
|
||||
|
||||
export function buildTrueNASProtectionStaleNoticeMap(
|
||||
points: readonly RecoveryPoint[],
|
||||
systems: readonly Resource[],
|
||||
): Map<string, TrueNASProtectionStaleNotice> {
|
||||
const notices = new Map<string, TrueNASProtectionStaleNotice>();
|
||||
if (points.length === 0 || systems.length === 0) return notices;
|
||||
const indexed = indexTrueNASSystemsForProtection(systems);
|
||||
if (!indexed.some((entry) => entry.notice !== null)) return notices;
|
||||
for (const point of points) {
|
||||
const notice = resolveProtectionStaleNotice(point, indexed);
|
||||
if (notice) notices.set(point.id, notice);
|
||||
}
|
||||
return notices;
|
||||
}
|
||||
|
||||
export function mapTrueNASProtectionStatus(point: RecoveryPoint): TrueNASProtectionStatusBucket {
|
||||
return normalizeProtectionOutcome(point.outcome);
|
||||
}
|
||||
|
||||
export type TrueNASProtectionPosture = {
|
||||
healthy: number;
|
||||
stale: number;
|
||||
warning: number;
|
||||
failed: number;
|
||||
running: number;
|
||||
@@ -915,9 +1099,11 @@ export type TrueNASProtectionPosture = {
|
||||
|
||||
export function buildTrueNASProtectionPosture(
|
||||
points: readonly RecoveryPoint[],
|
||||
staleNotices?: ReadonlyMap<string, TrueNASProtectionStaleNotice>,
|
||||
): TrueNASProtectionPosture {
|
||||
const posture: TrueNASProtectionPosture = {
|
||||
healthy: 0,
|
||||
stale: 0,
|
||||
warning: 0,
|
||||
failed: 0,
|
||||
running: 0,
|
||||
@@ -926,10 +1112,19 @@ export function buildTrueNASProtectionPosture(
|
||||
};
|
||||
for (const point of points) {
|
||||
const status = mapTrueNASProtectionStatus(point);
|
||||
if (status === 'success') posture.healthy += 1;
|
||||
else posture[status] += 1;
|
||||
const isStale = Boolean(staleNotices?.get(point.id));
|
||||
if (isStale) posture.stale += 1;
|
||||
if (status === 'success') {
|
||||
if (!isStale) posture.healthy += 1;
|
||||
} else if (status === 'running') {
|
||||
if (!isStale) posture.running += 1;
|
||||
} else {
|
||||
posture[status] += 1;
|
||||
}
|
||||
if (status === 'failed' || status === 'warning' || isStale) {
|
||||
posture.attention += 1;
|
||||
}
|
||||
}
|
||||
posture.attention = posture.warning + posture.failed;
|
||||
return posture;
|
||||
}
|
||||
|
||||
@@ -949,7 +1144,10 @@ export function mapTrueNASProtectionKind(point: RecoveryPoint): TrueNASProtectio
|
||||
return 'other';
|
||||
}
|
||||
|
||||
const trueNASProtectionSearchTokens = (point: RecoveryPoint): string => {
|
||||
const trueNASProtectionSearchTokens = (
|
||||
point: RecoveryPoint,
|
||||
staleNotice?: TrueNASProtectionStaleNotice,
|
||||
): string => {
|
||||
const details = point.details ?? {};
|
||||
const sourceDatasets = Array.isArray(details.sourceDatasets) ? details.sourceDatasets : [];
|
||||
return joinSearchTokens([
|
||||
@@ -978,20 +1176,31 @@ const trueNASProtectionSearchTokens = (point: RecoveryPoint): string => {
|
||||
details.taskId,
|
||||
details.taskName,
|
||||
...sourceDatasets,
|
||||
staleNotice?.badge,
|
||||
staleNotice?.detail,
|
||||
staleNotice?.systemName,
|
||||
]);
|
||||
};
|
||||
|
||||
const trueNASProtectionAttentionRank = (point: RecoveryPoint): number => {
|
||||
const trueNASProtectionAttentionRank = (
|
||||
point: RecoveryPoint,
|
||||
staleNotices?: ReadonlyMap<string, TrueNASProtectionStaleNotice>,
|
||||
): number => {
|
||||
const status = mapTrueNASProtectionStatus(point);
|
||||
if (status === 'failed') return 0;
|
||||
if (status === 'warning') return 1;
|
||||
return 2;
|
||||
if (staleNotices?.has(point.id)) return 2;
|
||||
return 3;
|
||||
};
|
||||
|
||||
export function sortTrueNASProtectionPoints(points: readonly RecoveryPoint[]): RecoveryPoint[] {
|
||||
export function sortTrueNASProtectionPoints(
|
||||
points: readonly RecoveryPoint[],
|
||||
staleNotices?: ReadonlyMap<string, TrueNASProtectionStaleNotice>,
|
||||
): RecoveryPoint[] {
|
||||
return [...points].sort((left, right) => {
|
||||
const attentionDelta =
|
||||
trueNASProtectionAttentionRank(left) - trueNASProtectionAttentionRank(right);
|
||||
trueNASProtectionAttentionRank(left, staleNotices) -
|
||||
trueNASProtectionAttentionRank(right, staleNotices);
|
||||
if (attentionDelta !== 0) return attentionDelta;
|
||||
const leftTime = getRecoveryPointTimestampMs(left);
|
||||
const rightTime = getRecoveryPointTimestampMs(right);
|
||||
@@ -1013,17 +1222,37 @@ export function filterTrueNASProtectionPoints(
|
||||
points: RecoveryPoint[],
|
||||
search: string,
|
||||
status: TrueNASProtectionStatusFilter,
|
||||
staleNotices?: ReadonlyMap<string, TrueNASProtectionStaleNotice>,
|
||||
): RecoveryPoint[] {
|
||||
const needle = search.trim().toLowerCase();
|
||||
return points.filter((point) => {
|
||||
const pointStatus = mapTrueNASProtectionStatus(point);
|
||||
if (status === 'attention' && pointStatus !== 'warning' && pointStatus !== 'failed') {
|
||||
const staleNotice = staleNotices?.get(point.id);
|
||||
const isStale = Boolean(staleNotice);
|
||||
if (
|
||||
status === 'attention' &&
|
||||
pointStatus !== 'warning' &&
|
||||
pointStatus !== 'failed' &&
|
||||
!isStale
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (status === 'stale' && !isStale) return false;
|
||||
if (status === 'success' && (pointStatus !== 'success' || isStale)) return false;
|
||||
if (status === 'running' && (pointStatus !== 'running' || isStale)) return false;
|
||||
if (
|
||||
status !== 'all' &&
|
||||
status !== 'attention' &&
|
||||
status !== 'stale' &&
|
||||
status !== 'success' &&
|
||||
status !== 'running' &&
|
||||
pointStatus !== status
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (status !== 'all' && status !== 'attention' && pointStatus !== status) return false;
|
||||
if (!needle) return true;
|
||||
if (mapTrueNASProtectionKind(point).includes(needle)) return true;
|
||||
return trueNASProtectionSearchTokens(point).includes(needle);
|
||||
return trueNASProtectionSearchTokens(point, staleNotice).includes(needle);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user