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.

Remove storage growth planner

rcourtman127389cd6fec
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index ac9a1dce21..5546e538c4 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -705,6 +705,11 @@ prompt explain the same operator-facing priority.
still add collection labels such as Pulse Agent, but it must not repeat the
same platform again as an unversioned source badge.
9. Keep top-of-page summary interaction on shared primitives. Infrastructure, workloads, and storage summary cards must route sticky-shell behavior through `frontend-modern/src/components/shared/StickySummarySection.tsx` and route row-hover or focused-series rendering through shared chart primitives such as `frontend-modern/src/components/shared/InteractiveSparkline.tsx` and `frontend-modern/src/components/shared/DensityMap.tsx`, rather than page-local sticky wrappers or metric-card-specific hover logic. When a page keeps summary charts visible below the desktop breakpoint, it must use the shared `stickyDesktopOnly` mode instead of adding page-local media queries, so wrapped two-column summaries scroll as normal content and only become sticky once the large-screen layout is active. The shared summary-card contract must also own stable summary-card geometry for chart-backed cards so row hover, focus, synchronized readouts, or idle header metadata cannot ratchet the sticky summary taller across rerenders.
+ Storage's top-of-page summary scope is limited to the stable chart grid and
+ shared row/group focus affordances. A rolling-history capacity planner must
+ not be bolted onto the sticky summary shell as an extra frontend primitive;
+ if capacity planning returns, it needs an owner-level model that can keep
+ the summary geometry and visible card set stable across refreshes.
10. Keep summary chart interaction identity on one shared helper. Summary surfaces that expose row-hover, group-hover, chart-hover, or route-focus-driven chart emphasis must derive page/group/entity scope through `frontend-modern/src/components/shared/summaryCardInteraction.ts` and pass that same resolved scope into card-state, sparkline, and density-map primitives, rather than letting cards read `hovered || focused` while charts listen to a different page-local ID source. Hovering one summary chart must promote that series into the shared active entity so sibling cards highlight the same object instead of keeping chart-local hover islands, and hovering or pinning a workload group header, infrastructure cluster header, or storage pool-group header must scope the matching summary cards through that same shared contract instead of forking a page-local summary filter path. Sibling cards should surface that synchronized hover as one compact header readout through the shared summary-card contract, while the chart under the pointer keeps the only floating tooltip. `frontend-modern/src/components/Recovery/RecoverySummary.tsx` is explicitly outside this interaction dialect: recovery posture cards may share summary framing, but they must not silently grow row/group/chart hover behavior without a separate governed product decision.
11. Keep page summaries page-scoped when table rows enter contextual focus. Route-backed row selection may add a focused label and shared series emphasis, but infrastructure, workloads, and storage summary cards must continue to render the page-level series set instead of collapsing the summary down to the selected row or replacing the global trend view with row-local empty states.
12. Keep contextual row focus on the shared summary primitive. Summary surfaces and same-route table drill-ins must reuse `frontend-modern/src/components/shared/contextualFocus.ts` for interactive-series filtering, focused-name lookup, active-series derivation, local scroll preservation, and deliberate inline-detail reveal instead of rebuilding page-local `Set` filters, focused-label scans, drawer-aware scroll math, or ad hoc scroll restoration in each surface.
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 96ebdad573..418e48f076 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -205,6 +205,11 @@ bypass the API fail-closed execution gate.
breakpoint, it must use the frontend-primitives-owned
`StickySummarySection` desktop-sticky mode so the wrapped 2x2 chart grid
scrolls with the page instead of pinning most of a narrow viewport.
+ Storage must not reintroduce a sticky, frontend-only growth planner or
+ runway card derived directly from rolling summary chart deltas. Capacity
+ pressure planning may return as a governed storage/recovery model only when
+ the signal is stable, backend-owned, and action-oriented enough not to churn
+ the primary monitoring surface during ordinary refreshes.
Ceph table shells on the storage route share the same frontend-primitives
table contract: `frontend-modern/src/pages/Ceph.tsx` may own Ceph-specific
columns and rows, but horizontal overflow and scrollbar hiding must route
diff --git a/frontend-modern/src/components/Storage/Storage.tsx b/frontend-modern/src/components/Storage/Storage.tsx
index 6aef783699..497f224042 100644
--- a/frontend-modern/src/components/Storage/Storage.tsx
+++ b/frontend-modern/src/components/Storage/Storage.tsx
@@ -1,7 +1,6 @@
import { Component, Show } from 'solid-js';
import StorageCephSection from '@/components/Storage/StorageCephSection';
import StorageContentCard from '@/components/Storage/StorageContentCard';
-import StorageGrowthPlanner from '@/components/Storage/StorageGrowthPlanner';
import StoragePageBanners from '@/components/Storage/StoragePageBanners';
import StoragePageControls from '@/components/Storage/StoragePageControls';
import StoragePageSummary from '@/components/Storage/StoragePageSummary';
@@ -20,7 +19,6 @@ const Storage: Component = () => {
setStorageSummaryCollapsed,
storageGrowthBySeriesId,
storageGrowthColumnLabel,
- storageGrowthPlanner,
storageSummaryData,
storageSummaryLoaded,
storageSummaryFetchFailed,
@@ -74,7 +72,6 @@ const Storage: Component = () => {
hoveredStorageResourceId,
isLoadingPools,
focusedStorageResourceId,
- focusStorageGrowthPool,
jumpToActiveStorageRow,
selectedDiskId,
setChartHoverSync,
@@ -129,14 +126,6 @@ const Storage: Component = () => {
setStorageFilterStatus('attention');
}}
/>
- <StorageGrowthPlanner
- planner={storageGrowthPlanner()}
- loaded={storageSummaryLoaded()}
- fetchFailed={storageSummaryFetchFailed()}
- activeSeriesId={activeSummaryStorageResourceId()}
- onFocusPool={focusStorageGrowthPool}
- onHoverPool={setHoveredStorageResourceId}
- />
</div>
</StickySummarySection>
</Show>
diff --git a/frontend-modern/src/components/Storage/StorageGrowthPlanner.tsx b/frontend-modern/src/components/Storage/StorageGrowthPlanner.tsx
deleted file mode 100644
index 677876f25d..0000000000
--- a/frontend-modern/src/components/Storage/StorageGrowthPlanner.tsx
+++ /dev/null
@@ -1,151 +0,0 @@
-import { Component, For, Show } from 'solid-js';
-import type {
- StorageGrowthPlannerPool,
- StorageGrowthPlannerPresentation,
-} from '@/features/storageBackups/storageGrowthPlannerPresentation';
-
-type StorageGrowthPlannerProps = {
- planner: StorageGrowthPlannerPresentation;
- loaded: boolean;
- fetchFailed: boolean;
- activeSeriesId?: string | null;
- onFocusPool?: (seriesId: string) => void;
- onHoverPool?: (seriesId: string | null) => void;
-};
-
-const STORAGE_GROWTH_PLANNER_FRAME_CLASS = 'rounded-md border border-border bg-surface shadow-sm';
-const STORAGE_GROWTH_PLANNER_HEADER_CLASS =
- 'flex flex-wrap items-center justify-between gap-2 border-b border-border-subtle px-3 py-2';
-const STORAGE_GROWTH_PLANNER_LIST_CLASS = 'grid gap-2 p-2 sm:grid-cols-2 xl:grid-cols-3';
-const STORAGE_GROWTH_PLANNER_ITEM_CLASS =
- 'min-w-0 rounded border border-border bg-surface-alt px-2.5 py-2 text-left transition-colors hover:border-sky-300 hover:bg-surface focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40';
-const STORAGE_GROWTH_PLANNER_ACTIVE_ITEM_CLASS =
- 'border-sky-400 bg-sky-50 ring-2 ring-inset ring-sky-500/20 dark:bg-sky-950/30';
-const STORAGE_GROWTH_PLANNER_EMPTY_CLASS = 'px-3 py-4 text-sm text-muted';
-const STORAGE_GROWTH_PLANNER_SKELETON_CLASS =
- 'h-[74px] animate-pulse rounded border border-border bg-surface-alt';
-
-const StorageGrowthPlannerItem: Component<{
- pool: StorageGrowthPlannerPool;
- active: boolean;
- onFocus?: (seriesId: string) => void;
- onHover?: (seriesId: string | null) => void;
-}> = (props) => (
- <button
- type="button"
- class={`${STORAGE_GROWTH_PLANNER_ITEM_CLASS} ${
- props.active ? STORAGE_GROWTH_PLANNER_ACTIVE_ITEM_CLASS : ''
- }`.trim()}
- title={props.pool.runwayTitle}
- data-testid={`storage-growth-planner-pool-${props.pool.seriesId}`}
- data-summary-series-id={props.pool.seriesId}
- data-storage-growth-priority={props.pool.priority}
- onClick={() => props.onFocus?.(props.pool.seriesId)}
- onPointerEnter={(event) => {
- if (event.pointerType !== 'touch') {
- props.onHover?.(props.pool.seriesId);
- }
- }}
- onPointerLeave={(event) => {
- if (event.pointerType !== 'touch') {
- props.onHover?.(null);
- }
- }}
- onFocus={() => props.onHover?.(props.pool.seriesId)}
- onBlur={() => props.onHover?.(null)}
- >
- <div class="flex min-w-0 items-start justify-between gap-2">
- <div class="min-w-0">
- <div class="truncate text-[12px] font-semibold text-base-content">{props.pool.name}</div>
- <div class="truncate text-[11px] text-muted">{props.pool.hostLabel}</div>
- </div>
- <span
- class={`shrink-0 rounded-full border px-1.5 py-0.5 text-[10px] font-semibold ${props.pool.priorityToneClass}`}
- >
- {props.pool.priorityLabel}
- </span>
- </div>
- <div class="mt-2 grid grid-cols-3 gap-2 text-[11px]">
- <div class="min-w-0">
- <div class="text-muted">Growth</div>
- <div class={`truncate font-mono font-semibold ${props.pool.growthToneClass}`}>
- {props.pool.growthLabel}
- </div>
- </div>
- <div class="min-w-0">
- <div class="text-muted">Runway</div>
- <div class="truncate font-semibold text-base-content">{props.pool.runwayLabel}</div>
- </div>
- <div class="min-w-0">
- <div class="text-muted">{props.pool.usageLabel}</div>
- <div class="truncate text-base-content">{props.pool.freeLabel}</div>
- </div>
- </div>
- </button>
-);
-
-export const StorageGrowthPlanner: Component<StorageGrowthPlannerProps> = (props) => {
- const headerSummary = () => {
- if (props.fetchFailed) {
- return 'History unavailable';
- }
- return `${props.planner.growingPoolCount}/${props.planner.trackedPoolCount} growing`;
- };
-
- return (
- <section
- class={STORAGE_GROWTH_PLANNER_FRAME_CLASS}
- data-testid="storage-growth-planner"
- aria-label="Storage growth planner"
- >
- <div class={STORAGE_GROWTH_PLANNER_HEADER_CLASS}>
- <div class="min-w-0">
- <h2 class="text-sm font-semibold text-base-content">Growth Planner</h2>
- <p class="text-[11px] text-muted">
- {props.planner.rangeLabel} runway from storage history
- </p>
- </div>
- <div class="text-[11px] font-medium text-muted">{headerSummary()}</div>
- </div>
- <Show
- when={props.loaded}
- fallback={
- <div class={STORAGE_GROWTH_PLANNER_LIST_CLASS}>
- <div class={STORAGE_GROWTH_PLANNER_SKELETON_CLASS} />
- <div class={STORAGE_GROWTH_PLANNER_SKELETON_CLASS} />
- <div class={STORAGE_GROWTH_PLANNER_SKELETON_CLASS} />
- </div>
- }
- >
- <Show
- when={!props.fetchFailed && props.planner.topPools.length > 0}
- fallback={
- <div class={STORAGE_GROWTH_PLANNER_EMPTY_CLASS}>
- <div class="font-medium text-base-content">{props.planner.emptyTitle}</div>
- <div class="mt-0.5">
- {props.fetchFailed
- ? 'Trend history could not be loaded.'
- : props.planner.emptyMessage}
- </div>
- </div>
- }
- >
- <div class={STORAGE_GROWTH_PLANNER_LIST_CLASS}>
- <For each={props.planner.topPools}>
- {(pool) => (
- <StorageGrowthPlannerItem
- pool={pool}
- active={props.activeSeriesId === pool.seriesId}
- onFocus={props.onFocusPool}
- onHover={props.onHoverPool}
- />
- )}
- </For>
- </div>
- </Show>
- </Show>
- </section>
- );
-};
-
-export default StorageGrowthPlanner;
diff --git a/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx b/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx
index d397111d03..ee511164bd 100644
--- a/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx
+++ b/frontend-modern/src/components/Storage/__tests__/Storage.test.tsx
@@ -501,17 +501,6 @@ describe('Storage', () => {
const storageContentSurface = screen.getByTestId('storage-content-surface');
expect(await within(storageContentSurface).findByText(/\+40(?:\.0)? GB/)).toBeInTheDocument();
expect(within(storageContentSurface).getByText(/-20(?:\.0)? GB/)).toBeInTheDocument();
- expect(screen.getByTestId('storage-growth-planner')).toHaveTextContent(
- '24h runway from storage history',
- );
- expect(screen.getByTestId('storage-growth-planner')).toHaveTextContent('1/2 growing');
- expect(screen.getByTestId('storage-growth-planner')).toHaveTextContent('3 days');
-
- fireEvent.click(screen.getByTestId('storage-growth-planner-pool-pool:alpha'));
-
- await waitFor(() => {
- expect(screen.getByRole('button', { name: 'Collapse Alpha-Store' })).toBeInTheDocument();
- });
expect(storageSummarySpy).toHaveBeenCalledWith('24h', undefined, { nodeId: undefined });
storageSummarySpy.mockRestore();
diff --git a/frontend-modern/src/components/Storage/useStoragePageModel.ts b/frontend-modern/src/components/Storage/useStoragePageModel.ts
index 7a02e84972..6f731fc24f 100644
--- a/frontend-modern/src/components/Storage/useStoragePageModel.ts
+++ b/frontend-modern/src/components/Storage/useStoragePageModel.ts
@@ -6,7 +6,6 @@ import {
type SummaryTimeRange,
} from '@/components/shared/summaryTimeRange';
import { buildStorageCapacityDeltaPresentation } from '@/features/storageBackups/storageCapacityDeltaPresentation';
-import { buildStorageGrowthPlannerPresentation } from '@/features/storageBackups/storageGrowthPlannerPresentation';
import {
resolvePhysicalDiskMetricResourceId,
resolveStorageRecordMetricResourceId,
@@ -193,13 +192,6 @@ export const useStoragePageModel = () => {
}
return growth;
});
- const storageGrowthPlanner = createMemo(() =>
- buildStorageGrowthPlannerPresentation({
- records: filteredRecords(),
- pools: storageSummaryCharts.data()?.pools,
- rangeLabel: storageGrowthRangeLabel(),
- }),
- );
const hoveredStorageResourceId = createMemo(() => {
const hoveredId = hoveredStorageRowId();
if (!hoveredId) return null;
@@ -227,13 +219,6 @@ export const useStoragePageModel = () => {
}
return keys;
});
- const storageRecordIdByMetricSeriesId = createMemo(() => {
- const ids = new Map<string, string>();
- for (const record of records()) {
- ids.set(resolveStorageRecordMetricResourceId(record), record.id);
- }
- return ids;
- });
const physicalDiskSeriesIds = createMemo(() => {
const ids = new Set<string>();
for (const disk of physicalDisks()) {
@@ -457,21 +442,6 @@ export const useStoragePageModel = () => {
},
});
- const focusStorageGrowthPool = (seriesId: string) => {
- const recordId = storageRecordIdByMetricSeriesId().get(seriesId);
- if (!recordId) {
- return;
- }
- if (view() !== 'pools') {
- setView('pools');
- }
- const groupKey = storageGroupKeyByMetricSeriesId().get(seriesId);
- if (groupKey && !expandedGroups().has(groupKey)) {
- toggleGroup(groupKey);
- }
- setExpandedPoolId(recordId);
- };
-
onCleanup(() => {
routeStateNavigate.cleanup();
});
@@ -489,7 +459,6 @@ export const useStoragePageModel = () => {
setStorageSummaryCollapsed,
storageGrowthBySeriesId,
storageGrowthColumnLabel,
- storageGrowthPlanner,
storageSummaryData: storageSummaryCharts.data,
storageSummaryLoaded: storageSummaryCharts.loaded,
storageSummaryFetchFailed: storageSummaryCharts.fetchFailed,
@@ -540,7 +509,6 @@ export const useStoragePageModel = () => {
hoveredStorageResourceId,
isLoadingPools,
jumpToActiveStorageRow: summaryInteraction.jumpToActiveRow,
- focusStorageGrowthPool,
focusedSummaryStorageGroupScope: focusedStorageGroupScope,
focusedSummaryStorageGroupId: selectedStorageGroupId,
hoveredSummaryStorageGroupScope: hoveredStorageGroupScope,
diff --git a/frontend-modern/src/features/storageBackups/__tests__/storageGrowthPlannerPresentation.test.ts b/frontend-modern/src/features/storageBackups/__tests__/storageGrowthPlannerPresentation.test.ts
deleted file mode 100644
index aa0973d88f..0000000000
--- a/frontend-modern/src/features/storageBackups/__tests__/storageGrowthPlannerPresentation.test.ts
+++ /dev/null
@@ -1,148 +0,0 @@
-import { describe, expect, it } from 'vitest';
-import type { StorageRecord } from '@/features/storageBackups/models';
-import { buildStorageGrowthPlannerPresentation } from '@/features/storageBackups/storageGrowthPlannerPresentation';
-
-const GB = 1024 * 1024 * 1024;
-
-const buildRecord = (
- id: string,
- name: string,
- capacity: StorageRecord['capacity'],
-): StorageRecord => ({
- id,
- name,
- category: 'pool',
- health: 'healthy',
- hostLabel: 'pve1',
- location: { label: 'pve1', scope: 'node' },
- capacity,
- capabilities: ['capacity'],
- source: {
- platform: 'proxmox-pve',
- family: 'virtualization',
- origin: 'resource',
- adapterId: 'test',
- },
- observedAt: 0,
- metricsTarget: {
- resourceType: 'storage',
- resourceId: `pool:${id}`,
- },
- refs: {},
- details: {},
-});
-
-describe('storageGrowthPlannerPresentation', () => {
- it('ranks pools by runway using selected-range used history and current capacity', () => {
- const planner = buildStorageGrowthPlannerPresentation({
- rangeLabel: '24h',
- records: [
- buildRecord('alpha', 'Alpha Pool', {
- totalBytes: 250 * GB,
- usedBytes: 140 * GB,
- freeBytes: 110 * GB,
- usagePercent: 56,
- }),
- buildRecord('beta', 'Beta Pool', {
- totalBytes: 300 * GB,
- usedBytes: 276 * GB,
- freeBytes: 24 * GB,
- usagePercent: 92,
- }),
- buildRecord('gamma', 'Gamma Pool', {
- totalBytes: 200 * GB,
- usedBytes: 80 * GB,
- freeBytes: 120 * GB,
- usagePercent: 40,
- }),
- ],
- pools: {
- 'pool:alpha': {
- name: 'Alpha Pool',
- usage: [],
- used: [
- { timestamp: 1, value: 100 * GB },
- { timestamp: 86_400_001, value: 140 * GB },
- ],
- avail: [
- { timestamp: 1, value: 150 * GB },
- { timestamp: 86_400_001, value: 110 * GB },
- ],
- },
- 'pool:beta': {
- name: 'Beta Pool',
- usage: [],
- used: [
- { timestamp: 1, value: 276 * GB },
- { timestamp: 86_400_001, value: 276 * GB },
- ],
- avail: [
- { timestamp: 1, value: 24 * GB },
- { timestamp: 86_400_001, value: 24 * GB },
- ],
- },
- 'pool:gamma': {
- name: 'Gamma Pool',
- usage: [],
- used: [
- { timestamp: 1, value: 90 * GB },
- { timestamp: 86_400_001, value: 80 * GB },
- ],
- avail: [
- { timestamp: 1, value: 110 * GB },
- { timestamp: 86_400_001, value: 120 * GB },
- ],
- },
- },
- });
-
- expect(planner.rangeLabel).toBe('24h');
- expect(planner.trackedPoolCount).toBe(3);
- expect(planner.growingPoolCount).toBe(1);
- expect(planner.topPools.map((pool) => pool.name)).toEqual(['Alpha Pool', 'Beta Pool']);
- expect(planner.topPools[0]).toMatchObject({
- growthLabel: '+40.0 GB',
- runwayLabel: '3 days',
- priorityLabel: 'Plan now',
- });
- expect(planner.topPools[1]).toMatchObject({
- growthLabel: '0 B',
- runwayLabel: 'Unknown',
- priorityLabel: 'Plan now',
- });
- });
-
- it('returns an empty state when scoped pools are stable', () => {
- const planner = buildStorageGrowthPlannerPresentation({
- rangeLabel: '7d',
- records: [
- buildRecord('stable', 'Stable Pool', {
- totalBytes: 100 * GB,
- usedBytes: 20 * GB,
- freeBytes: 80 * GB,
- usagePercent: 20,
- }),
- ],
- pools: {
- 'pool:stable': {
- name: 'Stable Pool',
- usage: [],
- used: [
- { timestamp: 1, value: 30 * GB },
- { timestamp: 604_800_001, value: 20 * GB },
- ],
- avail: [
- { timestamp: 1, value: 70 * GB },
- { timestamp: 604_800_001, value: 80 * GB },
- ],
- },
- },
- });
-
- expect(planner.topPools).toEqual([]);
- expect(planner.emptyTitle).toBe('No capacity planning pressure over 7d');
- expect(planner.planningPools[0]?.priorityToneClass).toBe(
- 'border-green-200 bg-green-50 text-green-700 dark:border-green-900/60 dark:bg-green-950/30 dark:text-green-300',
- );
- });
-});
diff --git a/frontend-modern/src/features/storageBackups/storageGrowthPlannerPresentation.ts b/frontend-modern/src/features/storageBackups/storageGrowthPlannerPresentation.ts
deleted file mode 100644
index 9e2d8a7865..0000000000
--- a/frontend-modern/src/features/storageBackups/storageGrowthPlannerPresentation.ts
+++ /dev/null
@@ -1,274 +0,0 @@
-import type { MetricPoint, StoragePoolChartData } from '@/api/charts';
-import { formatBytes, formatPercent } from '@/utils/format';
-import type { StorageRecord } from './models';
-import {
- buildStorageCapacityDeltaPresentation,
- computeStorageCapacityDeltaAnalysis,
-} from './storageCapacityDeltaPresentation';
-import { getStorageRecordHostLabel } from './recordPresentation';
-import { resolveStorageRecordMetricResourceId } from './storageMetricsIdentity';
-
-const DAY_MS = 24 * 60 * 60 * 1000;
-const TOP_POOL_LIMIT = 3;
-
-export type StorageGrowthPlannerPriority = 'critical' | 'warning' | 'watch' | 'stable' | 'unknown';
-
-export interface StorageGrowthPlannerPool {
- recordId: string;
- seriesId: string;
- name: string;
- hostLabel: string;
- usageLabel: string;
- freeLabel: string;
- growthDeltaBytes: number | null;
- growthLabel: string;
- growthTitle: string;
- growthToneClass: string;
- runwayDays: number | null;
- runwayLabel: string;
- runwayTitle: string;
- priority: StorageGrowthPlannerPriority;
- priorityLabel: string;
- priorityToneClass: string;
-}
-
-export interface StorageGrowthPlannerPresentation {
- rangeLabel: string;
- trackedPoolCount: number;
- growingPoolCount: number;
- planningPools: StorageGrowthPlannerPool[];
- topPools: StorageGrowthPlannerPool[];
- emptyTitle: string;
- emptyMessage: string;
-}
-
-function asFiniteNonNegative(value: number | null | undefined): number | null {
- if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
- return null;
- }
- return value;
-}
-
-function getLatestMetricValue(points: MetricPoint[] | undefined): number | null {
- if (!points) {
- return null;
- }
- let latest: MetricPoint | null = null;
- for (const point of points) {
- if (!Number.isFinite(point.timestamp) || !Number.isFinite(point.value)) {
- continue;
- }
- if (!latest || point.timestamp > latest.timestamp) {
- latest = point;
- }
- }
- return asFiniteNonNegative(latest?.value);
-}
-
-function formatRunwayDays(runwayDays: number | null): string {
- if (runwayDays === null) {
- return 'Unknown';
- }
- if (runwayDays <= 0) {
- return 'Full now';
- }
- if (runwayDays < 1) {
- return '<1 day';
- }
- if (runwayDays < 90) {
- const days = Math.max(1, Math.round(runwayDays));
- return `${days} ${days === 1 ? 'day' : 'days'}`;
- }
- const months = Math.max(3, Math.round(runwayDays / 30));
- if (months < 24) {
- return `${months} mo`;
- }
- const years = Math.round(months / 12);
- return `${years} yr`;
-}
-
-function getPriority(
- usagePercent: number | null,
- growthDeltaBytes: number | null,
- runwayDays: number | null,
-): StorageGrowthPlannerPriority {
- if (runwayDays !== null) {
- if (runwayDays <= 30) return 'critical';
- if (runwayDays <= 90) return 'warning';
- return 'watch';
- }
- if ((usagePercent ?? 0) >= 90) {
- return 'critical';
- }
- if ((usagePercent ?? 0) >= 80) {
- return 'warning';
- }
- if ((growthDeltaBytes ?? 0) > 0) {
- return 'unknown';
- }
- return 'stable';
-}
-
-function getPriorityLabel(priority: StorageGrowthPlannerPriority): string {
- switch (priority) {
- case 'critical':
- return 'Plan now';
- case 'warning':
- return 'Plan soon';
- case 'watch':
- return 'Watch';
- case 'unknown':
- return 'Needs trend';
- case 'stable':
- return 'Stable';
- }
-}
-
-function getPriorityToneClass(priority: StorageGrowthPlannerPriority): string {
- switch (priority) {
- case 'critical':
- return 'border-red-200 bg-red-50 text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300';
- case 'warning':
- return 'border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300';
- case 'watch':
- return 'border-sky-200 bg-sky-50 text-sky-700 dark:border-sky-900/60 dark:bg-sky-950/30 dark:text-sky-300';
- case 'unknown':
- return 'border-border bg-surface-alt text-muted';
- case 'stable':
- return 'border-green-200 bg-green-50 text-green-700 dark:border-green-900/60 dark:bg-green-950/30 dark:text-green-300';
- }
-}
-
-function buildRunwayTitle(
- poolName: string,
- runwayDays: number | null,
- growthDeltaBytes: number | null,
- rangeLabel: string,
-): string {
- if ((growthDeltaBytes ?? 0) <= 0) {
- return `${poolName} is not growing over ${rangeLabel}.`;
- }
- if (runwayDays === null) {
- return `${poolName} needs more capacity data before runway can be estimated.`;
- }
- return `${poolName} reaches full capacity in about ${formatRunwayDays(runwayDays)} at the ${rangeLabel} growth rate.`;
-}
-
-function buildPoolPresentation(
- record: StorageRecord,
- chartData: StoragePoolChartData | undefined,
- rangeLabel: string,
-): StorageGrowthPlannerPool {
- const seriesId = resolveStorageRecordMetricResourceId(record);
- const totalBytes = asFiniteNonNegative(record.capacity.totalBytes);
- const usedBytes = asFiniteNonNegative(record.capacity.usedBytes);
- const latestAvailBytes = getLatestMetricValue(chartData?.avail);
- const freeBytes =
- asFiniteNonNegative(record.capacity.freeBytes) ??
- (totalBytes !== null && usedBytes !== null ? Math.max(totalBytes - usedBytes, 0) : null) ??
- latestAvailBytes;
- const effectiveTotalBytes =
- totalBytes ??
- (usedBytes !== null && freeBytes !== null ? Math.max(usedBytes + freeBytes, 0) : null);
- const usagePercent =
- typeof record.capacity.usagePercent === 'number' &&
- Number.isFinite(record.capacity.usagePercent)
- ? record.capacity.usagePercent
- : effectiveTotalBytes && usedBytes !== null
- ? (usedBytes / effectiveTotalBytes) * 100
- : null;
- const deltaPresentation = buildStorageCapacityDeltaPresentation(
- chartData?.used ?? [],
- rangeLabel,
- );
- const deltaAnalysis = computeStorageCapacityDeltaAnalysis(chartData?.used ?? []);
- const growthRatePerMs =
- deltaAnalysis && deltaAnalysis.deltaBytes > 0
- ? deltaAnalysis.deltaBytes / deltaAnalysis.durationMs
- : null;
- const runwayDays =
- growthRatePerMs && freeBytes !== null
- ? Math.max(0, freeBytes / growthRatePerMs / DAY_MS)
- : null;
- const priority = getPriority(usagePercent, deltaPresentation.deltaBytes, runwayDays);
-
- return {
- recordId: record.id,
- seriesId,
- name: record.name,
- hostLabel: getStorageRecordHostLabel(record),
- usageLabel: usagePercent === null ? 'Usage n/a' : `${formatPercent(usagePercent)} used`,
- freeLabel: freeBytes === null ? 'Free n/a' : `${formatBytes(freeBytes)} free`,
- growthDeltaBytes: deltaPresentation.deltaBytes,
- growthLabel: deltaPresentation.label,
- growthTitle: deltaPresentation.title,
- growthToneClass: deltaPresentation.toneClass,
- runwayDays,
- runwayLabel: formatRunwayDays(runwayDays),
- runwayTitle: buildRunwayTitle(
- record.name,
- runwayDays,
- deltaPresentation.deltaBytes,
- rangeLabel,
- ),
- priority,
- priorityLabel: getPriorityLabel(priority),
- priorityToneClass: getPriorityToneClass(priority),
- };
-}
-
-function comparePlanningPools(
- left: StorageGrowthPlannerPool,
- right: StorageGrowthPlannerPool,
-): number {
- const priorityRank: Record<StorageGrowthPlannerPriority, number> = {
- critical: 0,
- warning: 1,
- watch: 2,
- unknown: 3,
- stable: 4,
- };
- const priorityDelta = priorityRank[left.priority] - priorityRank[right.priority];
- if (priorityDelta !== 0) {
- return priorityDelta;
- }
- const leftRunway = left.runwayDays ?? Number.POSITIVE_INFINITY;
- const rightRunway = right.runwayDays ?? Number.POSITIVE_INFINITY;
- if (leftRunway !== rightRunway) {
- return leftRunway - rightRunway;
- }
- return (right.growthDeltaBytes ?? 0) - (left.growthDeltaBytes ?? 0);
-}
-
-export function buildStorageGrowthPlannerPresentation(params: {
- records: StorageRecord[];
- pools: Record<string, StoragePoolChartData> | undefined;
- rangeLabel: string;
-}): StorageGrowthPlannerPresentation {
- const planningPools = params.records
- .map((record) => {
- const seriesId = resolveStorageRecordMetricResourceId(record);
- return buildPoolPresentation(record, params.pools?.[seriesId], params.rangeLabel);
- })
- .sort(comparePlanningPools);
- const topPools = planningPools
- .filter((pool) => pool.priority !== 'stable')
- .slice(0, TOP_POOL_LIMIT);
- const growingPoolCount = planningPools.filter((pool) => (pool.growthDeltaBytes ?? 0) > 0).length;
-
- return {
- rangeLabel: params.rangeLabel,
- trackedPoolCount: planningPools.length,
- growingPoolCount,
- planningPools,
- topPools,
- emptyTitle:
- planningPools.length === 0
- ? 'No pools in scope'
- : `No capacity planning pressure over ${params.rangeLabel}`,
- emptyMessage:
- planningPools.length === 0
- ? 'Storage filters have removed every pool from the planner.'
- : 'Tracked pools are stable or shrinking for the selected range.',
- };
-}