Defer stale GuestDrawer metrics and preserve static disk capacity

On current main after #5369, GuestDrawer renders the amber Readings are
stale notice for workloads whose primary provider poll is stale, but
still passed live currentMetrics into inline History charts (labelling
stale snapshot readings as current) and displayed stale used bytes in
guest-drawer-facts. Meanwhile GuestDrawerOverview.diskFact() omitted
allocated disk size whenever deferredMetrics.disk was active (unlike
memoryFact(), which keeps total RAM).

Defer stale primary-provider metrics in GuestDrawer.tsx into
historyDeferredMetrics (keeping live linked-agent disk readings current
when disksFromAgent is true) with concise last-known messaging so inline
History labels them last known and clears reactively on recovery, and
update GuestDrawerOverview.diskFact() to preserve static total disk
capacity (<total> disk) for retained readings while omitting disk when
unavailable. Leaves human-claimed guestDrawerModel.ts and
.bundlesize.json untouched.

Contract-Neutral: frontend-only GuestDrawer and GuestDrawerOverview presentation update over existing telemetryStale, deferredMetrics, and disk.total fields; no API, schema, route, or backend contract changes.
Change-source: pulse-maintainer
This commit is contained in:
pulse-triage[bot]
2026-11-28 09:46:20 +00:00
parent 6f708f829e
commit 13e38a9f3d
5 changed files with 201 additions and 13 deletions

View File

@@ -0,0 +1,39 @@
{
"version": 1,
"base_sha": "6f708f829eb3ccca653a2b2a8da5910d21de3c8a",
"verified_at": "2026-11-28T09:45:56Z",
"result": "passed",
"changed_paths": [
"frontend-modern/src/components/Workloads/GuestDrawer.tsx",
"frontend-modern/src/components/Workloads/GuestDrawerOverview.tsx"
],
"content_sha256": {
"frontend-modern/src/components/Workloads/GuestDrawer.tsx": "7f16c103f434422d698cc2c60a84094e89451b254529937c77b255dac5c6f903",
"frontend-modern/src/components/Workloads/GuestDrawerOverview.tsx": "adf909f6ab9dc962af3a0fd6ce8d34e8d96ac72c600852ea6452788d57194060"
},
"routes": [
"/proxmox/overview",
"/vmware/overview"
],
"viewports": [
{
"width": 1440,
"height": 940
},
{
"width": 360,
"height": 820
}
],
"states": [
"Paired production Vite builds of unpatched base (9ab10347ba/6f708f829e) and patched HEAD served locally via pulse-worker-browser over identical synthetic REST and WebSocket payloads in desktop Chromium (1440x940 light theme, en-GB, UTC) and touch phone WebKit (360x820 dark theme, en-GB, UTC).",
"/proxmox/overview stale db-primary GuestDrawer: inline History defers all 7 platform metrics (cpu, memory, disk, netin, netout, diskread, diskwrite) as last known with concise notes instead of current, and guest-drawer-facts preserves static capacities 8.00 GB RAM and 100 GB disk without showing stale used bytes (vs 6.00 GB of 8.00 GB RAM and 48.0 GB of 100 GB disk on unpatched base).",
"/proxmox/overview live WebSocket rawData recovery on db-primary without page reload: clears Readings are stale notice, restores Running 2 / Attention 0 and green indicator, restores all 7 History metrics to current, and restores 6.00 GB of 8.00 GB RAM and 48.0 GB of 100 GB disk in guest-drawer-facts.",
"/vmware/overview stale billing-api-vm GuestDrawer: inline History defers cpu, memory, and disk as last known while leaving unavailable network/disk I/O unflagged, and guest-drawer-facts preserves static 8.00 GB RAM and 80.0 GB disk beside 10.20.0.41 (vs 4.40 GB of 8.00 GB RAM and 40.0 GB of 80.0 GB disk on unpatched base).",
"Zero console errors, zero page errors, zero HTTP >= 400 responses, and 0px horizontal overflow across all captured desktop and phone states; all 10 paired before/after PNGs were visually inspected."
],
"interactions": [
"Loaded /proxmox/overview on desktop Chromium (1440x940 light) and touch WebKit phone (360x820 dark), clicked stale workload db-primary to open GuestDrawer, verified deferred last-known History metrics and static RAM/disk facts, scrolled facts into view, and sent live WebSocket rawData recovery without reload to verify reactive restoration.",
"Navigated to /vmware/overview on desktop Chromium and touch WebKit phone, clicked stale VM billing-api-vm to open GuestDrawer, and verified deferred last-known History metrics and static 8.00 GB RAM and 80.0 GB disk facts."
]
}

View File

@@ -1294,6 +1294,36 @@ describe('GuestDrawer', () => {
));
expect(screen.getByTestId('guest-drawer-facts')).not.toHaveTextContent('RAM');
});
it('states only the disk size for a retained reading and omits it when unavailable', () => {
const GiB = 1024 ** 3;
solidRender(() => (
<GuestDrawer
guest={makeGuest({
type: 'qemu',
disk: { total: 100 * GiB, used: 25 * GiB, free: 75 * GiB, usage: 25 },
diskStatusReason: 'prev-vm-locked',
})}
onClose={vi.fn()}
/>
));
const retainedFacts = screen.getByTestId('guest-drawer-facts');
expect(retainedFacts).toHaveTextContent('100 GB disk');
expect(retainedFacts).not.toHaveTextContent(/of 100 GB disk/);
cleanup();
solidRender(() => (
<GuestDrawer
guest={makeGuest({
type: 'qemu',
disk: { total: 100 * GiB, used: 25 * GiB, free: 75 * GiB, usage: 25 },
diskStatusReason: 'agent-not-running',
})}
onClose={vi.fn()}
/>
));
expect(screen.getByTestId('guest-drawer-facts')).not.toHaveTextContent('disk');
});
});
// ── Tags card ──

View File

@@ -11,6 +11,7 @@ import {
getGuestDrawerGuestReadPrecaution,
getGuestDrawerCurrentMetrics,
getGuestDrawerDeferredMetrics,
type GuestDrawerHistoryDeferredMetric,
type GuestDrawerProps,
} from './guestDrawerModel';
import { getCanonicalWorkloadId } from '@/utils/workloads';
@@ -50,8 +51,28 @@ const GuestDrawerContent: Component<GuestDrawerProps> = (props) => {
workloadActionAgentTitle,
} = useGuestDrawerState(props);
const headingId = () => `guest-drawer-heading-${guestId()}`;
const historyCurrentMetrics = createMemo(() => getGuestDrawerCurrentMetrics(props.guest));
const historyDeferredMetrics = createMemo(() => getGuestDrawerDeferredMetrics(props.guest));
const baseCurrentMetrics = createMemo(() => getGuestDrawerCurrentMetrics(props.guest));
const historyCurrentMetrics = createMemo(() => {
const current = baseCurrentMetrics();
if (!props.guest.telemetryStale) return current;
return props.guest.disksFromAgent && current.disk !== undefined ? { disk: current.disk } : {};
});
const historyDeferredMetrics = createMemo(() => {
const deferred = getGuestDrawerDeferredMetrics(props.guest);
const stale = props.guest.telemetryStale;
if (!stale) return deferred;
const staleMessage = stale.age
? `Last value received ${stale.age} ago.`
: 'Last value received before polling stopped.';
const next: Record<string, GuestDrawerHistoryDeferredMetric> = { ...deferred };
for (const [metric, lastKnownValue] of Object.entries(baseCurrentMetrics())) {
if (metric === 'disk' && props.guest.disksFromAgent) continue;
if (!next[metric] && lastKnownValue !== undefined) {
next[metric] = { lastKnownValue, message: staleMessage };
}
}
return next;
});
const guestReadPrecaution = createMemo(() => getGuestDrawerGuestReadPrecaution(props.guest));

View File

@@ -408,19 +408,25 @@ export function GuestDrawerOverview(props: GuestDrawerOverviewProps) {
};
const diskFact = () => {
const disk = props.guest.disk;
const hasReading =
typeof props.currentMetrics?.disk === 'number' ||
typeof props.deferredMetrics?.disk?.lastKnownValue === 'number';
if (
!disk ||
!hasReading ||
typeof disk.total !== 'number' ||
!Number.isFinite(disk.total) ||
disk.total <= 0 ||
typeof disk.used !== 'number' ||
!Number.isFinite(disk.used) ||
disk.used < 0 ||
typeof props.currentMetrics?.disk !== 'number'
disk.total <= 0
) {
return '';
}
return `${formatBytes(disk.used ?? 0)} of ${formatBytes(disk.total ?? 0)} disk`;
// A retained or stale reading is qualified in the chart; here it states
// the size only, so no used amount reads as current.
if (props.deferredMetrics?.disk) return `${formatBytes(disk.total)} disk`;
if (typeof disk.used !== 'number' || !Number.isFinite(disk.used) || disk.used < 0) {
return '';
}
return `${formatBytes(disk.used)} of ${formatBytes(disk.total)} disk`;
};
const chartAlerts = createMemo(() =>
getDrawerChartAlerts(props.alerts, GUEST_DRAWER_CHARTED_METRICS),

View File

@@ -1,11 +1,28 @@
import { cleanup, render, screen } from '@solidjs/testing-library';
import { cleanup, render, screen, waitFor } from '@solidjs/testing-library';
import { createSignal } from 'solid-js';
import { afterEach, describe, expect, it } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { GuestDrawer } from '../GuestDrawer';
import { NodeGroupHeader } from '@/components/shared/NodeGroupHeader';
import { resetCreateNonSuspendingQueryCacheForTest } from '@/hooks/createNonSuspendingQuery';
import type { Node } from '@/types/api';
import type { WorkloadGuest } from '@/types/workloads';
vi.mock('@/api/charts', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/api/charts')>();
return {
...actual,
ChartsAPI: {
...actual.ChartsAPI,
getMetricsHistory: vi.fn().mockResolvedValue({
resourceType: 'vm',
resourceId: 'prod-pve-stale-101',
range: '24h',
metrics: {},
}),
},
};
});
const makeGuest = (overrides: Partial<WorkloadGuest> = {}): WorkloadGuest => ({
id: 'prod-pve-stale-101',
name: 'db-primary',
@@ -16,7 +33,17 @@ const makeGuest = (overrides: Partial<WorkloadGuest> = {}): WorkloadGuest => ({
status: 'running',
cpu: 0.42,
cpus: 4,
memory: { total: 8 * 1024 ** 3, used: 6 * 1024 ** 3, free: 2 * 1024 ** 3, usage: 75 },
memory: {
total: 8 * 1024 ** 3,
used: 6 * 1024 ** 3,
free: 2 * 1024 ** 3,
usage: 75,
observation: {
state: 'current',
source: 'guest-agent-meminfo',
observedAt: new Date().toISOString(),
},
},
disk: { total: 100 * 1024 ** 3, used: 48 * 1024 ** 3, free: 52 * 1024 ** 3, usage: 48 },
networkIn: 120000,
networkOut: 85000,
@@ -53,10 +80,17 @@ const makeNode = (overrides: Partial<Node> = {}): Node => ({
...overrides,
});
afterEach(cleanup);
beforeEach(() => {
resetCreateNonSuspendingQueryCacheForTest();
});
afterEach(() => {
cleanup();
resetCreateNonSuspendingQueryCacheForTest();
});
describe('GuestDrawer and NodeGroupHeader stale telemetry presentation', () => {
it('shows stale warning header status and notice in GuestDrawer and clears reactively on recovery', () => {
it('shows stale warning header status, defers platform metrics with static capacities, and clears reactively on recovery', async () => {
const stale = {
label: 'Stale data',
age: '18m',
@@ -73,9 +107,67 @@ describe('GuestDrawer and NodeGroupHeader stale telemetry presentation', () => {
expect(notice).toHaveTextContent(stale.detail);
expect(screen.getByRole('img', { name: stale.detail })).toBeVisible();
const facts = screen.getByTestId('guest-drawer-facts');
expect(facts).toHaveTextContent('8.00 GB RAM');
expect(facts).not.toHaveTextContent('6.00 GB of 8.00 GB RAM');
expect(facts).toHaveTextContent('100 GB disk');
expect(facts).not.toHaveTextContent('48.0 GB of 100 GB disk');
await waitFor(() => {
const historyRegion = screen.getByTestId('guest-history-region');
const cpuDeferred = historyRegion.querySelector('[data-history-deferred="cpu"]');
expect(cpuDeferred).not.toBeNull();
expect(cpuDeferred).toHaveTextContent('Last value received 18m ago.');
expect(historyRegion.querySelector('[data-history-deferred="memory"]')).not.toBeNull();
expect(historyRegion.querySelector('[data-history-deferred="disk"]')).not.toBeNull();
expect(historyRegion.querySelector('[data-history-deferred="netin"]')).not.toBeNull();
expect(historyRegion.querySelector('[data-history-deferred="netout"]')).not.toBeNull();
expect(historyRegion.querySelector('[data-history-deferred="diskread"]')).not.toBeNull();
expect(historyRegion.querySelector('[data-history-deferred="diskwrite"]')).not.toBeNull();
});
setGuest(makeGuest({ telemetryStale: undefined }));
expect(screen.queryByTestId('guest-telemetry-stale-notice')).not.toBeInTheDocument();
expect(screen.getByRole('img', { name: 'Running' })).toBeVisible();
expect(facts).toHaveTextContent('6.00 GB of 8.00 GB RAM');
expect(facts).toHaveTextContent('48.0 GB of 100 GB disk');
await waitFor(() => {
const historyRegion = screen.getByTestId('guest-history-region');
expect(historyRegion.querySelector('[data-history-deferred="cpu"]')).toBeNull();
expect(historyRegion.querySelector('[data-history-deferred="memory"]')).toBeNull();
expect(historyRegion.querySelector('[data-history-deferred="disk"]')).toBeNull();
});
});
it('keeps fresh linked-agent disk live while deferring stale hypervisor metrics', async () => {
const stale = {
label: 'Stale data',
age: '18m',
detail: 'No Proxmox report for 18m. Showing the last values received.',
};
render(() => (
<GuestDrawer
guest={makeGuest({
telemetryStale: stale,
disksFromAgent: true,
agentStale: false,
agentKind: 'pulse',
})}
onClose={() => {}}
/>
));
const facts = screen.getByTestId('guest-drawer-facts');
expect(facts).toHaveTextContent('8.00 GB RAM');
expect(facts).not.toHaveTextContent('6.00 GB of 8.00 GB RAM');
expect(facts).toHaveTextContent('48.0 GB of 100 GB disk');
await waitFor(() => {
const historyRegion = screen.getByTestId('guest-history-region');
expect(historyRegion.querySelector('[data-history-deferred="cpu"]')).not.toBeNull();
expect(historyRegion.querySelector('[data-history-deferred="memory"]')).not.toBeNull();
expect(historyRegion.querySelector('[data-history-deferred="disk"]')).toBeNull();
});
});
it('shows a Stale data badge on NodeGroupHeader when node connection health is stale', () => {