From 1251aff8230cd3739a2828c9af16738c3263a80a Mon Sep 17 00:00:00 2001 From: Marek Libra Date: Thu, 4 Apr 2019 14:08:35 +0200 Subject: [PATCH] ClusterOverview: Improve prometheus query for CPU Capacity and fix Capacity tests. --- .../ClusterOverview/Capacity/Capacity.js | 11 ++++----- .../Capacity/fixtures/Capacity.fixture.js | 3 +-- .../tests/__snapshots__/Capacity.test.js.snap | 24 ++++--------------- src/utils/utils.js | 1 + 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/components/ClusterOverview/Capacity/Capacity.js b/src/components/ClusterOverview/Capacity/Capacity.js index b8f91045d..896f61ebd 100644 --- a/src/components/ClusterOverview/Capacity/Capacity.js +++ b/src/components/ClusterOverview/Capacity/Capacity.js @@ -11,12 +11,11 @@ import { } from '../../Dashboard/DashboardCard'; import { ClusterOverviewContext } from '../ClusterOverviewContext'; import { CapacityItem } from '../../Dashboard/Capacity/CapacityItem'; -import { formatBytes, formatCores, formatNetTraffic } from '../../../utils'; +import { formatBytes, formatPercents, formatNetTraffic } from '../../../utils'; import { getCapacityStats } from '../../../selectors'; import { CapacityBody } from '../../Dashboard/Capacity/CapacityBody'; export const Capacity = ({ - cpuTotal, cpuUsed, memoryTotal, memoryUsed, @@ -36,10 +35,10 @@ export const Capacity = ({ id="cpu" title="CPU" used={getCapacityStats(cpuUsed)} - total={getCapacityStats(cpuTotal)} - formatValue={formatCores} + total={100} + formatValue={formatPercents} LoadingComponent={LoadingComponent} - isLoading={!(cpuUsed && cpuTotal)} + isLoading={!cpuUsed} /> ({ }); export const capacityStats = { - cpuTotal: getPromResponse(10), cpuUsed: getPromResponse(5), memoryTotal: getPromResponse(10), memoryUsed: getPromResponse(5), @@ -23,5 +22,5 @@ export const capacityStats = { export default { component: Capacity, - props: { capacityStats }, + props: capacityStats, }; diff --git a/src/components/ClusterOverview/Capacity/tests/__snapshots__/Capacity.test.js.snap b/src/components/ClusterOverview/Capacity/tests/__snapshots__/Capacity.test.js.snap index 31b001ae5..62266829c 100644 --- a/src/components/ClusterOverview/Capacity/tests/__snapshots__/Capacity.test.js.snap +++ b/src/components/ClusterOverview/Capacity/tests/__snapshots__/Capacity.test.js.snap @@ -28,11 +28,7 @@ exports[` renders correctly 1`] = ` CPU
-
-
-
+ 95 % available out of 100 %
renders correctly 1`] = ` Memory
-
-
-
+ 5 B available out of 10 B
renders correctly 1`] = ` Storage
-
-
-
+ 5 B available out of 10 B
renders correctly 1`] = ` Network
-
-
-
+ 5 Bps available out of 10 Bps
{ }; export const formatCores = cores => ({ value: cores, unit: 'cores' }); +export const formatPercents = percents => ({ value: percents, unit: '%' }); export const formatNetTraffic = (bytesPerSecond, preferredUnit, fixed = 2) => { preferredUnit =