Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
ClusterOverview: Improve prometheus query for CPU Capacity
Browse files Browse the repository at this point in the history
and fix Capacity tests.
  • Loading branch information
mareklibra committed Apr 4, 2019
1 parent 13a2eda commit 1251aff
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
11 changes: 4 additions & 7 deletions src/components/ClusterOverview/Capacity/Capacity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}
/>
<CapacityItem
id="memory"
Expand Down Expand Up @@ -74,7 +73,6 @@ export const Capacity = ({
);

Capacity.defaultProps = {
cpuTotal: null,
cpuUsed: null,
memoryTotal: null,
memoryUsed: null,
Expand All @@ -86,7 +84,6 @@ Capacity.defaultProps = {
};

Capacity.propTypes = {
cpuTotal: PropTypes.object,
cpuUsed: PropTypes.object,
memoryTotal: PropTypes.object,
memoryUsed: PropTypes.object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const getPromResponse = value => ({
});

export const capacityStats = {
cpuTotal: getPromResponse(10),
cpuUsed: getPromResponse(5),
memoryTotal: getPromResponse(10),
memoryUsed: getPromResponse(5),
Expand All @@ -23,5 +22,5 @@ export const capacityStats = {

export default {
component: Capacity,
props: { capacityStats },
props: capacityStats,
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ exports[`<Capacity /> renders correctly 1`] = `
CPU
</h2>
<h6>
<div>
<div
class="spinner spinner-md blank-slate-pf-icon"
/>
</div>
95 % available out of 100 %
</h6>
<div>
<div
Expand All @@ -49,11 +45,7 @@ exports[`<Capacity /> renders correctly 1`] = `
Memory
</h2>
<h6>
<div>
<div
class="spinner spinner-md blank-slate-pf-icon"
/>
</div>
5 B available out of 10 B
</h6>
<div>
<div
Expand All @@ -70,11 +62,7 @@ exports[`<Capacity /> renders correctly 1`] = `
Storage
</h2>
<h6>
<div>
<div
class="spinner spinner-md blank-slate-pf-icon"
/>
</div>
5 B available out of 10 B
</h6>
<div>
<div
Expand All @@ -91,11 +79,7 @@ exports[`<Capacity /> renders correctly 1`] = `
Network
</h2>
<h6>
<div>
<div
class="spinner spinner-md blank-slate-pf-icon"
/>
</div>
5 Bps available out of 10 Bps
</h6>
<div>
<div
Expand Down
1 change: 1 addition & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const formatBytes = (bytes, unit, fixed = 2) => {
};

export const formatCores = cores => ({ value: cores, unit: 'cores' });
export const formatPercents = percents => ({ value: percents, unit: '%' });

export const formatNetTraffic = (bytesPerSecond, preferredUnit, fixed = 2) => {
preferredUnit =
Expand Down

0 comments on commit 1251aff

Please sign in to comment.