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.

Keep PBS backup counts with their exact reader and datastore

pulse-triage[bot]0041d56afc6d
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index e680239989..f6c90af88a 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -20,6 +20,25 @@
## Purpose
+### PBS server counts belong to the exact backup reader and datastore
+
+The existing Backups server count matches `PBSBackup.instance` to the resource's
+configured connection `name` and matches the exact datastore name. Service IDs
+(`pbs-` plus the connection name), hostnames and display labels are not backup
+reader aliases; an empty tuple must not borrow another connection's inventory.
+Both identities retain their positions, punctuation and case without a joined
+separator key. Counts still include all admitted inventory entries and namespaces,
+not only completed or verified points. Loading/unavailable inventory remains
+non-numeric; independently observed capacity and reachability remain unchanged.
+
+Normal-suite `backupServerCountEvidence.test.tsx` consumes parsed inventory and
+checks prefix-alias and delimiter collisions, case, namespaces, valid zero and
+existing all-entry semantics. Its real table consumer checks ordinary polling,
+failed reads, retry and detail continuity without extra requests. Desktop and
+narrow browser proof exercises the same producer through the inventory consumer
+with native interactions and inspected pixels. No API, provider, guest, polling,
+auth, resource identity or protection-policy change, nor installed recovery claim.
+
### Coverage duration requires observed task timing
The existing Coverage task disclosure derives a duration only from positive,
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 16885690ae..dd54ea71ab 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -21,6 +21,25 @@
## Purpose
+### PBS server counts belong to the exact backup reader and datastore
+
+The existing Backups server count matches `PBSBackup.instance` to the resource's
+configured connection `name` and matches the exact datastore name. Service IDs
+(`pbs-` plus the connection name), hostnames and display labels are not backup
+reader aliases; an empty tuple must not borrow another connection's inventory.
+Both identities retain their positions, punctuation and case without a joined
+separator key. Counts still include all admitted inventory entries and namespaces,
+not only completed or verified points. Loading/unavailable inventory remains
+non-numeric; independently observed capacity and reachability remain unchanged.
+
+Normal-suite `backupServerCountEvidence.test.tsx` consumes parsed inventory and
+checks prefix-alias and delimiter collisions, case, namespaces, valid zero and
+existing all-entry semantics. Its real table consumer checks ordinary polling,
+failed reads, retry and detail continuity without extra requests. Desktop and
+narrow browser proof exercises the same producer through the inventory consumer
+with native interactions and inspected pixels. No API, provider, guest, polling,
+auth, resource identity or protection-policy change, nor installed recovery claim.
+
### Coverage duration requires observed task timing
The existing Coverage task disclosure derives a duration only from positive,
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 343bf1d8f7..102a1d9d72 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -23,6 +23,25 @@ and sort the complete canonical change table while startup and ingestion wait.
## Purpose
+### PBS server counts belong to the exact backup reader and datastore
+
+The existing Backups server count matches `PBSBackup.instance` to the resource's
+configured connection `name` and matches the exact datastore name. Service IDs
+(`pbs-` plus the connection name), hostnames and display labels are not backup
+reader aliases; an empty tuple must not borrow another connection's inventory.
+Both identities retain their positions, punctuation and case without a joined
+separator key. Counts still include all admitted inventory entries and namespaces,
+not only completed or verified points. Loading/unavailable inventory remains
+non-numeric; independently observed capacity and reachability remain unchanged.
+
+Normal-suite `backupServerCountEvidence.test.tsx` consumes parsed inventory and
+checks prefix-alias and delimiter collisions, case, namespaces, valid zero and
+existing all-entry semantics. Its real table consumer checks ordinary polling,
+failed reads, retry and detail continuity without extra requests. Desktop and
+narrow browser proof exercises the same producer through the inventory consumer
+with native interactions and inspected pixels. No API, provider, guest, polling,
+auth, resource identity or protection-policy change, nor installed recovery claim.
+
### Coverage duration requires observed task timing
The existing Coverage task disclosure derives a duration only from positive,
diff --git a/frontend-modern/src/features/proxmox/ProxmoxBackupServersTable.tsx b/frontend-modern/src/features/proxmox/ProxmoxBackupServersTable.tsx
index 3825bb1f98..6b4a4c027e 100644
--- a/frontend-modern/src/features/proxmox/ProxmoxBackupServersTable.tsx
+++ b/frontend-modern/src/features/proxmox/ProxmoxBackupServersTable.tsx
@@ -72,11 +72,18 @@ interface BackupServerRow {
}
// Key by instance and datastore so multi-datastore servers get accurate counts.
-function buildBackupCounts(backups: readonly PBSBackup[]): Map<string, number> {
- const counts = new Map<string, number>();
+function buildBackupCounts(backups: readonly PBSBackup[]): Map<string, Map<string, number>> {
+ const counts = new Map<string, Map<string, number>>();
for (const backup of backups) {
- const key = `${backup.instance ?? ''}::${backup.datastore ?? ''}`;
- counts.set(key, (counts.get(key) ?? 0) + 1);
+ // Both fields are provider identities, not a delimiter-joined display key.
+ // An unattributed entry cannot establish a count for any named datastore.
+ if (!backup.instance || !backup.datastore) continue;
+ let datastores = counts.get(backup.instance);
+ if (!datastores) {
+ datastores = new Map();
+ counts.set(backup.instance, datastores);
+ }
+ datastores.set(backup.datastore, (datastores.get(backup.datastore) ?? 0) + 1);
}
return counts;
}
@@ -319,15 +326,12 @@ export function buildBackupServerRows(
): BackupServerRow[] {
const rows: BackupServerRow[] = [];
const counts = buildBackupCounts(backups);
- // PBS backups carry instance; resources may expose it under name or pbs.instanceId.
- const countFor = (server: Resource, datastoreName: string): number => {
- const ids = [server.name, server.pbs?.instanceId].filter(Boolean) as string[];
- for (const id of ids) {
- const n = counts.get(`${id}::${datastoreName}`);
- if (n !== undefined) return n;
- }
- return 0;
- };
+ // The PBS producer reports the configured connection name in both
+ // PBSBackup.instance and Resource.name. PBS.instanceId is a service identity
+ // ("pbs-" + that name), not another backup reader: using it as a fallback can
+ // borrow a different connection's backups when this one has none.
+ const countFor = (server: Resource, datastoreName: string): number =>
+ counts.get(server.name)?.get(datastoreName) ?? 0;
// `model().pbs` is scope-filtered (proxmox-pbs), which also catches PBS
// *datastore* storage resources (type 'storage', sources ['pbs']). This table
// is about the server, so keep only actual PBS server instances — otherwise a
diff --git a/frontend-modern/src/features/proxmox/__tests__/ProxmoxBackupsTable.test.tsx b/frontend-modern/src/features/proxmox/__tests__/ProxmoxBackupsTable.test.tsx
index ead159d16b..26fe7b840a 100644
--- a/frontend-modern/src/features/proxmox/__tests__/ProxmoxBackupsTable.test.tsx
+++ b/frontend-modern/src/features/proxmox/__tests__/ProxmoxBackupsTable.test.tsx
@@ -227,6 +227,19 @@ beforeEach(() => {
});
describe('ProxmoxBackupsTable', () => {
+ it('does not treat a runtime service identity as a second backup reader', () => {
+ // The actual producer uses Name=main, ID=pbs-main. A separate configured
+ // reader may itself be named pbs-main; its snapshots cannot fill main.
+ const emptyReader = {
+ ...pbsServerResource,
+ name: 'main',
+ pbs: { ...pbsServerResource.pbs!, instanceId: 'pbs-main' },
+ } as Resource;
+ const other = pbsPayload.data.backups;
+ expect(buildBackupServerRows([emptyReader], other)[0].backupCount).toBe(0);
+ expect(buildBackupServerRows([pbsServerResource], other)[0].backupCount).toBe(1);
+ });
+
it.each([
{ used: 9_500, usagePercent: 0, expected: '95.0%', tone: 'text-red-600' },
{ used: 8_000, usagePercent: 20, expected: '80.0%', tone: 'text-amber-600' },
diff --git a/frontend-modern/src/features/proxmox/__tests__/backupServerCountEvidence.test.tsx b/frontend-modern/src/features/proxmox/__tests__/backupServerCountEvidence.test.tsx
new file mode 100644
index 0000000000..85e68220d7
--- /dev/null
+++ b/frontend-modern/src/features/proxmox/__tests__/backupServerCountEvidence.test.tsx
@@ -0,0 +1,193 @@
+import { cleanup, fireEvent, render, screen, waitFor, within } from '@solidjs/testing-library';
+import { Route, Router } from '@solidjs/router';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { Resource } from '@/types/resource';
+import { resetCreateNonSuspendingQueryCacheForTest } from '@/hooks/createNonSuspendingQuery';
+import { parsePBSBackupInventory } from '../proxmoxBackupInventory';
+import { buildBackupServerRows } from '../ProxmoxBackupServersTable';
+import { ProxmoxBackupsTable } from '../ProxmoxBackupsTable';
+
+vi.mock('@/components/Infrastructure/ResourceDetailDrawer', () => ({
+ ResourceDetailDrawer: () => <div data-testid="pbs-count-owner-detail">Existing owner detail</div>,
+}));
+
+const apiFetchMock = vi.hoisted(() => vi.fn());
+vi.mock('@/utils/apiClient', () => ({ apiFetch: apiFetchMock, apiFetchJSON: vi.fn() }));
+
+const server = (name: string, datastore = 'tank'): Resource => ({
+ id: `resource-${name}`,
+ name,
+ displayName: `Display ${name}`,
+ type: 'pbs',
+ status: 'online',
+ lastSeen: 1_793_300_000_000,
+ platformId: 'proxmox-pbs',
+ platformType: 'proxmox-pbs',
+ sourceType: 'api',
+ pbs: {
+ instanceId: `pbs-${name}`,
+ hostname: 'shared-host.example.test',
+ connectionHealth: 'healthy',
+ datastores: [{ name: datastore, total: 1000, used: 400 }],
+ },
+});
+
+const entry = (instance: string | undefined, datastore = 'tank', suffix = '1') => ({
+ id: JSON.stringify([instance, datastore, suffix]),
+ instance,
+ datastore,
+ namespace: suffix,
+ backupType: 'vm',
+ vmid: '100',
+ backupTime: '2026-10-30T01:00:00Z',
+ files: ['index.json.blob'],
+});
+const inventory = (...entries: ReturnType<typeof entry>[]) => ({ data: { backups: entries } });
+const rows = (servers: Resource[], payload: unknown) =>
+ buildBackupServerRows(servers, parsePBSBackupInventory(payload).backups);
+
+// No DOM marker dependency: the table's summary rows have count-column cells,
+// whereas a detail row has only its spanning cell.
+const displayedCounts = (table: HTMLElement) => {
+ const index = [...table.querySelectorAll('th')].findIndex(
+ (cell) => cell.getAttribute('aria-label') === 'Backups',
+ );
+ return [...table.querySelectorAll('tbody tr')]
+ .filter((row) => row.querySelectorAll('td').length > index)
+ .map((row) => row.querySelectorAll('td')[index].textContent?.trim());
+};
+
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+ vi.unstubAllGlobals();
+ apiFetchMock.mockReset();
+ resetCreateNonSuspendingQueryCacheForTest();
+ window.history.replaceState({}, '', '/');
+});
+
+describe('PBS server count identity', () => {
+ it('does not borrow a namesake service-ID connection when the named reader has no entries', () => {
+ const result = rows(
+ [server('main'), server('pbs-main')],
+ inventory(entry('pbs-main'), entry('pbs-main', 'tank', '2')),
+ );
+ expect(result.map((row) => [row.serverName, row.backupCount])).toEqual([
+ ['main', 0],
+ ['pbs-main', 2],
+ ]);
+ });
+
+ it.each([
+ ['a::b', 'c', 'a', 'b::c'],
+ ['a', 'b::c', 'a::b', 'c'],
+ ])('keeps delimiter-bearing identities separate (%s / %s)', (name, store, other, otherStore) => {
+ const result = rows(
+ [server(name, store), server(other, otherStore)],
+ inventory(entry(name, store), entry(other, otherStore), entry(other, otherStore, '2')),
+ );
+ expect(result.find((row) => row.serverName === name)?.backupCount).toBe(1);
+ expect(result.find((row) => row.serverName === other)?.backupCount).toBe(2);
+ });
+
+ it('keeps exact reader/store case, namespaces and explicit empty tuples', () => {
+ const result = rows(
+ [server('Main', 'Tank'), server('main', 'tank'), server('empty')],
+ inventory(entry('Main', 'Tank'), entry('Main', 'Tank', '2'), entry('main', 'tank')),
+ );
+ expect(result.map((row) => [row.serverName, row.backupCount])).toEqual([
+ ['empty', 0],
+ ['main', 1],
+ ['Main', 2],
+ ]);
+ });
+
+ it('does not use display labels, hostnames or unattributed entries as reader identity', () => {
+ const result = rows(
+ [server('main')],
+ inventory(entry('Display main'), entry('shared-host.example.test'), entry(undefined)),
+ );
+ expect(result[0].backupCount).toBe(0);
+ });
+
+ it('counts admitted entries rather than inventing a completion or verification filter', () => {
+ const payload = inventory(entry('main'), entry('main', 'tank', '2'));
+ Object.assign(payload.data.backups[1], { inProgress: true, verified: false });
+ expect(rows([server('main')], payload)[0].backupCount).toBe(2);
+ });
+
+ it('keeps name-matched inventory even when an unrelated service-ID tuple also exists', () => {
+ expect(
+ rows(
+ [server('main')],
+ inventory(entry('main'), entry('pbs-main'), entry('pbs-main', 'tank', '2')),
+ )[0].backupCount,
+ ).toBe(1);
+ });
+
+ it('replaces exact server counts on polling, withdrawing failed reads without losing capacity', async () => {
+ vi.stubGlobal('scrollTo', vi.fn());
+ window.history.replaceState({}, '', '/proxmox/backups/date');
+ let payload = inventory(entry('pbs-main'), entry('pbs-main', 'tank', '2'));
+ let failed = false;
+ apiFetchMock.mockImplementation((url: string) =>
+ Promise.resolve(
+ new Response(
+ JSON.stringify(
+ url === '/api/backups/pbs'
+ ? payload
+ : { data: { storageBackups: [], guestSnapshots: [], backupTasks: [] } },
+ ),
+ { status: url === '/api/backups/pbs' && failed ? 403 : 200 },
+ ),
+ ),
+ );
+ const { container } = render(() => (
+ <Router>
+ <Route
+ path="/*"
+ component={() => (
+ <ProxmoxBackupsTable
+ emptyIcon={<span />}
+ servers={[server('main'), server('pbs-main')]}
+ />
+ )}
+ />
+ </Router>
+ ));
+ await screen.findByRole('columnheader', { name: 'Backups' });
+ const table = container.querySelector('[data-proxmox-backups-table="servers"]') as HTMLElement;
+ await waitFor(() => expect(displayedCounts(table)).toEqual(['0', '2']));
+ const disclosures = within(table).getAllByRole('button', { name: /details/i });
+ await fireEvent.click(disclosures[0]);
+ const detail = screen.getByTestId('pbs-count-owner-detail');
+
+ // Only the query's actual 30-second polling is advanced; no direct call to
+ // the count producer and no fabricated rendered rows in this consumer test.
+ vi.useFakeTimers();
+ payload = inventory(entry('main'), entry('main', 'tank', '2'), entry('main', 'tank', '3'));
+ await vi.advanceTimersByTimeAsync(30_000);
+ vi.useRealTimers();
+ await waitFor(() => expect(displayedCounts(table)).toEqual(['3', '0']));
+ expect(screen.getByTestId('pbs-count-owner-detail')).toBe(detail);
+
+ vi.useFakeTimers();
+ failed = true;
+ await vi.advanceTimersByTimeAsync(30_000);
+ vi.useRealTimers();
+ await screen.findByRole('button', { name: 'Retry PBS inventory' });
+ await waitFor(() => expect(displayedCounts(table)).toEqual(['Unavailable', 'Unavailable']));
+ expect(within(table).getAllByText('40.0%')).toHaveLength(2);
+ expect(within(table).getAllByText('Healthy')).toHaveLength(2);
+ failed = false;
+ payload = inventory();
+ await fireEvent.click(screen.getByRole('button', { name: 'Retry PBS inventory' }));
+ await waitFor(() => expect(displayedCounts(table)).toEqual(['0', '0']));
+ expect(apiFetchMock.mock.calls.filter(([url]) => url === '/api/backups/pbs')).toHaveLength(4);
+ expect(
+ apiFetchMock.mock.calls.every(([url]) =>
+ ['/api/backups/pbs', '/api/backups/pve'].includes(url),
+ ),
+ ).toBe(true);
+ });
+});