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.

Centralize throughput rate formatting

rcourtman6d721528d7d0
diff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
index cb42b13692..2a26fc6f75 100644
--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md
@@ -110,6 +110,10 @@ The aggregate `/api/charts/workloads-summary` endpoint now also has its own
explicit API p95 budget constant, aligned with the per-workload charts budget,
and `internal/api/slo_bench_test.go` must fail if that aggregate budget or its
store-backed mixed-workload benchmark coverage drifts.
+The infrastructure and workload summary cards now share a canonical
+throughput-rate formatter in `frontend-modern/src/utils/throughputPresentation.ts`,
+so bytes-per-second labels stay consistent between the two summary surfaces
+instead of each component carrying its own rate string builder.
Infrastructure selector status ordering must now tolerate arbitrary filter-set
strings without widening the canonical hot-path order tuple. Unknown statuses
diff --git a/frontend-modern/src/components/Infrastructure/InfrastructureSummary.tsx b/frontend-modern/src/components/Infrastructure/InfrastructureSummary.tsx
index 91da59dade..67df3e473d 100644
--- a/frontend-modern/src/components/Infrastructure/InfrastructureSummary.tsx
+++ b/frontend-modern/src/components/Infrastructure/InfrastructureSummary.tsx
@@ -25,6 +25,7 @@ import {
getResourceIdentityAliases,
getNormalizedIdentityLookupVariants,
} from '@/utils/resourceIdentity';
+import { formatThroughputRate } from '@/utils/throughputPresentation';
import { asTrimmedString } from '@/utils/stringUtils';
import { getOrgID } from '@/utils/apiClient';
import { normalizeOrgScope } from '@/utils/orgScope';
@@ -47,14 +48,6 @@ const getLinkedNodeIdFromResource = (resource: Resource): string | null =>
asTrimmedString(getPlatformAgentRecord(resource)?.linkedNodeId) ||
null;
-// Format bytes/sec to human-readable rate
-const formatRate = (bytesPerSec: number): string => {
- if (bytesPerSec >= 1e9) return `${(bytesPerSec / 1e9).toFixed(1)} GB/s`;
- if (bytesPerSec >= 1e6) return `${(bytesPerSec / 1e6).toFixed(1)} MB/s`;
- if (bytesPerSec >= 1e3) return `${(bytesPerSec / 1e3).toFixed(0)} KB/s`;
- return `${Math.round(bytesPerSec)} B/s`;
-};
-
// Combine a resource's net in/out into a single throughput series.
// Buckets points into 30-second windows and sums rates from both directions.
function combineResourceThroughputSeries(
@@ -645,7 +638,7 @@ export const InfrastructureSummary: Component<InfrastructureSummaryProps> = (pro
series={diskioSeries()}
rangeLabel={rangeLabel()}
timeRange={props.timeRange}
- formatValue={formatRate}
+ formatValue={formatThroughputRate}
/>
</SummaryMetricCard>
@@ -711,7 +704,7 @@ export const InfrastructureSummary: Component<InfrastructureSummaryProps> = (pro
series={networkSeries()}
rangeLabel={rangeLabel()}
timeRange={props.timeRange}
- formatValue={formatRate}
+ formatValue={formatThroughputRate}
/>
</SummaryMetricCard>
</Show>
diff --git a/frontend-modern/src/components/Workloads/WorkloadsSummary.tsx b/frontend-modern/src/components/Workloads/WorkloadsSummary.tsx
index d23d0ff49a..a65052087c 100644
--- a/frontend-modern/src/components/Workloads/WorkloadsSummary.tsx
+++ b/frontend-modern/src/components/Workloads/WorkloadsSummary.tsx
@@ -16,6 +16,7 @@ import {
import { getOrgID } from '@/utils/apiClient';
import { normalizeOrgScope } from '@/utils/orgScope';
import { eventBus } from '@/stores/events';
+import { formatThroughputRate } from '@/utils/throughputPresentation';
interface WorkloadsSummaryProps {
timeRange?: TimeRange;
@@ -291,13 +292,6 @@ const clampNonNegative = (value: number): number => {
return value;
};
-const formatRate = (bytesPerSec: number): string => {
- if (bytesPerSec >= 1e9) return `${(bytesPerSec / 1e9).toFixed(1)} GB/s`;
- if (bytesPerSec >= 1e6) return `${(bytesPerSec / 1e6).toFixed(1)} MB/s`;
- if (bytesPerSec >= 1e3) return `${(bytesPerSec / 1e3).toFixed(0)} KB/s`;
- return `${Math.round(bytesPerSec)} B/s`;
-};
-
const workloadPointLimitForCount = (count: number): number => {
if (count >= 600) return 48;
if (count >= 400) return 64;
@@ -789,7 +783,7 @@ export const WorkloadsSummary: Component<WorkloadsSummaryProps> = (props) => {
series={diskioSeries()}
rangeLabel={selectedRange()}
timeRange={selectedRange()}
- formatValue={formatRate}
+ formatValue={formatThroughputRate}
/>
</SummaryMetricCard>
@@ -804,7 +798,7 @@ export const WorkloadsSummary: Component<WorkloadsSummaryProps> = (props) => {
series={networkSeries()}
rangeLabel={selectedRange()}
timeRange={selectedRange()}
- formatValue={formatRate}
+ formatValue={formatThroughputRate}
/>
</SummaryMetricCard>
</SummaryPanel>
diff --git a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
index c0f0c2d1ce..d91e56f732 100644
--- a/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
+++ b/frontend-modern/src/utils/__tests__/frontendResourceTypeBoundaries.test.ts
@@ -70,6 +70,7 @@ import dashboardStoragePresentationSource from '@/utils/dashboardStoragePresenta
import dashboardRecoveryPresentationSource from '@/utils/dashboardRecoveryPresentation.ts?raw';
import dashboardKpiPresentationSource from '@/utils/dashboardKpiPresentation.ts?raw';
import dashboardEmptyStatePresentationSource from '@/utils/dashboardEmptyStatePresentation.ts?raw';
+import throughputPresentationSource from '@/utils/throughputPresentation.ts?raw';
import resourceChangeSummarySource from '@/components/Infrastructure/ResourceChangeSummary.tsx?raw';
import resourceChangePresentationSource from '@/utils/resourceChangePresentation.ts?raw';
import resourceRelationshipPresentationSource from '@/utils/resourceRelationshipPresentation.ts?raw';
@@ -1918,6 +1919,7 @@ describe('frontend resource type boundaries', () => {
expect(confidencePresentationSource).toContain('formatConfidencePercentage');
expect(confidencePresentationSource).toContain('formatConfidenceLabel');
expect(approvalPresentationSource).toContain('getResourceApprovalLevelLabel');
+ expect(throughputPresentationSource).toContain('formatThroughputRate');
expect(resourceChangePresentationSource).toContain('humanizeToken');
expect(resourceRelationshipPresentationSource).toContain('humanizeToken');
expect(resourceCorrelationPresentationSource).toContain('humanizeToken');
diff --git a/frontend-modern/src/utils/__tests__/throughputPresentation.test.ts b/frontend-modern/src/utils/__tests__/throughputPresentation.test.ts
new file mode 100644
index 0000000000..5e61b7fbf2
--- /dev/null
+++ b/frontend-modern/src/utils/__tests__/throughputPresentation.test.ts
@@ -0,0 +1,13 @@
+import { describe, expect, it } from 'vitest';
+
+import { formatThroughputRate } from '@/utils/throughputPresentation';
+
+describe('throughputPresentation', () => {
+ it('formats bytes per second with canonical throughput labels', () => {
+ expect(formatThroughputRate(0)).toBe('0 B/s');
+ expect(formatThroughputRate(999)).toBe('999 B/s');
+ expect(formatThroughputRate(1_000)).toBe('1 KB/s');
+ expect(formatThroughputRate(1_500_000)).toBe('1.5 MB/s');
+ expect(formatThroughputRate(2_000_000_000)).toBe('2.0 GB/s');
+ });
+});
diff --git a/frontend-modern/src/utils/throughputPresentation.ts b/frontend-modern/src/utils/throughputPresentation.ts
new file mode 100644
index 0000000000..9549cb48ed
--- /dev/null
+++ b/frontend-modern/src/utils/throughputPresentation.ts
@@ -0,0 +1,19 @@
+const RATE_UNITS = [
+ { threshold: 1e9, suffix: 'GB/s', precision: 1 },
+ { threshold: 1e6, suffix: 'MB/s', precision: 1 },
+ { threshold: 1e3, suffix: 'KB/s', precision: 0 },
+] as const;
+
+export function formatThroughputRate(bytesPerSecond: number): string {
+ if (!Number.isFinite(bytesPerSecond) || bytesPerSecond < 0) {
+ return '0 B/s';
+ }
+
+ for (const unit of RATE_UNITS) {
+ if (bytesPerSecond >= unit.threshold) {
+ return `${(bytesPerSecond / unit.threshold).toFixed(unit.precision)} ${unit.suffix}`;
+ }
+ }
+
+ return `${Math.round(bytesPerSecond)} B/s`;
+}