From 20c3b987c09916b47261b8836668d308c0be19e6 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 29 Mar 2021 22:21:00 -0700 Subject: [PATCH] Aggregate the BANs in the cluster details panel --- ui/app/controllers/topology.js | 17 +++++++++++++++-- ui/app/templates/topology.hbs | 2 +- ui/app/utils/units.js | 2 +- ui/tests/acceptance/optimize-test.js | 6 ------ ui/tests/acceptance/topology-test.js | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ui/app/controllers/topology.js b/ui/app/controllers/topology.js index 193685727fe5..4b9a38b060e9 100644 --- a/ui/app/controllers/topology.js +++ b/ui/app/controllers/topology.js @@ -4,9 +4,12 @@ import { alias } from '@ember/object/computed'; import { inject as service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; import classic from 'ember-classic-decorator'; -import { reduceBytes } from 'nomad-ui/utils/units'; +import { reduceBytes, reduceHertz } from 'nomad-ui/utils/units'; const sumAggregator = (sum, value) => sum + (value || 0); +const formatter = new Intl.NumberFormat(window.navigator.locale || 'en', { + maximumFractionDigits: 2, +}); @classic export default class TopologyControllers extends Controller { @@ -39,7 +42,7 @@ export default class TopologyControllers extends Controller { @computed('totalMemory') get totalMemoryFormatted() { - return reduceBytes(this.totalMemory)[0].toFixed(2); + return formatter.format(reduceBytes(this.totalMemory)[0]); } @computed('totalMemory') @@ -47,6 +50,16 @@ export default class TopologyControllers extends Controller { return reduceBytes(this.totalMemory)[1]; } + @computed('totalCPU') + get totalCPUFormatted() { + return formatter.format(reduceHertz(this.totalCPU, null, 'MHz')[0]); + } + + @computed('totalCPU') + get totalCPUUnits() { + return reduceHertz(this.totalCPU, null, 'MHz')[1]; + } + @computed('scheduledAllocations.@each.allocatedResources') get totalReservedMemory() { const mibs = this.scheduledAllocations diff --git a/ui/app/templates/topology.hbs b/ui/app/templates/topology.hbs index ba4044b1bae5..59f509a4c075 100644 --- a/ui/app/templates/topology.hbs +++ b/ui/app/templates/topology.hbs @@ -205,7 +205,7 @@
-

{{this.totalCPU}} MHz of CPU

+

{{this.totalCPUFormatted}} {{this.totalCPUUnits}} of CPU

diff --git a/ui/app/utils/units.js b/ui/app/utils/units.js index a4cb24a88498..d5c6284fc19e 100644 --- a/ui/app/utils/units.js +++ b/ui/app/utils/units.js @@ -39,7 +39,7 @@ export function reduceBytes(bytes = 0, maxUnitSize, startingUnitSize) { return unitReducer(bytes, 1024, BYTES_UNITS, maxUnitSize, startingUnitSize); } -export function reduceHertz(hertz, maxUnitSize, startingUnitSize) { +export function reduceHertz(hertz = 0, maxUnitSize, startingUnitSize) { return unitReducer(hertz, 1000, HERTZ_UNITS, maxUnitSize, startingUnitSize); } diff --git a/ui/tests/acceptance/optimize-test.js b/ui/tests/acceptance/optimize-test.js index 257e3f7a3a38..d645d6963a00 100644 --- a/ui/tests/acceptance/optimize-test.js +++ b/ui/tests/acceptance/optimize-test.js @@ -161,12 +161,6 @@ module('Acceptance | optimize', function(hooks) { memDiff ? `${memSign}${formattedMemDiff(memDiff)} ${memSign}${memDiffPercent}%` : '' ); - console.log( - summary.aggregateCpu, - cpuDiff, - cpuDiff * currentTaskGroupAllocations.length, - formatHertz(cpuDiff * currentTaskGroupAllocations.length, 'MHz') - ); assert.equal( summary.aggregateCpu, cpuDiff diff --git a/ui/tests/acceptance/topology-test.js b/ui/tests/acceptance/topology-test.js index d98ddc4e07d0..45dd8a99a645 100644 --- a/ui/tests/acceptance/topology-test.js +++ b/ui/tests/acceptance/topology-test.js @@ -67,7 +67,7 @@ module('Acceptance | topology', function(hooks) { assert.equal( Topology.clusterInfoPanel.memoryAbsoluteValue, - `${formatBytes(reservedMem, 'MiB')} / ${formatBytes(totalMem, 'MiB')} reserved` + `${formatBytes(reservedMem * 1024 * 1024)} / ${formatBytes(totalMem * 1024 * 1024)} reserved` ); assert.equal(