diff --git a/frontend-modern/browser-verification/cb60935a2e734b62.json b/frontend-modern/browser-verification/cb60935a2e734b62.json new file mode 100644 index 0000000000..ee059dacd7 --- /dev/null +++ b/frontend-modern/browser-verification/cb60935a2e734b62.json @@ -0,0 +1,49 @@ +{ + "version": 1, + "base_sha": "fa26be2e2f35f5daced2024060a26df0ff60bb42", + "verified_at": "2026-11-27T20:24:33Z", + "result": "passed", + "changed_paths": [ + "frontend-modern/src/components/Storage/DiskDrawerOverview.tsx", + "frontend-modern/src/components/Storage/DiskList.tsx", + "frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx", + "frontend-modern/src/features/storageBackups/diskDrawerPresentation.ts", + "frontend-modern/src/features/storageBackups/diskPresentation.ts", + "frontend-modern/src/features/storageBackups/diskTemperaturePresentation.ts", + "frontend-modern/src/features/storageBackups/storagePoolDetailPresentation.ts" + ], + "content_sha256": { + "frontend-modern/src/components/Storage/DiskDrawerOverview.tsx": "1a535354a7802e1ebee95965ecba7607373fe31f34e477ccec71d381f36e88bf", + "frontend-modern/src/components/Storage/DiskList.tsx": "3e915a4c94eaf3c2dfc75827650a09de8921a155c1b84cff53f97c2b12b7a7b7", + "frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx": "6ea98e64d3942bc866c03c73dcad00e662809df5e6aafb6e0aeb2039b009506d", + "frontend-modern/src/features/storageBackups/diskDrawerPresentation.ts": "ab49c24c4007bf31ee4fce308cb68c7cbd22fabd0dcdd8106bfb4eed87826668", + "frontend-modern/src/features/storageBackups/diskPresentation.ts": "aeb70f130891f1e09688ed3b23e646e047414987e19a4421b85980dff64975a9", + "frontend-modern/src/features/storageBackups/diskTemperaturePresentation.ts": "c4d049ee29ff7139b4f6cd6afb882c4c22e22b2c629d6c44c58351fe1a307b11", + "frontend-modern/src/features/storageBackups/storagePoolDetailPresentation.ts": "0e90a4f217bd206850f8987b926031bf9ac1a01d6f18672942277d5d8dae8789" + }, + "routes": [ + "/proxmox/storage" + ], + "viewports": [ + { + "width": 1440, + "height": 940 + }, + { + "width": 390, + "height": 844 + } + ], + "states": [ + "Paired production builds (before fa26be2e2f35 vs after) verified via pulse-worker-browser (Playwright 1.56.1) on desktop Chromium 141.0.7390.37 (1440x940 light) and touch WebKit phone 26.0 (390x844 dark); all 13 screenshots visually inspected with 0 console errors, 0 page errors, 0 failed/4xx+ requests, 0 off-origin requests, and 0px horizontal overflow (1440/1440 and 390/390).", + "Physical Disks table on /proxmox/storage: stale Samsung 870 EVO 2TB (pve-stale, 16m error Proxmox node poll timed out, retained 68C, 94% life) changes from false red Running Hot/Hot + live red 68C + green 94% to amber Stale + muted dotted last-known 68C and 94%; stale failed WDC Red Pro 8TB preserves red Replace Now/Replace while gaining amber Stale data cue beneath disk name and muted dotted last-known 45C; fresh Intel Optane P4800X stays green Healthy + 98% + 36C.", + "Expanded Samsung 870 EVO 2TB drawer switches from red dot + Running Hot Worth checking + current latest readings to amber Stale dot + amber Stale data InlineNotice warning banner (including refresh age and poll timeout reason) + last-known deferred metrics + Stale SMART health card with no duplicate Worth checking row.", + "Expanded WDC Red Pro 8TB drawer shows both the amber Stale data InlineNotice warning banner and preserved red Replace Now + Reallocated/Pending Sectors in Worth checking, with last-known deferred readings.", + "Live RFC 6455 WebSocket rawData recovery while Samsung 870 EVO 2TB drawer stays open reactively clears the Stale data banner, restores green Healthy dot, live 36C temperature, green 94% life, and current latest readings, and removes the Stale data cue from WDC Red Pro 8TB while preserving Replace Now." + ], + "interactions": [ + "Navigated to /proxmox/storage and clicked the Physical Disks tab on desktop light (1440x940) and touch phone dark (390x844).", + "Expanded Samsung 870 EVO 2TB and WDC Red Pro 8TB inline drawers in both before and after production builds and compared paired pixels.", + "Re-opened Samsung 870 EVO 2TB drawer on desktop light and delivered a live WebSocket rawData recovery snapshot verifying reactive clearance without page reload." + ] +} diff --git a/frontend-modern/src/components/Storage/DiskDrawerOverview.tsx b/frontend-modern/src/components/Storage/DiskDrawerOverview.tsx index 5ac95dd7f5..1e873c7483 100644 --- a/frontend-modern/src/components/Storage/DiskDrawerOverview.tsx +++ b/frontend-modern/src/components/Storage/DiskDrawerOverview.tsx @@ -2,6 +2,7 @@ import { Component, For, Show, Suspense, createMemo, lazy } from 'solid-js'; import type { HistoryTimeRange } from '@/api/charts'; import type { DetailSection } from '@/components/shared/DetailSectionTable'; import { DrawerAttentionSection } from '@/components/shared/DrawerAttentionSection'; +import { InlineNotice } from '@/components/shared/InlineNotice'; import { TechnicalDetailsDisclosure, TechnicalDetailsSection, @@ -28,7 +29,10 @@ import { getDiskDrawerNotices, isDiskDrawerIOAvailable, } from '@/features/storageBackups/diskDrawerPresentation'; -import type { PhysicalDiskPresentationData } from '@/features/storageBackups/diskPresentation'; +import { + getPhysicalDiskStaleDetail, + type PhysicalDiskPresentationData, +} from '@/features/storageBackups/diskPresentation'; import type { Alert } from '@/types/api'; import type { Resource } from '@/types/resource'; import { useRelativeTimeNow } from '@/utils/relativeTimeClock'; @@ -101,6 +105,10 @@ export const DiskDrawerOverview: Component = (props) => ); const notices = createMemo(() => getDiskDrawerNotices(props.diskData)); const facts = createMemo(() => getDiskDrawerFacts(props.diskData, props.disk)); + const staleDetail = createMemo(() => { + const detail = getPhysicalDiskStaleDetail(props.diskData); + return detail && !/[.!?]$/.test(detail) ? `${detail}.` : detail; + }); return (
@@ -115,6 +123,15 @@ export const DiskDrawerOverview: Component = (props) => }))} /> + +
+ + Stale data. {staleDetail()} Health, temperature, and + SMART readings reflect the last report received and may no longer be current. + +
+
+ {/* What the collector could not read says so once, above the charts it diff --git a/frontend-modern/src/components/Storage/DiskList.tsx b/frontend-modern/src/components/Storage/DiskList.tsx index c9013c47ec..51da7a0ca7 100644 --- a/frontend-modern/src/components/Storage/DiskList.tsx +++ b/frontend-modern/src/components/Storage/DiskList.tsx @@ -82,6 +82,7 @@ import { getPhysicalDiskLifeTextClass, getPhysicalDiskParentLabel, getPhysicalDiskRoleLabel, + getPhysicalDiskStaleDetail, getPhysicalDiskTableLayoutModeForContainer, getPhysicalDiskTemperaturePresentation, isPhysicalDiskColumnVisible, @@ -342,6 +343,11 @@ export const DiskList: Component = (props) => { // the row first mounts, so health and identity cannot go stale. const data = createMemo(() => model.getDiskData(disk)); const status = createMemo(() => getPhysicalDiskHealthStatus(data())); + const isStale = () => data().freshness === 'stale'; + const staleDetail = createMemo(() => + isStale() ? getPhysicalDiskStaleDetail(data()) : '', + ); + const showInlineStaleCue = () => isStale() && status().label !== 'Stale'; const hostLabel = createMemo(() => model.getDiskHostLabel(disk)); const hostTitle = createMemo(() => model.getDiskHostTitle(disk)); const healthSummary = createMemo(() => getPhysicalDiskHealthSummary(status())); @@ -396,12 +402,23 @@ export const DiskList: Component = (props) => { onAction={() => model.toggleSelectedDisk(disk)} onPreviewClear={() => props.onHoverChange?.(null)} /> - - {data().model || 'Unknown Disk'} - +
+ + {data().model || 'Unknown Disk'} + + + + Stale data + + +
@@ -511,8 +528,13 @@ export const DiskList: Component = (props) => { > {getPhysicalDiskLifeLabel(data())} + + , last known + diff --git a/frontend-modern/src/components/Storage/__tests__/DiskDrawer.test.tsx b/frontend-modern/src/components/Storage/__tests__/DiskDrawer.test.tsx index 0ede98d6d2..7789fcb2e6 100644 --- a/frontend-modern/src/components/Storage/__tests__/DiskDrawer.test.tsx +++ b/frontend-modern/src/components/Storage/__tests__/DiskDrawer.test.tsx @@ -321,4 +321,49 @@ describe('DiskDrawer', () => { expect(screen.getByTestId('operator-state')).toHaveTextContent('physical_disk:disk-1'); expect(screen.getByTestId('drawer-history')).toHaveAttribute('data-enabled', 'false'); }); + + it('shows the stale-readings notice without duplicating Worth checking, preserves faults, and clears on recovery', () => { + const staleHealthy = { + ...buildDisk({ diskType: 'ssd', wearout: 94, temperature: 44 }), + sourceStatus: { + proxmox: { + status: 'error', + lastSeen: Date.now() - 18 * 60_000, + error: 'Proxmox node unreachable', + }, + }, + } as unknown as Resource; + const [disk, setDisk] = createSignal(staleHealthy); + renderDrawer(disk); + + expect(screen.getByLabelText('Stale').className).toContain('amber'); + expect(screen.getByTestId('disk-drawer-stale-notice')).toHaveTextContent('Stale data.'); + expect(screen.getByTestId('disk-drawer-stale-notice')).toHaveTextContent( + 'Proxmox node unreachable', + ); + expect(screen.queryByTestId('disk-drawer-exceptions')).toBeNull(); + const card = screen.getByTestId('disk-drawer-health-card'); + expect(within(card).getByText('Stale')).toBeInTheDocument(); + expect(within(card).getByText('Last known temperature')).toBeInTheDocument(); + + // A stale failing disk keeps Replace Now in Worth checking alongside the stale banner. + setDisk({ + ...staleHealthy, + physicalDisk: { ...staleHealthy.physicalDisk!, health: 'FAILED' }, + } as unknown as Resource); + expect(screen.getByLabelText('Replace Now').className).toContain('red'); + expect(screen.getByTestId('disk-drawer-stale-notice')).toBeInTheDocument(); + expect(screen.getByTestId('disk-drawer-exceptions')).toHaveTextContent('Replace Now'); + + // Live recovery clears the stale banner and returns live temperature framing. + setDisk({ + ...staleHealthy, + sourceStatus: { proxmox: { status: 'online', lastSeen: Date.now() } }, + } as unknown as Resource); + expect(screen.queryByTestId('disk-drawer-stale-notice')).toBeNull(); + expect(screen.getByLabelText('Healthy').className).toContain('emerald'); + expect( + within(screen.getByTestId('disk-drawer-health-card')).getByText('Temperature'), + ).toBeInTheDocument(); + }); }); diff --git a/frontend-modern/src/components/Storage/__tests__/DiskList.test.tsx b/frontend-modern/src/components/Storage/__tests__/DiskList.test.tsx index 5f2c6ca446..842c0a77b7 100644 --- a/frontend-modern/src/components/Storage/__tests__/DiskList.test.tsx +++ b/frontend-modern/src/components/Storage/__tests__/DiskList.test.tsx @@ -698,4 +698,86 @@ describe('DiskList', () => { expect(screen.queryByText('pve20')).toBeNull(); expect(screen.getByText('ext4')).toBeInTheDocument(); }); + + it('surfaces Stale health and last-known metrics for stale sources, preserves faults with Stale data cue, and clears on recovery', async () => { + const healthyDisk = { + ...buildDisk('sda', 'pve-stale', { + model: 'Samsung 870 EVO', + diskType: 'ssd', + wearout: 94, + temperature: 68, + health: 'PASSED', + }), + sourceStatus: { + proxmox: { + status: 'error', + lastSeen: Date.now() - 15 * 60_000, + error: 'Proxmox poll timed out', + }, + }, + } as unknown as Resource; + const failedDisk = { + ...buildDisk('sdb', 'pve-stale', { + model: 'WDC Archive', + diskType: 'hdd', + temperature: 46, + health: 'FAILED', + }), + sourceStatus: { + proxmox: { + status: 'stale', + lastSeen: Date.now() - 15 * 60_000, + }, + }, + } as unknown as Resource; + + const [disks, setDisks] = createSignal([healthyDisk, failedDisk]); + const view = render(() => ( + {}} + /> + )); + + const sdaRow = view.container.querySelector('[data-row-id="sda"]')!; + expect(within(sdaRow).getByText('Stale')).toBeInTheDocument(); + expect(sdaRow.querySelector('[data-disk-stale-cue]')).toBeNull(); + const sdaTemp = sdaRow.querySelector('[data-temperature-reading]')!; + expect(sdaTemp).toHaveAttribute('data-temperature-reading', 'last-known'); + expect(sdaTemp).toHaveAttribute('title', expect.stringContaining('Proxmox poll timed out')); + const sdaLife = sdaRow.querySelector('[data-life-reading]')!; + expect(sdaLife).toHaveAttribute('data-life-reading', 'last-known'); + expect(sdaLife).toHaveTextContent('94%, last known'); + + const sdbRow = view.container.querySelector('[data-row-id="sdb"]')!; + expect(within(sdbRow).getByText('Replace Now')).toBeInTheDocument(); + expect(sdbRow.querySelector('[data-disk-stale-cue]')).toHaveTextContent('Stale data'); + + // Live recovery restores live verdict, temperature, and wearout styling. + setDisks([ + { + ...healthyDisk, + physicalDisk: { ...healthyDisk.physicalDisk!, temperature: 36 }, + sourceStatus: { proxmox: { status: 'online', lastSeen: Date.now() } }, + } as unknown as Resource, + { + ...failedDisk, + sourceStatus: { proxmox: { status: 'online', lastSeen: Date.now() } }, + } as unknown as Resource, + ]); + await waitFor(() => expect(within(sdaRow).getByText('Healthy')).toBeInTheDocument()); + expect(sdaRow.querySelector('[data-temperature-reading]')).toHaveAttribute( + 'data-temperature-reading', + 'current', + ); + expect(sdaRow.querySelector('[data-life-reading]')).toHaveAttribute( + 'data-life-reading', + 'current', + ); + expect(sdbRow.querySelector('[data-disk-stale-cue]')).toBeNull(); + }); }); diff --git a/frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx b/frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx index 68753e622d..00dd59a911 100644 --- a/frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx +++ b/frontend-modern/src/components/Workloads/GuestPhysicalDisks.tsx @@ -21,6 +21,7 @@ import { useUnifiedResources } from '@/hooks/useUnifiedResources'; import { extractPhysicalDiskPresentationData, getPhysicalDiskHealthStatus, + getPhysicalDiskStaleDetail, } from '@/features/storageBackups/diskPresentation'; import { PHYSICAL_DISK_TEMPERATURE_LAST_KNOWN_CLASS, @@ -92,6 +93,15 @@ const GuestPhysicalDiskRow: Component<{ {health().label} + + + Stale data + + {(reading) => ( { tone: 'default', }); }); + + it('defers all chart metrics and mutes retained readings when the disk source is stale', () => { + const staleDisk = disk({ + type: 'nvme', + wearout: 92, + temperature: 44, + freshness: 'stale', + freshnessReason: 'Retained last-known disk readings. Last successful refresh 14m ago.', + smartAttributes: { percentageUsed: 8, availableSpare: 99 }, + }); + + expect(getPhysicalDiskHealthIndicator(staleDisk)).toEqual({ + variant: 'warning', + label: 'Stale', + }); + expect(getDiskDrawerCurrentMetrics(staleDisk)).toEqual({}); + expect(getDiskDrawerDeferredMetrics(staleDisk)).toEqual({ + smart_temp: { + lastKnownValue: 44, + message: + 'Last known reading, not current: Retained last-known disk readings. Last successful refresh 14m ago.', + }, + smart_percentage_used: { + lastKnownValue: 8, + message: 'Retained last-known disk readings. Last successful refresh 14m ago.', + }, + smart_available_spare: { + lastKnownValue: 99, + message: 'Retained last-known disk readings. Last successful refresh 14m ago.', + }, + }); + const health = buildDiskDrawerHealthSection(staleDisk); + expect(health.rows.find((row) => row.label === 'Health')).toMatchObject({ + value: 'Stale', + tone: 'default', + }); + expect(health.rows.find((row) => row.label === 'Last known temperature')).toMatchObject({ + value: '44°C', + tone: 'muted', + }); + expect(health.rows.find((row) => row.label === 'Life remaining')).toMatchObject({ + value: '92%', + tone: 'muted', + }); + }); }); diff --git a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.test.ts b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.test.ts index f927939f4a..a007bfb6a6 100644 --- a/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.test.ts +++ b/frontend-modern/src/features/storageBackups/__tests__/diskPresentation.test.ts @@ -6,6 +6,7 @@ import { buildPhysicalDiskGroupFilterOptions, buildPhysicalDiskRoleFilterOptions, comparePhysicalDiskPresentation, + extractPhysicalDiskFreshness, extractPhysicalDiskPresentationData, filterAndSortPhysicalDisks, PHYSICAL_DISK_EMPTY_CARD_CLASS, @@ -1027,3 +1028,197 @@ describe('wearout evidence boundary', () => { ); }); }); + +describe('physical disk source freshness', () => { + const makeResource = (overrides: Partial = {}): Resource => + ({ + id: 'disk-stale-1', + type: 'physical_disk', + name: 'Samsung 870 EVO', + platformId: 'pve-cluster', + platformType: 'proxmox-pve', + sourceType: 'api', + status: 'online', + lastSeen: Date.now() - 15 * 60_000, + physicalDisk: { + devPath: '/dev/sda', + model: 'Samsung 870 EVO', + diskType: 'ssd', + sizeBytes: 1_000_000_000_000, + health: 'PASSED', + wearout: 94, + temperature: 72, + }, + ...overrides, + }) as unknown as Resource; + + const isoAgo = (minutes: number) => new Date(Date.now() - minutes * 60_000).toISOString(); + + it('extracts stale freshness from impaired sourceStatus and prefers top-level over platformData', () => { + const staleResource = makeResource({ + sourceStatus: { + proxmox: { + status: 'error', + lastSeen: isoAgo(12), + error: 'Proxmox API timed out', + }, + }, + }); + expect(extractPhysicalDiskFreshness(staleResource)).toMatchObject({ + freshness: 'stale', + freshnessError: 'Proxmox API timed out', + }); + + // Live top-level recovery clears an older stale platformData.sourceStatus copy. + const recovered = makeResource({ + sourceStatus: { proxmox: { status: 'online', lastSeen: isoAgo(0) } }, + platformData: { + sourceStatus: { proxmox: { status: 'stale', error: 'old timeout' } }, + }, + }); + expect(extractPhysicalDiskFreshness(recovered).freshness).toBe('fresh'); + + // Availability checks are not a disk's own telemetry source. + const availabilityOnly = makeResource({ + sourceStatus: { + availability: { status: 'stale' }, + proxmox: { status: 'online', lastSeen: isoAgo(0) }, + }, + }); + expect(extractPhysicalDiskFreshness(availabilityOnly).freshness).toBe('fresh'); + }); + + it('surfaces Stale for stale healthy disks, preserves Replace Now for stale failed disks, and treats stale temps and life as last known', () => { + const staleHot = extractPhysicalDiskPresentationData( + makeResource({ + sourceStatus: { + proxmox: { + status: 'stale', + lastSeen: isoAgo(20), + error: 'node polling stalled', + }, + }, + }), + ); + + // Retained 72°C must not trigger live Running Hot; Health reads Stale instead. + expect(getPhysicalDiskHealthStatus(staleHot)).toMatchObject({ + label: 'Stale', + tone: 'text-amber-700 dark:text-amber-300', + }); + expect(getPhysicalDiskHealthStatus(staleHot).summary).toContain('node polling stalled'); + expect(getPhysicalDiskTemperaturePresentation(staleHot)).toMatchObject({ + label: '72°C', + current: false, + }); + expect(getPhysicalDiskLifeTextClass(staleHot)).toBe(PHYSICAL_DISK_TEMPERATURE_LAST_KNOWN_CLASS); + expect(getPhysicalDiskNormalizedHealth(makeResource(), staleHot)).toBe('warning'); + + // A critical drive fault remains Replace Now even when its source stops updating. + const staleFailed = extractPhysicalDiskPresentationData( + makeResource({ + sourceStatus: { agent: { status: 'stale', lastSeen: isoAgo(10) } }, + physicalDisk: { + devPath: '/dev/sdb', + model: 'Archive HDD', + diskType: 'hdd', + sizeBytes: 4_000_000_000_000, + health: 'FAILED', + temperature: 44, + }, + }), + ); + expect(getPhysicalDiskHealthStatus(staleFailed)).toMatchObject({ + label: 'Replace Now', + tone: 'text-red-700 dark:text-red-300', + }); + expect(getPhysicalDiskNormalizedHealth(makeResource(), staleFailed)).toBe('critical'); + }); + + it('sorts stale disks above fresh healthy disks and matches stale and error search terms', () => { + const freshResource = makeResource({ + id: 'disk-fresh', + sourceStatus: { proxmox: { status: 'online', lastSeen: isoAgo(0) } }, + physicalDisk: { + devPath: '/dev/sda', + model: 'Fresh SSD', + diskType: 'ssd', + sizeBytes: 1_000_000_000_000, + health: 'PASSED', + temperature: 34, + }, + }); + const staleResource = makeResource({ + id: 'disk-stale', + sourceStatus: { + proxmox: { + status: 'error', + lastSeen: isoAgo(15), + error: 'pve-b API timed out', + }, + }, + physicalDisk: { + devPath: '/dev/sdb', + model: 'Stale SSD', + diskType: 'ssd', + sizeBytes: 1_000_000_000_000, + health: 'PASSED', + temperature: 38, + }, + }); + const failedResource = makeResource({ + id: 'disk-failed', + sourceStatus: { proxmox: { status: 'online', lastSeen: isoAgo(0) } }, + physicalDisk: { + devPath: '/dev/sdc', + model: 'Failed HDD', + diskType: 'hdd', + sizeBytes: 2_000_000_000_000, + health: 'FAILED', + temperature: 40, + }, + }); + const byId = new Map( + [freshResource, staleResource, failedResource].map((item) => [ + item.id, + extractPhysicalDiskPresentationData(item), + ]), + ); + + expect( + filterAndSortPhysicalDisks([freshResource, staleResource, failedResource], { + selectedNode: null, + searchTerm: '', + healthFilter: 'all', + getDiskData: (item) => byId.get(item.id)!, + matchesNode: () => true, + }).map((item) => item.id), + ).toEqual(['disk-failed', 'disk-stale', 'disk-fresh']); + + expect( + filterAndSortPhysicalDisks([freshResource, staleResource], { + selectedNode: null, + searchTerm: '', + healthFilter: 'healthy', + getDiskData: (item) => byId.get(item.id)!, + matchesNode: () => true, + }).map((item) => item.id), + ).toEqual(['disk-fresh']); + + expect( + filterAndSortPhysicalDisks([freshResource, staleResource], { + selectedNode: null, + searchTerm: '', + healthFilter: 'attention', + getDiskData: (item) => byId.get(item.id)!, + matchesNode: () => true, + }).map((item) => item.id), + ).toEqual(['disk-stale']); + + expect(matchesPhysicalDiskSearch(staleResource, byId.get('disk-stale')!, 'stale')).toBe(true); + expect(matchesPhysicalDiskSearch(staleResource, byId.get('disk-stale')!, 'api timed out')).toBe( + true, + ); + expect(matchesPhysicalDiskSearch(freshResource, byId.get('disk-fresh')!, 'stale')).toBe(false); + }); +}); diff --git a/frontend-modern/src/features/storageBackups/__tests__/storagePoolDetailPresentation.test.ts b/frontend-modern/src/features/storageBackups/__tests__/storagePoolDetailPresentation.test.ts index 98e5ef86b5..a34ad40e9f 100644 --- a/frontend-modern/src/features/storageBackups/__tests__/storagePoolDetailPresentation.test.ts +++ b/frontend-modern/src/features/storageBackups/__tests__/storagePoolDetailPresentation.test.ts @@ -345,4 +345,22 @@ describe('storagePoolDetailPresentation', () => { ]), ); }); + + it('marks linked disk temperature as last known when the disk reporting source is stale', () => { + const record = buildRecord(); + const staleDisk = { + ...buildDisk(), + sourceStatus: { + truenas: { + status: 'stale', + lastSeen: new Date(Date.now() - 18 * 60_000).toISOString(), + error: 'TrueNAS API unreachable', + }, + }, + } as Resource; + + const [linked] = getStoragePoolLinkedDisks(record, [staleDisk]); + expect(linked.temperatureLastKnownTitle).toContain('Last known reading, not current:'); + expect(linked.temperatureLastKnownTitle).toContain('TrueNAS API unreachable'); + }); }); diff --git a/frontend-modern/src/features/storageBackups/diskDrawerPresentation.ts b/frontend-modern/src/features/storageBackups/diskDrawerPresentation.ts index 1eee1a3824..7d2d56a866 100644 --- a/frontend-modern/src/features/storageBackups/diskDrawerPresentation.ts +++ b/frontend-modern/src/features/storageBackups/diskDrawerPresentation.ts @@ -25,6 +25,7 @@ import { getPhysicalDiskParentLabel, getPhysicalDiskRoleLabel, getPhysicalDiskSourceBadgePresentation, + getPhysicalDiskStaleDetail, getPhysicalDiskTemperaturePresentation, getPhysicalDiskTemperatureThresholds, isPhysicalDiskWearoutReported, @@ -116,10 +117,13 @@ export function isDiskDrawerIOAvailable(disk: PhysicalDiskPresentationData): boo const finite = (value: number | undefined): number | undefined => typeof value === 'number' && Number.isFinite(value) ? value : undefined; +const ensureSentence = (value: string): string => (/[.!?]$/.test(value) ? value : `${value}.`); + /** Current readings the charts show before any history is stored. */ export function getDiskDrawerCurrentMetrics( disk: PhysicalDiskPresentationData, ): Record { + if (disk.freshness === 'stale') return {}; const temperature = getPhysicalDiskTemperaturePresentation(disk); const attrs = disk.smartAttributes ?? {}; return { @@ -130,19 +134,43 @@ export function getDiskDrawerCurrentMetrics( }; } -/** A retained temperature is charted as last known, never as live. */ +/** A retained temperature or stale disk snapshot is charted as last known, never as live. */ export function getDiskDrawerDeferredMetrics( disk: PhysicalDiskPresentationData, ): Record | undefined { const temperature = getPhysicalDiskTemperaturePresentation(disk); + if (disk.freshness === 'stale') { + const message = ensureSentence(getPhysicalDiskStaleDetail(disk)); + const attrs = disk.smartAttributes ?? {}; + const deferred: Record = {}; + if (temperature) { + deferred.smart_temp = { + lastKnownValue: disk.temperature, + message: temperature.title ? ensureSentence(temperature.title) : message, + }; + } + const reallocated = finite(attrs.reallocatedSectors); + if (reallocated !== undefined) { + deferred.smart_reallocated_sectors = { lastKnownValue: reallocated, message }; + } + const pctUsed = finite(attrs.percentageUsed); + if (pctUsed !== undefined) { + deferred.smart_percentage_used = { lastKnownValue: pctUsed, message }; + } + const spare = finite(attrs.availableSpare); + if (spare !== undefined) { + deferred.smart_available_spare = { lastKnownValue: spare, message }; + } + return Object.keys(deferred).length > 0 ? deferred : undefined; + } if (!temperature || temperature.current || !temperature.title) return undefined; return { - smart_temp: { lastKnownValue: disk.temperature, message: `${temperature.title}.` }, + smart_temp: { lastKnownValue: disk.temperature, message: ensureSentence(temperature.title) }, }; } const lifeTone = (disk: PhysicalDiskPresentationData): DetailValueTone => { - if (!isPhysicalDiskWearoutReported(disk)) return 'muted'; + if (!isPhysicalDiskWearoutReported(disk) || disk.freshness === 'stale') return 'muted'; const textClass = getPhysicalDiskLifeTextClass(disk); if (textClass.includes('red')) return 'danger'; if (textClass.includes('amber')) return 'warning'; @@ -163,21 +191,32 @@ export function buildDiskDrawerHealthSection(disk: PhysicalDiskPresentationData) const indicator = getPhysicalDiskHealthIndicator(disk); const summary = getPhysicalDiskHealthSummary(status); const temperature = getPhysicalDiskTemperaturePresentation(disk); + const isStale = disk.freshness === 'stale'; + const staleDetail = isStale ? getPhysicalDiskStaleDetail(disk) : undefined; + const staleVerdictOnly = isStale && status.label === 'Stale'; return { label: 'SMART health', testId: 'disk-drawer-health', rows: compactDetailRows([ - makeDetailRow('Health', summary ? `${status.label}: ${summary}` : status.label, { - tone: - indicator.variant === 'danger' - ? 'danger' - : indicator.variant === 'warning' - ? 'warning' - : indicator.variant === 'success' - ? 'success' - : 'default', - wrap: true, - }), + makeDetailRow( + 'Health', + staleVerdictOnly ? status.label : summary ? `${status.label}: ${summary}` : status.label, + { + // Stale-only disks show the prominent amber banner above the charts; + // keep the Health row inside SMART health instead of repeating it in Worth checking. + tone: staleVerdictOnly + ? 'default' + : indicator.variant === 'danger' + ? 'danger' + : indicator.variant === 'warning' + ? 'warning' + : indicator.variant === 'success' + ? 'success' + : 'default', + title: staleVerdictOnly ? staleDetail : undefined, + wrap: true, + }, + ), temperature ? makeDetailRow( temperature.current ? 'Temperature' : 'Last known temperature', @@ -190,10 +229,12 @@ export function buildDiskDrawerHealthSection(disk: PhysicalDiskPresentationData) // Worn flash already turns the verdict above; the life left then stays // in this card instead of repeating the verdict in Worth checking. makeDetailRow('Life remaining', getPhysicalDiskLifeLabel(disk), { - tone: - indicator.variant === 'warning' || indicator.variant === 'danger' + tone: isStale + ? 'muted' + : indicator.variant === 'warning' || indicator.variant === 'danger' ? 'default' : lifeTone(disk), + title: isStale ? staleDetail : undefined, }), ]), }; diff --git a/frontend-modern/src/features/storageBackups/diskPresentation.ts b/frontend-modern/src/features/storageBackups/diskPresentation.ts index c1b833b898..1917622913 100644 --- a/frontend-modern/src/features/storageBackups/diskPresentation.ts +++ b/frontend-modern/src/features/storageBackups/diskPresentation.ts @@ -20,9 +20,12 @@ import { } from '@/utils/metricThresholds'; import { normalizeStorageSourceKey, storageSourceMatchesFilter } from '@/utils/storageSources'; import type { StatusIndicator } from '@/utils/status'; +import { formatRelativeTime } from '@/utils/format'; import { + PHYSICAL_DISK_TEMPERATURE_LAST_KNOWN_CLASS, getPhysicalDiskHeatSummary, isPhysicalDiskRunningHot, + type PhysicalDiskFreshness, } from './diskTemperaturePresentation'; import type { NormalizedHealth, StorageHealthFilter } from './models'; import { matchesStorageNodeTerms, parseStorageSearchQuery } from './storageSearchQuery'; @@ -85,6 +88,10 @@ export interface PhysicalDiskPresentationData { temperatureThresholds?: MetricDisplayThresholds | null; rpm: number; used: string; + freshness?: PhysicalDiskFreshness; + freshnessReason?: string; + freshnessError?: string; + observedAt?: number; collection?: PhysicalDiskCollectionStatus; smartAttributes?: { powerOnHours?: number; @@ -439,6 +446,78 @@ export const getPhysicalDiskTemperatureThresholds = ( ? disk.temperatureThresholds : resolveFactoryDiskTemperatureThresholds(disk.type); +const STALE_PHYSICAL_DISK_SOURCE_STATUSES = new Set([ + 'stale', + 'offline', + 'error', + 'failed', + 'unauthorized', +]); +const CONNECTED_PHYSICAL_DISK_SOURCE_STATUSES = new Set([ + 'online', + 'running', + 'healthy', + 'connected', + 'ok', +]); + +const parseObservedAt = (value: unknown): number | undefined => { + if (typeof value === 'number' && Number.isFinite(value) && value > 0) return value; + if (typeof value === 'string' && value.trim()) { + const parsed = Date.parse(value); + if (Number.isFinite(parsed) && parsed > 0) return parsed; + } + return undefined; +}; + +export function extractPhysicalDiskFreshness(resource: Resource): { + freshness: PhysicalDiskFreshness; + freshnessError?: string; + observedAt?: number; +} { + const sourceStatus = + resource.sourceStatus ?? + (resource.platformData as { sourceStatus?: Resource['sourceStatus'] } | undefined) + ?.sourceStatus; + const entries = Object.entries(sourceStatus ?? {}).filter( + ([source]) => source.trim().toLowerCase() !== 'availability', + ); + const degraded = entries.find(([, entry]) => + STALE_PHYSICAL_DISK_SOURCE_STATUSES.has((entry?.status || '').trim().toLowerCase()), + )?.[1]; + if (degraded) { + return { + freshness: 'stale', + freshnessError: degraded.error?.trim() || undefined, + observedAt: parseObservedAt(degraded.lastSeen) ?? parseObservedAt(resource.lastSeen), + }; + } + const connected = entries.some(([, entry]) => + CONNECTED_PHYSICAL_DISK_SOURCE_STATUSES.has((entry?.status || '').trim().toLowerCase()), + ); + return { + freshness: connected ? 'fresh' : 'unknown', + observedAt: parseObservedAt(resource.lastSeen), + }; +} + +export function getPhysicalDiskStaleDetail( + disk: Pick< + PhysicalDiskPresentationData, + 'freshness' | 'freshnessReason' | 'freshnessError' | 'observedAt' + >, +): string { + if (disk.freshness !== 'stale') return ''; + if (disk.freshnessReason?.trim()) return disk.freshnessReason.trim(); + const observed = + typeof disk.observedAt === 'number' && Number.isFinite(disk.observedAt) && disk.observedAt > 0 + ? formatRelativeTime(disk.observedAt) + : ''; + const age = observed ? ` Last successful refresh ${observed}.` : ''; + const error = disk.freshnessError?.trim() ? ` ${disk.freshnessError.trim()}` : ''; + return `Retained last-known disk readings.${age}${error}`.trim(); +} + export function extractPhysicalDiskPresentationData( resource: Resource, resolveTemperatureThresholds: PhysicalDiskTemperatureThresholdResolver = resolveFactoryDiskTemperatureThresholds, @@ -446,6 +525,9 @@ export function extractPhysicalDiskPresentationData( ): PhysicalDiskPresentationData { const pd = resource.physicalDisk || ((resource.platformData as any)?.physicalDisk ?? {}); const diskNode = getPhysicalDiskNodeIdentity(resource); + const freshnessInfo = extractPhysicalDiskFreshness(resource); + const freshnessReason = + freshnessInfo.freshness === 'stale' ? getPhysicalDiskStaleDetail(freshnessInfo) : undefined; // A reason's severity decides the verdict even when it carries no display // text, so only the summary list drops empty summaries. const riskReasonDetails: ResourceStorageRiskReason[] = Array.isArray(pd.risk?.reasons) @@ -480,6 +562,10 @@ export function extractPhysicalDiskPresentationData( temperatureThresholds: resolveTemperatureThresholds(pd.diskType || '', alertResourceIds), rpm: pd.rpm ?? 0, used: pd.used || '', + freshness: freshnessInfo.freshness, + freshnessReason, + freshnessError: freshnessInfo.freshnessError, + observedAt: freshnessInfo.observedAt, storageRole: pd.storageRole, storageGroup: pd.storageGroup, storageState: pd.storageState, @@ -533,6 +619,7 @@ export { getPhysicalDiskLastKnownTemperatureTitle, getPhysicalDiskTemperaturePresentation, isPhysicalDiskTemperatureCurrent, + type PhysicalDiskFreshness, type PhysicalDiskTemperaturePresentation, } from './diskTemperaturePresentation'; @@ -579,7 +666,7 @@ const getPhysicalDiskVerdictPriority = (disk: PhysicalDiskPresentationData): num case 'attention': return 200; default: - return 0; + return disk.freshness === 'stale' ? 100 : 0; } }; @@ -619,6 +706,9 @@ export function matchesPhysicalDiskSearch( resource, getSourcePlatformLabel(getPhysicalDiskSourceKey(resource)), ), + disk.freshness === 'stale' ? 'stale stale data' : '', + disk.freshnessError, + disk.freshness === 'stale' ? getPhysicalDiskStaleDetail(disk) : '', ] .join(' ') .toLowerCase(); @@ -831,6 +921,14 @@ export function getPhysicalDiskHealthStatus( return { label: 'Needs Attention', summary: verdict.summary, tone: PHYSICAL_DISK_WARNING_TONE }; } + if (disk.freshness === 'stale') { + return { + label: 'Stale', + summary: getPhysicalDiskStaleDetail(disk), + tone: PHYSICAL_DISK_WARNING_TONE, + }; + } + if (isUnraidPhysicalDisk(disk) && !hasUnraidPhysicalDiskFaultSignal(disk)) { return { label: normalizePhysicalDiskState(disk.storageState) === 'online' ? 'Online' : 'Unknown', @@ -877,7 +975,7 @@ export function getPhysicalDiskNormalizedHealth( // A disk running hot sits in the health filter with the critical disks, as // its Temp cell reads red. if (verdict.kind === 'hot') return 'critical'; - if (verdict.kind === 'attention') return 'warning'; + if (verdict.kind === 'attention' || disk.freshness === 'stale') return 'warning'; return clearLabel === 'Healthy' ? 'healthy' : 'unknown'; } @@ -941,6 +1039,9 @@ export function getPhysicalDiskLifeTextClass(disk: PhysicalDiskPresentationData) if (!isPhysicalDiskWearoutReported(disk)) { return PHYSICAL_DISK_MUTED_PLACEHOLDER_CLASS; } + if (disk.freshness === 'stale') { + return PHYSICAL_DISK_TEMPERATURE_LAST_KNOWN_CLASS; + } if (disk.wearout < 20) return 'text-red-600 dark:text-red-400'; if (disk.wearout < 50) return 'text-amber-600 dark:text-amber-400'; return 'text-green-600 dark:text-green-400'; diff --git a/frontend-modern/src/features/storageBackups/diskTemperaturePresentation.ts b/frontend-modern/src/features/storageBackups/diskTemperaturePresentation.ts index b4571083ea..9051f47bf8 100644 --- a/frontend-modern/src/features/storageBackups/diskTemperaturePresentation.ts +++ b/frontend-modern/src/features/storageBackups/diskTemperaturePresentation.ts @@ -13,13 +13,17 @@ import { formatTemperature } from '@/utils/temperature'; export const PHYSICAL_DISK_TEMPERATURE_LAST_KNOWN_CLASS = 'text-muted underline decoration-dotted underline-offset-2 cursor-help'; +export type PhysicalDiskFreshness = 'fresh' | 'stale' | 'unknown'; + // Normalization may keep the last known temperature when the current // observation is not available, such as a disk in standby or a host agent that -// stopped reporting. The value is a current reading only when its collection -// state is available, or when the source predates collection state. +// stopped reporting. The value is a current reading only when its source is +// not stale and its collection state is available (or absent for older sources). export function isPhysicalDiskTemperatureCurrent( collection: PhysicalDiskCollectionStatus | null | undefined, + freshness?: PhysicalDiskFreshness, ): boolean { + if (freshness === 'stale') return false; const state = collection?.temperature?.state; return !state || state === 'available'; } @@ -41,15 +45,23 @@ export interface PhysicalDiskTemperaturePresentation { export function getPhysicalDiskTemperaturePresentation(disk: { temperature: number; collection?: PhysicalDiskCollectionStatus | null; + freshness?: PhysicalDiskFreshness; + freshnessReason?: string; }): PhysicalDiskTemperaturePresentation | null { if (!Number.isFinite(disk.temperature) || disk.temperature <= 0) return null; - const current = isPhysicalDiskTemperatureCurrent(disk.collection); + const fieldUnavailable = !isPhysicalDiskTemperatureCurrent(disk.collection); + const current = !fieldUnavailable && disk.freshness !== 'stale'; + const staleReason = disk.freshnessReason?.trim(); return { label: formatTemperature(disk.temperature), current, title: current ? undefined - : getPhysicalDiskLastKnownTemperatureTitle(disk.collection?.temperature), + : fieldUnavailable + ? getPhysicalDiskLastKnownTemperatureTitle(disk.collection?.temperature) + : staleReason + ? `Last known reading, not current: ${staleReason}` + : 'Last known reading, not current: reporting source has not updated recently', }; } @@ -60,12 +72,16 @@ export function getPhysicalDiskTemperaturePresentation(disk: { // reading is not current, and null thresholds mean disk temperature alerting // is off for the disk, so neither is ever hot. Disk risk never carries heat. export function isPhysicalDiskRunningHot( - disk: { temperature: number; collection?: PhysicalDiskCollectionStatus | null }, + disk: { + temperature: number; + collection?: PhysicalDiskCollectionStatus | null; + freshness?: PhysicalDiskFreshness; + }, thresholds: MetricDisplayThresholds | null, ): boolean { if (!thresholds || !(thresholds.critical > 0)) return false; if (!Number.isFinite(disk.temperature) || disk.temperature <= 0) return false; - if (!isPhysicalDiskTemperatureCurrent(disk.collection)) return false; + if (!isPhysicalDiskTemperatureCurrent(disk.collection, disk.freshness)) return false; return disk.temperature >= thresholds.critical; } diff --git a/frontend-modern/src/features/storageBackups/storagePoolDetailPresentation.ts b/frontend-modern/src/features/storageBackups/storagePoolDetailPresentation.ts index d2f03936eb..762607a81c 100644 --- a/frontend-modern/src/features/storageBackups/storagePoolDetailPresentation.ts +++ b/frontend-modern/src/features/storageBackups/storagePoolDetailPresentation.ts @@ -1,5 +1,7 @@ import type { HistoryTimeRange, ResourceType as HistoryChartResourceType } from '@/api/charts'; import { + extractPhysicalDiskFreshness, + getPhysicalDiskStaleDetail, getPhysicalDiskTemperaturePresentation, type PhysicalDiskAlertResourceIdResolver, } from '@/features/storageBackups/diskPresentation'; @@ -317,11 +319,16 @@ const readDiskTemperature = (disk: Resource): number => { return typeof physicalDisk.temperature === 'number' ? physicalDisk.temperature : 0; }; -const readDiskTemperatureLastKnownTitle = (disk: Resource): string | undefined => - getPhysicalDiskTemperaturePresentation({ +const readDiskTemperatureLastKnownTitle = (disk: Resource): string | undefined => { + const freshness = extractPhysicalDiskFreshness(disk); + return getPhysicalDiskTemperaturePresentation({ temperature: readDiskTemperature(disk), collection: readPhysicalDisk(disk).collection, + freshness: freshness.freshness, + freshnessReason: + freshness.freshness === 'stale' ? getPhysicalDiskStaleDetail(freshness) : undefined, })?.title; +}; const readDiskType = (disk: Resource): string => { const physicalDisk = readPhysicalDisk(disk);