Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Converge platform byte-size fallbacks

rcourtman448721fec09f
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index b010266b2d..9e771aa50a 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -2609,6 +2609,12 @@ canonical empty-cell marker behavior for dense platform table cells. Docker /
Podman hosts, Kubernetes nodes, Proxmox Mail Gateway instances, Standalone
machines, and TrueNAS systems must compose that helper instead of declaring
local `formatUptime` helpers for the same days/hours/minutes fallback.
+Platform table byte-size formatting follows the same rule.
+`formatPlatformTableBytesValue` owns the repeated positive-byte formatting plus
+canonical empty-cell marker behavior for dense platform table cells. Docker /
+Podman native table helpers, Kubernetes node capacity cells, and TrueNAS
+system/VM byte cells must compose that helper instead of declaring local
+`formatBytes` wrappers or reimplementing byte-unit precision in table files.
Platform table metric fallback rendering is also shared.
`PlatformTableMetricFallback` owns the centered muted empty marker used in
metric bar cells plus optional caller-owned fallback label/title text, and
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 6525f46da4..cd3cfe638d 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -244,6 +244,12 @@ unified-resource consumers own which uptime field is displayed, but platform
tables, including Standalone machines, must use
`formatPlatformTableUptimeValue` instead of recreating local days/hours/minutes
`formatUptime` helpers for dense table cells.
+Platform byte-size table cells follow that boundary too: unified-resource
+consumers own whether a capacity, memory, disk, or requested-size field is the
+right source-specific value, while dense platform table cells must use
+`formatPlatformTableBytesValue` for positive byte formatting and unknown /
+non-positive empty-cell markers instead of carrying table-local `formatBytes`
+wrappers.
Metric bar fallbacks follow that split as well: unified-resource consumers own
which CPU or memory value is selected, plus any source-specific fallback reason
such as outdated standalone agent telemetry, while platform tables must use
diff --git a/frontend-modern/scripts/shared-template-registry.json b/frontend-modern/scripts/shared-template-registry.json
index 59cb10f20c..7a17091405 100644
--- a/frontend-modern/scripts/shared-template-registry.json
+++ b/frontend-modern/scripts/shared-template-registry.json
@@ -1336,6 +1336,44 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "platform-table-byte-value-fallback",
+ "category": "platform-table-text-value",
+ "summary": "Platform tables must use the shared byte-size fallback helper for positive byte formatting and canonical empty-cell markers instead of recreating local formatBytes wrappers.",
+ "canonical": {
+ "path": "src/features/platformPage/sharedPlatformPage.tsx",
+ "export": "formatPlatformTableBytesValue"
+ },
+ "requiredConsumers": [
+ { "path": "src/features/docker/DockerNativeTableShared.tsx" },
+ { "path": "src/features/kubernetes/KubernetesNodesTable.tsx" },
+ { "path": "src/features/truenas/TrueNASSystemsTable.tsx" },
+ { "path": "src/features/truenas/TrueNASVirtualMachinesTable.tsx" }
+ ],
+ "forbiddenPatterns": [
+ {
+ "path": "src/features/docker/DockerNativeTableShared.tsx",
+ "patterns": ["formatBytes(value)"]
+ },
+ {
+ "path": "src/features/kubernetes/KubernetesNodesTable.tsx",
+ "patterns": ["const formatBytes", "value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2)"]
+ },
+ {
+ "path": "src/features/truenas/TrueNASSystemsTable.tsx",
+ "patterns": ["const formatBytes", "value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2)"]
+ },
+ {
+ "path": "src/features/truenas/TrueNASVirtualMachinesTable.tsx",
+ "patterns": ["const formatBytes", "value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2)"]
+ }
+ ],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/features/platformPage/__tests__/sharedPlatformPage.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
{
"id": "platform-table-metric-fallback",
"category": "platform-table-metric",
@@ -1912,6 +1950,26 @@
"scripts/shared-template-audit.mjs"
]
},
+ {
+ "id": "platform-table-local-bytes-helper",
+ "category": "platform-table-text-value",
+ "summary": "Platform tables must not recreate local formatBytes wrappers for positive byte-size empty-cell fallback.",
+ "canonical": {
+ "path": "src/features/platformPage/sharedPlatformPage.tsx",
+ "export": "formatPlatformTableBytesValue"
+ },
+ "scopes": ["src/features/docker", "src/features/kubernetes", "src/features/truenas"],
+ "extensions": [".tsx"],
+ "allPatterns": ["const formatBytes", "value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2)"],
+ "legacyReason": "Retired migration debt. Platform table byte-size cells must use formatPlatformTableBytesValue for shared positive-byte formatting and empty-cell markers.",
+ "allowedPaths": [],
+ "ignoredPaths": [],
+ "proof": [
+ "src/components/shared/SharedPrimitives.guardrails.test.ts",
+ "src/features/platformPage/__tests__/sharedPlatformPage.test.ts",
+ "scripts/shared-template-audit.mjs"
+ ]
+ },
{
"id": "platform-table-local-metric-fallback-helper",
"category": "platform-table-metric",
diff --git a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
index 5ccf704789..f3c0db660d 100644
--- a/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
+++ b/frontend-modern/src/components/shared/SharedPrimitives.guardrails.test.ts
@@ -150,6 +150,7 @@ import guestRowStateSource from '@/components/Workloads/useGuestRowState.ts?raw'
import workloadSelectionStateSource from '@/components/Workloads/useWorkloadSelectionState.ts?raw';
import dockerContainersTableSource from '@/features/docker/DockerContainersTable.tsx?raw';
import dockerHostsTableSource from '@/features/docker/DockerHostsTable.tsx?raw';
+import dockerNativeTableSharedSource from '@/features/docker/DockerNativeTableShared.tsx?raw';
import kubernetesAutoscalingTableSource from '@/features/kubernetes/KubernetesAutoscalingTable.tsx?raw';
import kubernetesClustersTableSource from '@/features/kubernetes/KubernetesClustersTable.tsx?raw';
import kubernetesConfigTableSource from '@/features/kubernetes/KubernetesConfigTable.tsx?raw';
@@ -3664,6 +3665,95 @@ describe('shared primitive guardrails', () => {
}
});
+ it('keeps platform table byte-size fallbacks on the shared helper', () => {
+ const registry = JSON.parse(sharedTemplateRegistrySource) as {
+ rules?: Array<{
+ id: string;
+ canonical?: { path?: string; export?: string };
+ requiredConsumers?: Array<{ path?: string }>;
+ forbiddenPatterns?: Array<{ path?: string; patterns?: string[] }>;
+ }>;
+ patternGuards?: Array<{
+ id: string;
+ canonical?: { path?: string; export?: string };
+ allPatterns?: string[];
+ scopes?: string[];
+ allowedPaths?: string[];
+ ignoredPaths?: string[];
+ }>;
+ };
+ const registeredRule = registry.rules?.find(
+ (rule) => rule.id === 'platform-table-byte-value-fallback',
+ );
+ const localHelperGuard = registry.patternGuards?.find(
+ (guard) => guard.id === 'platform-table-local-bytes-helper',
+ );
+ const platformByteValueConsumers: Array<[string, string]> = [
+ ['src/features/docker/DockerNativeTableShared.tsx', dockerNativeTableSharedSource],
+ ['src/features/kubernetes/KubernetesNodesTable.tsx', kubernetesNodesTableSource],
+ ['src/features/truenas/TrueNASSystemsTable.tsx', truenasSystemsTableSource],
+ ['src/features/truenas/TrueNASVirtualMachinesTable.tsx', truenasVirtualMachinesTableSource],
+ ];
+ const platformByteValueConsumerPaths = platformByteValueConsumers.map(([path]) => path);
+ const localFormatBytesHelperPatterns = [
+ 'const formatBytes',
+ 'value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2)',
+ ];
+
+ expect(registeredRule?.canonical?.path).toBe(
+ 'src/features/platformPage/sharedPlatformPage.tsx',
+ );
+ expect(registeredRule?.canonical?.export).toBe('formatPlatformTableBytesValue');
+ expect(registeredRule?.requiredConsumers?.map((consumer) => consumer.path)).toEqual(
+ platformByteValueConsumerPaths,
+ );
+ expect(registeredRule?.forbiddenPatterns).toEqual([
+ {
+ path: 'src/features/docker/DockerNativeTableShared.tsx',
+ patterns: ['formatBytes(value)'],
+ },
+ {
+ path: 'src/features/kubernetes/KubernetesNodesTable.tsx',
+ patterns: localFormatBytesHelperPatterns,
+ },
+ {
+ path: 'src/features/truenas/TrueNASSystemsTable.tsx',
+ patterns: localFormatBytesHelperPatterns,
+ },
+ {
+ path: 'src/features/truenas/TrueNASVirtualMachinesTable.tsx',
+ patterns: localFormatBytesHelperPatterns,
+ },
+ ]);
+ expect(localHelperGuard?.canonical?.path).toBe(
+ 'src/features/platformPage/sharedPlatformPage.tsx',
+ );
+ expect(localHelperGuard?.canonical?.export).toBe('formatPlatformTableBytesValue');
+ expect(localHelperGuard?.allPatterns).toEqual(localFormatBytesHelperPatterns);
+ expect(localHelperGuard?.scopes).toEqual([
+ 'src/features/docker',
+ 'src/features/kubernetes',
+ 'src/features/truenas',
+ ]);
+ expect(localHelperGuard?.allowedPaths ?? []).toHaveLength(0);
+ expect(localHelperGuard?.ignoredPaths ?? []).toHaveLength(0);
+
+ expect(sharedPlatformPageSource).toContain('export const formatPlatformTableBytesValue');
+ expect(sharedPlatformPageSource).toContain('formatBytes(bytes)');
+
+ for (const [path, source] of platformByteValueConsumers) {
+ expect(source).toContain('formatPlatformTableBytesValue');
+ const forbiddenPatterns =
+ registeredRule?.forbiddenPatterns?.find((entry) => entry.path === path)?.patterns ?? [];
+ for (const pattern of forbiddenPatterns) {
+ expect(source).not.toContain(pattern);
+ }
+ }
+ expect(truenasVirtualMachinesTableSource).toContain(
+ "formatPlatformTableBytesValue(vm()?.memoryBytes, '-')",
+ );
+ });
+
it('keeps platform table compact value summaries on the shared helper', () => {
const registry = JSON.parse(sharedTemplateRegistrySource) as {
rules?: Array<{
diff --git a/frontend-modern/src/features/docker/DockerNativeTableShared.tsx b/frontend-modern/src/features/docker/DockerNativeTableShared.tsx
index 8c1dd8a8e5..8ed14a359f 100644
--- a/frontend-modern/src/features/docker/DockerNativeTableShared.tsx
+++ b/frontend-modern/src/features/docker/DockerNativeTableShared.tsx
@@ -1,10 +1,12 @@
import { type Component, type JSX } from 'solid-js';
import { StatusDot } from '@/components/shared/StatusDot';
import { TableCell } from '@/components/shared/Table';
-import { formatBytes } from '@/utils/format';
import { getSimpleStatusIndicator, type StatusIndicator } from '@/utils/status';
import { asTrimmedString } from '@/utils/stringUtils';
-import { getPlatformTableCellClassForKind } from '@/features/platformPage/sharedPlatformPage';
+import {
+ formatPlatformTableBytesValue,
+ getPlatformTableCellClassForKind,
+} from '@/features/platformPage/sharedPlatformPage';
import type { Resource } from '@/types/resource';
import type { DockerResourceStatusFilter } from './dockerPageModel';
@@ -25,7 +27,7 @@ export const dockerNumberValue = (value: number | undefined): JSX.Element =>
typeof value === 'number' ? <span class="tabular-nums">{value}</span> : <span>—</span>;
export const dockerByteValue = (value: number | undefined): string =>
- typeof value === 'number' && value > 0 ? formatBytes(value) : '—';
+ formatPlatformTableBytesValue(value);
export const dockerCpuValue = (nanoCpus: number | undefined): string => {
if (typeof nanoCpus !== 'number' || nanoCpus <= 0) return '—';
diff --git a/frontend-modern/src/features/kubernetes/KubernetesNodesTable.tsx b/frontend-modern/src/features/kubernetes/KubernetesNodesTable.tsx
index 9e4cef3226..1d41f1a547 100644
--- a/frontend-modern/src/features/kubernetes/KubernetesNodesTable.tsx
+++ b/frontend-modern/src/features/kubernetes/KubernetesNodesTable.tsx
@@ -12,6 +12,7 @@ import {
PlatformTableShell,
PlatformTableToolbar,
createPlatformTableFilterState,
+ formatPlatformTableBytesValue,
formatPlatformTableTextValue,
formatPlatformTableUptimeValue,
getPlatformTableFiniteMetric,
@@ -46,18 +47,6 @@ import {
// the Overview stack reads as one consistent surface alongside the
// Docker / Proxmox / vSphere host tables.
-const formatBytes = (bytes: number | undefined): string => {
- if (!bytes || bytes <= 0) return '—';
- const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
- let value = bytes;
- let unitIdx = 0;
- while (value >= 1024 && unitIdx < units.length - 1) {
- value /= 1024;
- unitIdx += 1;
- }
- return `${value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2)} ${units[unitIdx]}`;
-};
-
const formatRoles = (roles: string[] | undefined): string => {
if (!roles || roles.length === 0) return '—';
return roles.map((role) => role.replace('node-role.kubernetes.io/', '')).join(', ');
@@ -188,7 +177,9 @@ export const KubernetesNodesTable: Component<{
const pods = meta()?.capacityPods;
const parts: string[] = [];
if (typeof cores === 'number' && cores > 0) parts.push(`${cores} cores`);
- if (typeof mem === 'number' && mem > 0) parts.push(formatBytes(mem));
+ if (typeof mem === 'number' && mem > 0) {
+ parts.push(formatPlatformTableBytesValue(mem));
+ }
if (typeof pods === 'number' && pods > 0) parts.push(`${pods} pods`);
return parts.join(' / ') || '—';
};
@@ -200,8 +191,7 @@ export const KubernetesNodesTable: Component<{
const indicator = () => mapKubernetesNodeStatus(node);
const metricsKey = () => buildMetricKeyForUnifiedResource(node);
const cpuPercent = () => getPlatformTableFiniteMetric(node.cpu?.current);
- const memoryTotal = () =>
- getPlatformTableFiniteMetric(node.memory?.total) ?? 0;
+ const memoryTotal = () => getPlatformTableFiniteMetric(node.memory?.total) ?? 0;
const memoryUsed = () => getPlatformTableFiniteMetric(node.memory?.used) ?? 0;
const memoryPercentOnly = () =>
memoryTotal() > 0
diff --git a/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts b/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts
index 7c8e56e634..2f6aac40b3 100644
--- a/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts
+++ b/frontend-modern/src/features/platformPage/__tests__/sharedPlatformPage.test.ts
@@ -5,6 +5,7 @@ import type { Resource } from '@/types/resource';
import {
PlatformTableMetricFallback,
createPlatformTableFilterState,
+ formatPlatformTableBytesValue,
formatPlatformTableTitleCaseValue,
formatPlatformTableUptimeValue,
filterPlatformResources,
@@ -288,6 +289,19 @@ describe('formatPlatformTableUptimeValue', () => {
});
});
+describe('formatPlatformTableBytesValue', () => {
+ it('formats positive byte values and preserves table-cell empty markers', () => {
+ expect(formatPlatformTableBytesValue(undefined)).toBe('—');
+ expect(formatPlatformTableBytesValue(0)).toBe('—');
+ expect(formatPlatformTableBytesValue(Number.NaN)).toBe('—');
+ expect(formatPlatformTableBytesValue(Number.POSITIVE_INFINITY)).toBe('—');
+ expect(formatPlatformTableBytesValue(undefined, '-')).toBe('-');
+ expect(formatPlatformTableBytesValue(1024)).toBe('1.00 KB');
+ expect(formatPlatformTableBytesValue(1_536)).toBe('1.50 KB');
+ expect(formatPlatformTableBytesValue(5 * 1024 * 1024 * 1024)).toBe('5.00 GB');
+ });
+});
+
describe('getPlatformTableFiniteMetric', () => {
it('normalizes platform table metrics to finite numeric values only', () => {
expect(getPlatformTableFiniteMetric(42)).toBe(42);
diff --git a/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx b/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
index 47302d5631..9d9db1ee04 100644
--- a/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
+++ b/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
@@ -12,7 +12,7 @@ import { TableCardHeader } from '@/components/shared/TableCardHeader';
import { useBreakpoint } from '@/hooks/useBreakpoint';
import { UnifiedResourceTable } from '@/components/Infrastructure/UnifiedResourceTable';
import type { Resource } from '@/types/resource';
-import { formatUptime } from '@/utils/format';
+import { formatBytes, formatUptime } from '@/utils/format';
import { asTrimmedString } from '@/utils/stringUtils';
import { formatVmwareClusterServices } from '@/utils/vmwareDisplay';
import { getPlatformColumnAlign, type PlatformTableColumnKind } from './columnAlignment';
@@ -195,6 +195,16 @@ export const formatPlatformTableUptimeValue = (
return formatUptime(seconds, true);
};
+export const formatPlatformTableBytesValue = (
+ bytes: number | undefined,
+ emptyText = '—',
+): string => {
+ if (typeof bytes !== 'number' || !Number.isFinite(bytes) || bytes <= 0) {
+ return emptyText;
+ }
+ return formatBytes(bytes);
+};
+
export const getPlatformTableFiniteMetric = (value: number | undefined): number | undefined =>
typeof value === 'number' && Number.isFinite(value) ? value : undefined;
diff --git a/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx b/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx
index 70d44c596a..c8794eeb31 100644
--- a/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx
+++ b/frontend-modern/src/features/truenas/TrueNASSystemsTable.tsx
@@ -13,6 +13,7 @@ import {
PlatformTableEmptyState,
createPlatformTableFilterState,
filterPlatformResources,
+ formatPlatformTableBytesValue,
formatPlatformTableUptimeValue,
getPlatformTableFiniteMetric,
getPlatformTableCellClassForKind,
@@ -46,18 +47,6 @@ import type { Resource } from '@/types/resource';
// client-side from the same TrueNAS resource scope already fetched by
// the page (no extra API calls).
-const formatBytes = (bytes: number | undefined): string => {
- if (!bytes || bytes <= 0) return '—';
- const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
- let value = bytes;
- let unitIdx = 0;
- while (value >= 1024 && unitIdx < units.length - 1) {
- value /= 1024;
- unitIdx += 1;
- }
- return `${value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2)} ${units[unitIdx]}`;
-};
-
const formatPercent = (percent?: number): JSX.Element => {
if (typeof percent !== 'number' || Number.isNaN(percent))
return <span class="text-muted">—</span>;
@@ -219,7 +208,7 @@ export const TrueNASSystemsTable: Component<{
const storageFullLabel = () =>
typeof system.disk?.used === 'number' &&
typeof system.disk?.total === 'number'
- ? `${formatBytes(system.disk.used)} / ${formatBytes(system.disk.total)}`
+ ? `${formatPlatformTableBytesValue(system.disk.used)} / ${formatPlatformTableBytesValue(system.disk.total)}`
: formatPercent(storagePercent());
const c = () => countsBySystem().get(system.id) ?? EMPTY_COUNTS;
const uptimeLabel = () => formatPlatformTableUptimeValue(system.uptime);
@@ -234,8 +223,7 @@ export const TrueNASSystemsTable: Component<{
const cpuPercent = () => getPlatformTableFiniteMetric(system.cpu?.current);
const memoryTotal = () =>
getPlatformTableFiniteMetric(system.memory?.total) ?? 0;
- const memoryUsed = () =>
- getPlatformTableFiniteMetric(system.memory?.used) ?? 0;
+ const memoryUsed = () => getPlatformTableFiniteMetric(system.memory?.used) ?? 0;
const memoryPercentOnly = () =>
memoryTotal() > 0
? undefined
diff --git a/frontend-modern/src/features/truenas/TrueNASVirtualMachinesTable.tsx b/frontend-modern/src/features/truenas/TrueNASVirtualMachinesTable.tsx
index 89d06877e6..bc2cca9f3f 100644
--- a/frontend-modern/src/features/truenas/TrueNASVirtualMachinesTable.tsx
+++ b/frontend-modern/src/features/truenas/TrueNASVirtualMachinesTable.tsx
@@ -7,6 +7,7 @@ import {
PlatformTableEmptyState,
PlatformTableToolbar,
createPlatformTableFilterState,
+ formatPlatformTableBytesValue,
formatPlatformTableTitleCaseValue,
getPlatformTableCellClassForKind,
getPlatformTableHeadClassForKind,
@@ -36,18 +37,6 @@ const TRUENAS_VM_STATUS_OPTIONS: PlatformTableFilterOption<TrueNASVMStatusFilter
const vmMeta = (resource: Resource): ResourceTrueNASVMMeta | undefined => resource.truenas?.vm;
-const formatBytes = (bytes: number | undefined): string => {
- if (!bytes || bytes <= 0) return '-';
- const units = ['B', 'KB', 'MB', 'GB', 'TB'];
- let value = bytes;
- let unitIdx = 0;
- while (value >= 1024 && unitIdx < units.length - 1) {
- value /= 1024;
- unitIdx += 1;
- }
- return `${value.toFixed(value >= 100 ? 0 : value >= 10 ? 1 : 2)} ${units[unitIdx]}`;
-};
-
const formatCPU = (vm: ResourceTrueNASVMMeta | undefined): string => {
const vcpus = vm?.vcpus;
if (typeof vcpus === 'number' && Number.isFinite(vcpus) && vcpus > 0) return `${vcpus} vCPU`;
@@ -254,7 +243,7 @@ export const TrueNASVirtualMachinesTable: Component<{
<TableCell
class={`${getPlatformTableCellClassForKind('numeric-value')} hidden text-base-content sm:table-cell`}
>
- {formatBytes(vm()?.memoryBytes)}
+ {formatPlatformTableBytesValue(vm()?.memoryBytes, '-')}
</TableCell>
<TableCell
class={`${getPlatformTableCellClassForKind('text')} hidden text-base-content md:table-cell`}