From a019587de5db673bd3d6fca0eb6ebb02d6a4f85a Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 29 Mar 2021 16:16:48 -0700 Subject: [PATCH] Use common helpers and utils for formatting hertz --- ui/app/components/allocation-stat.js | 7 +++-- .../components/primary-metric/allocation.hbs | 4 +-- ui/app/components/primary-metric/node.hbs | 2 +- ui/app/components/primary-metric/node.js | 15 +++++++-- ui/app/components/primary-metric/task.hbs | 2 +- ui/app/helpers/format-hertz.js | 16 ++++++++++ ui/app/helpers/format-scheduled-hertz.js | 16 ++++++++++ .../allocations/allocation/index.hbs | 4 +-- .../templates/components/task-group-row.hbs | 6 ++-- ui/app/templates/components/task-row.hbs | 4 +-- ui/app/templates/components/topo-viz.hbs | 4 +-- .../components/topo-viz/datacenter.hbs | 4 +-- ui/app/templates/components/topo-viz/node.hbs | 2 +- ui/app/templates/jobs/job/task-group.hbs | 6 ++-- ui/app/templates/topology.hbs | 4 +-- ui/app/utils/resources-diffs.js | 13 +++----- ui/app/utils/units.js | 10 ++++++ ui/tests/acceptance/client-detail-test.js | 5 +-- ui/tests/acceptance/optimize-test.js | 25 +++++++-------- ui/tests/acceptance/plugin-detail-test.js | 5 +-- ui/tests/acceptance/task-group-detail-test.js | 16 +++++++--- ui/tests/acceptance/topology-test.js | 14 +++++++-- ui/tests/acceptance/volume-detail-test.js | 5 +-- .../das/recommendation-card-test.js | 28 +++++++---------- .../job-page/parts/task-groups-test.js | 31 ++++++++++--------- .../components/primary-metric/node-test.js | 3 +- .../components/topo-viz/datacenter-test.js | 13 ++++++-- .../components/topo-viz/node-test.js | 5 +-- ui/tests/unit/utils/units-test.js | 6 ++++ 29 files changed, 176 insertions(+), 99 deletions(-) create mode 100644 ui/app/helpers/format-hertz.js create mode 100644 ui/app/helpers/format-scheduled-hertz.js diff --git a/ui/app/components/allocation-stat.js b/ui/app/components/allocation-stat.js index 22c7a42c8..b53531070 100644 --- a/ui/app/components/allocation-stat.js +++ b/ui/app/components/allocation-stat.js @@ -1,7 +1,7 @@ import Component from '@ember/component'; import { computed } from '@ember/object'; import { alias } from '@ember/object/computed'; -import { formatScheduledBytes, formatBytes } from 'nomad-ui/utils/units'; +import { formatBytes, formatHertz } from 'nomad-ui/utils/units'; import { tagName } from '@ember-decorators/component'; import classic from 'ember-classic-decorator'; @@ -36,13 +36,14 @@ export default class AllocationStat extends Component { get formattedStat() { if (!this.stat) return undefined; if (this.metric === 'memory') return formatBytes(this.stat.used); - return this.stat.used; + if (this.metric === 'cpu') return formatHertz(this.stat.used, 'MHz'); + return undefined; } @computed('metric', 'statsTracker.{reservedMemory,reservedCPU}') get formattedReserved() { if (this.metric === 'memory') return formatBytes(this.statsTracker.reservedMemory, 'MiB'); - if (this.metric === 'cpu') return `${this.statsTracker.reservedCPU} MHz`; + if (this.metric === 'cpu') return formatHertz(this.statsTracker.reservedCPU, 'MHz'); return undefined; } } diff --git a/ui/app/components/primary-metric/allocation.hbs b/ui/app/components/primary-metric/allocation.hbs index 31e8060ce..ed69fc077 100644 --- a/ui/app/components/primary-metric/allocation.hbs +++ b/ui/app/components/primary-metric/allocation.hbs @@ -18,7 +18,7 @@
  • {{series.name}} {{#if (eq this.metric "cpu")}} - {{datum.datum.used}} MHz + {{format-scheduled-hertz datum.datum.used}} {{else if (eq this.metric "memory")}} {{format-scheduled-bytes datum.datum.used}} {{else}} @@ -32,7 +32,7 @@
    {{#if (eq this.metric "cpu")}} - {{this.data.lastObject.used}} MHz / {{this.reservedAmount}} MHz Total + {{format-scheduled-hertz this.data.lastObject.used}} / {{format-scheduled-hertz this.reservedAmount}} Total {{else if (eq this.metric "memory")}} {{format-scheduled-bytes this.data.lastObject.used}} / {{format-scheduled-bytes this.reservedAmount start="MiB"}} Total {{else}} diff --git a/ui/app/components/primary-metric/node.hbs b/ui/app/components/primary-metric/node.hbs index 3d02ee860..c4164ae41 100644 --- a/ui/app/components/primary-metric/node.hbs +++ b/ui/app/components/primary-metric/node.hbs @@ -18,7 +18,7 @@
    {{#if (eq this.metric "cpu")}} - {{this.data.lastObject.used}} MHz / {{this.reservedAmount}} MHz Total + {{format-scheduled-hertz this.data.lastObject.used}} / {{format-scheduled-hertz this.reservedAmount}} Total {{else if (eq this.metric "memory")}} {{format-scheduled-bytes this.data.lastObject.used}} / {{format-scheduled-bytes this.reservedAmount start="MiB"}} Total {{else}} diff --git a/ui/app/components/primary-metric/node.js b/ui/app/components/primary-metric/node.js index 440a3c58b..781d3e38e 100644 --- a/ui/app/components/primary-metric/node.js +++ b/ui/app/components/primary-metric/node.js @@ -4,6 +4,7 @@ import { task, timeout } from 'ember-concurrency'; import { assert } from '@ember/debug'; import { inject as service } from '@ember/service'; import { action, get } from '@ember/object'; +import { formatScheduledBytes, formatScheduledHertz } from 'nomad-ui/utils/units'; export default class NodePrimaryMetric extends Component { @service('stats-trackers-registry') statsTrackersRegistry; @@ -42,12 +43,22 @@ export default class NodePrimaryMetric extends Component { get reservedAnnotations() { if (this.metric === 'cpu' && get(this.args.node, 'reserved.cpu')) { const cpu = this.args.node.reserved.cpu; - return [{ label: `${cpu} MHz reserved`, percent: cpu / this.reservedAmount }]; + return [ + { + label: `${formatScheduledHertz(cpu, 'MHz')} reserved`, + percent: cpu / this.reservedAmount, + }, + ]; } if (this.metric === 'memory' && get(this.args.node, 'reserved.memory')) { const memory = this.args.node.reserved.memory; - return [{ label: `${memory} MiB reserved`, percent: memory / this.reservedAmount }]; + return [ + { + label: `${formatScheduledBytes(memory, 'MiB')} reserved`, + percent: memory / this.reservedAmount, + }, + ]; } return []; diff --git a/ui/app/components/primary-metric/task.hbs b/ui/app/components/primary-metric/task.hbs index e1ec05bed..718315b5d 100644 --- a/ui/app/components/primary-metric/task.hbs +++ b/ui/app/components/primary-metric/task.hbs @@ -12,7 +12,7 @@
    {{#if (eq this.metric "cpu")}} - {{this.data.lastObject.used}} MHz / {{this.reservedAmount}} MHz Total + {{format-scheduled-hertz this.data.lastObject.used}} / {{format-scheduled-hertz this.reservedAmount}} Total {{else if (eq this.metric "memory")}} {{format-scheduled-bytes this.data.lastObject.used}} / {{format-scheduled-bytes this.reservedAmount start="MiB"}} Total {{else}} diff --git a/ui/app/helpers/format-hertz.js b/ui/app/helpers/format-hertz.js new file mode 100644 index 000000000..a9560d540 --- /dev/null +++ b/ui/app/helpers/format-hertz.js @@ -0,0 +1,16 @@ +import Helper from '@ember/component/helper'; +import { formatHertz } from 'nomad-ui/utils/units'; + +/** + * Hertz Formatter + * + * Usage: {{format-hertz hertz}} + * + * Outputs the frequency reduced to the largest supported unit size for which + * the resulting number is larger than one. + */ +function formatHertzHelper([hertz], { start }) { + return formatHertz(hertz, start || 'MHz'); +} + +export default Helper.helper(formatHertzHelper); diff --git a/ui/app/helpers/format-scheduled-hertz.js b/ui/app/helpers/format-scheduled-hertz.js new file mode 100644 index 000000000..9feacc68e --- /dev/null +++ b/ui/app/helpers/format-scheduled-hertz.js @@ -0,0 +1,16 @@ +import Helper from '@ember/component/helper'; +import { formatScheduledHertz } from 'nomad-ui/utils/units'; + +/** + * Scheduled Hertz Formatter + * + * Usage: {{format-scheduled-hertz hertz}} + * + * Outputs the frequency reduced to the resolution the scheduler + * and job spec operate at. + */ +function formatScheduledHertzHelper([hertz], { start }) { + return formatScheduledHertz(hertz, start || 'MHz'); +} + +export default Helper.helper(formatScheduledHertzHelper); diff --git a/ui/app/templates/allocations/allocation/index.hbs b/ui/app/templates/allocations/allocation/index.hbs index 39cf4e7ce..19593ef11 100644 --- a/ui/app/templates/allocations/allocation/index.hbs +++ b/ui/app/templates/allocations/allocation/index.hbs @@ -225,10 +225,10 @@ {{this.preempter.node.shortId}} Reserved CPU - {{this.preempter.resources.cpu}} MHz + {{format-scheduled-hertz this.preempter.resources.cpu}} Reserved Memory - {{this.preempter.resources.memory}} MiB + {{format-scheduled-bytes this.preempter.resources.memory start="MiB"}}
    diff --git a/ui/app/templates/components/task-group-row.hbs b/ui/app/templates/components/task-group-row.hbs index 795e63b93..7a1d20244 100644 --- a/ui/app/templates/components/task-group-row.hbs +++ b/ui/app/templates/components/task-group-row.hbs @@ -37,6 +37,6 @@
    {{if this.taskGroup.volumes.length "Yes"}} -{{this.taskGroup.reservedCPU}} MHz -{{this.taskGroup.reservedMemory}} MiB -{{this.taskGroup.reservedEphemeralDisk}} MiB +{{format-scheduled-hertz this.taskGroup.reservedCPU}} +{{format-scheduled-bytes this.taskGroup.reservedMemory start="MiB"}} +{{format-scheduled-bytes this.taskGroup.reservedEphemeralDisk start="MiB"}} diff --git a/ui/app/templates/components/task-row.hbs b/ui/app/templates/components/task-row.hbs index d3525e1ae..5974051d9 100644 --- a/ui/app/templates/components/task-row.hbs +++ b/ui/app/templates/components/task-row.hbs @@ -47,7 +47,7 @@ {{x-icon "alert-triangle" class="is-warning"}} {{else}} -
  • CPU - {{allocation.cpu}} MHz + {{format-scheduled-hertz allocation.cpu}}
  • {{/let}} diff --git a/ui/app/templates/components/topo-viz/datacenter.hbs b/ui/app/templates/components/topo-viz/datacenter.hbs index cf589c216..fcf16da20 100644 --- a/ui/app/templates/components/topo-viz/datacenter.hbs +++ b/ui/app/templates/components/topo-viz/datacenter.hbs @@ -3,8 +3,8 @@ {{@datacenter.name}} {{this.scheduledAllocations.length}} Allocs {{@datacenter.nodes.length}} Nodes - {{this.aggregatedAllocationResources.memory}}/{{this.aggregatedNodeResources.memory}} MiB, - {{this.aggregatedAllocationResources.cpu}}/{{this.aggregatedNodeResources.cpu}} MHz + {{format-bytes this.aggregatedAllocationResources.memory start="MiB"}}/{{format-bytes this.aggregatedNodeResources.memory start="MiB"}}, + {{format-hertz this.aggregatedAllocationResources.cpu}}/{{format-hertz this.aggregatedNodeResources.cpu}}
    diff --git a/ui/app/templates/components/topo-viz/node.hbs b/ui/app/templates/components/topo-viz/node.hbs index 409466caa..91a047043 100644 --- a/ui/app/templates/components/topo-viz/node.hbs +++ b/ui/app/templates/components/topo-viz/node.hbs @@ -8,7 +8,7 @@ {{/if}} {{@node.node.name}} {{this.count}} Allocs - {{@node.memory}} MiB, {{@node.cpu}} MHz + {{format-scheduled-bytes @node.memory start="MiB"}}, {{format-scheduled-hertz @node.cpu}}

    {{/unless}} Task Group Details # Tasks {{this.model.tasks.length}} - Reserved CPU {{this.model.reservedCPU}} MHz - Reserved Memory {{this.model.reservedMemory}} MiB - Reserved Disk {{this.model.reservedEphemeralDisk}} MiB + Reserved CPU {{format-scheduled-hertz this.model.reservedCPU}} + Reserved Memory {{format-scheduled-bytes this.model.reservedMemory start="MiB"}} + Reserved Disk {{format-scheduled-bytes this.model.reservedEphemeralDisk start="MiB"}} {{#if this.model.scaling}} Count Range {{this.model.scaling.min}} to {{this.model.scaling.max}} diff --git a/ui/app/templates/topology.hbs b/ui/app/templates/topology.hbs index a9b1521d5..ba4044b1b 100644 --- a/ui/app/templates/topology.hbs +++ b/ui/app/templates/topology.hbs @@ -130,7 +130,7 @@
    - {{this.nodeUtilization.totalReservedCPU}} MHz / {{this.nodeUtilization.totalCPU}} MHz reserved + {{format-scheduled-hertz this.nodeUtilization.totalReservedCPU}} / {{format-scheduled-hertz this.nodeUtilization.totalCPU}} reserved
    {{/let}} @@ -223,7 +223,7 @@
    - {{this.totalReservedCPU}} MHz / {{this.totalCPU}} MHz reserved + {{format-hertz this.totalReservedCPU}} / {{format-hertz this.totalCPU}} reserved
    {{/if}} diff --git a/ui/app/utils/resources-diffs.js b/ui/app/utils/resources-diffs.js index fe3e62393..068469f6a 100644 --- a/ui/app/utils/resources-diffs.js +++ b/ui/app/utils/resources-diffs.js @@ -1,6 +1,6 @@ import d3Format from 'd3-format'; -import { reduceBytes } from 'nomad-ui/utils/units'; +import { formatBytes, formatHertz } from 'nomad-ui/utils/units'; const formatPercent = d3Format.format('+.0%'); const sumAggregate = (total, val) => total + val; @@ -86,14 +86,9 @@ class ResourceDiffs { const delta = Math.abs(this.aggregateDiff); if (this.units === 'MiB') { - if (delta === 0) { - return '0 MiB'; - } - - const [memory, units] = reduceBytes(delta * 1024 * 1024); - const formattedMemory = Number.isInteger(memory) ? memory : memory.toFixed(2); - - return `${formattedMemory} ${units}`; + return formatBytes(delta, 'MiB'); + } else if (this.units === 'MHz') { + return formatHertz(delta, 'MHz'); } else { return `${delta} ${this.units}`; } diff --git a/ui/app/utils/units.js b/ui/app/utils/units.js index d535f826c..a4cb24a88 100644 --- a/ui/app/utils/units.js +++ b/ui/app/utils/units.js @@ -16,12 +16,22 @@ const unitReducer = (number = 0, interval, units, maxUnit, startingUnit) => { if (maxUnit && units.indexOf(maxUnit) !== -1) { units = units.slice(0, units.indexOf(maxUnit) + 1); } + + // Reduce negative numbers by temporarily flipping them positive. + const negative = number < 0; + if (negative) { + number *= -1; + } + let unitIndex = 0; while (number >= interval && unitIndex < units.length - 1) { number /= interval; unitIndex++; } + if (negative) { + number *= -1; + } return [number, units[unitIndex]]; }; diff --git a/ui/tests/acceptance/client-detail-test.js b/ui/tests/acceptance/client-detail-test.js index 66ab76c43..890a03982 100644 --- a/ui/tests/acceptance/client-detail-test.js +++ b/ui/tests/acceptance/client-detail-test.js @@ -4,7 +4,7 @@ import { module, test } from 'qunit'; import { setupApplicationTest } from 'ember-qunit'; import { setupMirage } from 'ember-cli-mirage/test-support'; import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; -import { formatBytes } from 'nomad-ui/utils/units'; +import { formatBytes, formatHertz } from 'nomad-ui/utils/units'; import moment from 'moment'; import ClientDetail from 'nomad-ui/tests/pages/clients/detail'; import Clients from 'nomad-ui/tests/pages/clients/list'; @@ -163,9 +163,10 @@ module('Acceptance | client detail', function(hooks) { Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed, 'CPU %' ); + const roundedTicks = Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks); assert.equal( allocationRow.cpuTooltip, - `${Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks)} / ${cpuUsed} MHz`, + `${formatHertz(roundedTicks, 'MHz')} / ${formatHertz(cpuUsed, 'MHz')}`, 'Detailed CPU information is in a tooltip' ); assert.equal( diff --git a/ui/tests/acceptance/optimize-test.js b/ui/tests/acceptance/optimize-test.js index db8856af3..257e3f7a3 100644 --- a/ui/tests/acceptance/optimize-test.js +++ b/ui/tests/acceptance/optimize-test.js @@ -5,6 +5,7 @@ import { setupMirage } from 'ember-cli-mirage/test-support'; import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; import Response from 'ember-cli-mirage/response'; import moment from 'moment'; +import { formatBytes, formatHertz } from 'nomad-ui/utils/units'; import Optimize from 'nomad-ui/tests/pages/optimize'; import Layout from 'nomad-ui/tests/pages/layout'; @@ -153,16 +154,24 @@ module('Acceptance | optimize', function(hooks) { assert.equal( summary.cpu, - cpuDiff ? `${cpuSign}${cpuDiff} MHz ${cpuSign}${cpuDiffPercent}%` : '' + cpuDiff ? `${cpuSign}${formatHertz(cpuDiff, 'MHz')} ${cpuSign}${cpuDiffPercent}%` : '' ); assert.equal( summary.memory, memDiff ? `${memSign}${formattedMemDiff(memDiff)} ${memSign}${memDiffPercent}%` : '' ); + console.log( + summary.aggregateCpu, + cpuDiff, + cpuDiff * currentTaskGroupAllocations.length, + formatHertz(cpuDiff * currentTaskGroupAllocations.length, 'MHz') + ); assert.equal( summary.aggregateCpu, - cpuDiff ? `${cpuSign}${cpuDiff * currentTaskGroupAllocations.length} MHz` : '' + cpuDiff + ? `${cpuSign}${formatHertz(cpuDiff * currentTaskGroupAllocations.length, 'MHz')}` + : '' ); assert.equal( @@ -773,15 +782,5 @@ function formattedMemDiff(memDiff) { const absMemDiff = Math.abs(memDiff); const negativeSign = memDiff < 0 ? '-' : ''; - if (absMemDiff >= 1024) { - const gibDiff = absMemDiff / 1024; - - if (Number.isInteger(gibDiff)) { - return `${negativeSign}${gibDiff} GiB`; - } else { - return `${negativeSign}${gibDiff.toFixed(2)} GiB`; - } - } else { - return `${negativeSign}${absMemDiff} MiB`; - } + return negativeSign + formatBytes(absMemDiff, 'MiB'); } diff --git a/ui/tests/acceptance/plugin-detail-test.js b/ui/tests/acceptance/plugin-detail-test.js index 5e664075f..75824bf8a 100644 --- a/ui/tests/acceptance/plugin-detail-test.js +++ b/ui/tests/acceptance/plugin-detail-test.js @@ -4,7 +4,7 @@ import { setupApplicationTest } from 'ember-qunit'; import { setupMirage } from 'ember-cli-mirage/test-support'; import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; import moment from 'moment'; -import { formatBytes } from 'nomad-ui/utils/units'; +import { formatBytes, formatHertz } from 'nomad-ui/utils/units'; import PluginDetail from 'nomad-ui/tests/pages/storage/plugins/detail'; import Layout from 'nomad-ui/tests/pages/layout'; @@ -125,9 +125,10 @@ module('Acceptance | plugin detail', function(hooks) { Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed, 'CPU %' ); + const roundedTicks = Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks); assert.equal( allocationRow.cpuTooltip, - `${Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks)} / ${cpuUsed} MHz`, + `${formatHertz(roundedTicks, 'MHz')} / ${formatHertz(cpuUsed, 'MHz')}`, 'Detailed CPU information is in a tooltip' ); assert.equal( diff --git a/ui/tests/acceptance/task-group-detail-test.js b/ui/tests/acceptance/task-group-detail-test.js index c4054bf45..e097b27a9 100644 --- a/ui/tests/acceptance/task-group-detail-test.js +++ b/ui/tests/acceptance/task-group-detail-test.js @@ -3,7 +3,12 @@ import { module, test } from 'qunit'; import { setupApplicationTest } from 'ember-qunit'; import { setupMirage } from 'ember-cli-mirage/test-support'; import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; -import { formatBytes } from 'nomad-ui/utils/units'; +import { + formatBytes, + formatHertz, + formatScheduledBytes, + formatScheduledHertz, +} from 'nomad-ui/utils/units'; import TaskGroup from 'nomad-ui/tests/pages/jobs/job/task-group'; import Layout from 'nomad-ui/tests/pages/layout'; import pageSizeSelect from './behaviors/page-size-select'; @@ -84,17 +89,17 @@ module('Acceptance | task group detail', function(hooks) { assert.equal(TaskGroup.tasksCount, `# Tasks ${tasks.length}`, '# Tasks'); assert.equal( TaskGroup.cpu, - `Reserved CPU ${totalCPU} MHz`, + `Reserved CPU ${formatScheduledHertz(totalCPU, 'MHz')}`, 'Aggregated CPU reservation for all tasks' ); assert.equal( TaskGroup.mem, - `Reserved Memory ${totalMemory} MiB`, + `Reserved Memory ${formatScheduledBytes(totalMemory, 'MiB')}`, 'Aggregated Memory reservation for all tasks' ); assert.equal( TaskGroup.disk, - `Reserved Disk ${totalDisk} MiB`, + `Reserved Disk ${formatScheduledBytes(totalDisk, 'MiB')}`, 'Aggregated Disk reservation for all tasks' ); @@ -209,9 +214,10 @@ module('Acceptance | task group detail', function(hooks) { 'CPU %' ); + const roundedTicks = Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks); assert.equal( allocationRow.cpuTooltip, - `${Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks)} / ${cpuUsed} MHz`, + `${formatHertz(roundedTicks, 'MHz')} / ${formatHertz(cpuUsed, 'MHz')}`, 'Detailed CPU information is in a tooltip' ); diff --git a/ui/tests/acceptance/topology-test.js b/ui/tests/acceptance/topology-test.js index 89f0f1953..d98ddc4e0 100644 --- a/ui/tests/acceptance/topology-test.js +++ b/ui/tests/acceptance/topology-test.js @@ -5,7 +5,12 @@ import { setupApplicationTest } from 'ember-qunit'; import { setupMirage } from 'ember-cli-mirage/test-support'; import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; import Topology from 'nomad-ui/tests/pages/topology'; -import { reduceBytes, formatBytes, formatScheduledBytes } from 'nomad-ui/utils/units'; +import { + formatBytes, + formatScheduledBytes, + formatHertz, + formatScheduledHertz, +} from 'nomad-ui/utils/units'; import queryString from 'query-string'; const sumResources = (list, dimension) => @@ -67,7 +72,7 @@ module('Acceptance | topology', function(hooks) { assert.equal( Topology.clusterInfoPanel.cpuAbsoluteValue, - `${reservedCPU} MHz / ${totalCPU} MHz reserved` + `${formatHertz(reservedCPU, 'MHz')} / ${formatHertz(totalCPU, 'MHz')} reserved` ); }); @@ -206,7 +211,10 @@ module('Acceptance | topology', function(hooks) { assert.equal( Topology.nodeInfoPanel.cpuAbsoluteValue, - `${reservedCPU} MHz / ${totalCPU} MHz reserved` + `${formatScheduledHertz(reservedCPU, 'MHz')} / ${formatScheduledHertz( + totalCPU, + 'MHz' + )} reserved` ); await Topology.nodeInfoPanel.visitNode(); diff --git a/ui/tests/acceptance/volume-detail-test.js b/ui/tests/acceptance/volume-detail-test.js index 9ffb1cd7c..6b36b000e 100644 --- a/ui/tests/acceptance/volume-detail-test.js +++ b/ui/tests/acceptance/volume-detail-test.js @@ -4,7 +4,7 @@ import { setupApplicationTest } from 'ember-qunit'; import { setupMirage } from 'ember-cli-mirage/test-support'; import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; import moment from 'moment'; -import { formatBytes } from 'nomad-ui/utils/units'; +import { formatBytes, formatHertz } from 'nomad-ui/utils/units'; import VolumeDetail from 'nomad-ui/tests/pages/storage/volumes/detail'; import Layout from 'nomad-ui/tests/pages/layout'; @@ -140,9 +140,10 @@ module('Acceptance | volume detail', function(hooks) { Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed, 'CPU %' ); + const roundedTicks = Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks); assert.equal( allocationRow.cpuTooltip, - `${Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks)} / ${cpuUsed} MHz`, + `${formatHertz(roundedTicks, 'MHz')} / ${formatHertz(cpuUsed, 'MHz')}`, 'Detailed CPU information is in a tooltip' ); assert.equal( diff --git a/ui/tests/integration/components/das/recommendation-card-test.js b/ui/tests/integration/components/das/recommendation-card-test.js index 2be3d71e5..4145e616a 100644 --- a/ui/tests/integration/components/das/recommendation-card-test.js +++ b/ui/tests/integration/components/das/recommendation-card-test.js @@ -22,13 +22,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { this._super(...arguments); }, - urlFor( - route, - slug, - { - queryParams: { namespace }, - } - ) { + urlFor(route, slug, { queryParams: { namespace } }) { return `${route}:${slug}?namespace=${namespace}`; }, }); @@ -99,7 +93,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { }) ); - await render(hbs``); + await render(hbs``); assert.equal(RecommendationCard.slug.jobName, 'job-name'); assert.equal(RecommendationCard.slug.groupName, 'group-name'); @@ -241,7 +235,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { }) ); - await render(hbs``); + await render(hbs``); assert.notOk(RecommendationCard.togglesTable.toggleAllIsPresent); assert.notOk(RecommendationCard.togglesTable.toggleAllCPU.isPresent); @@ -281,7 +275,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { }) ); - await render(hbs``); + await render(hbs``); await RecommendationCard.togglesTable.tasks[0].cpu.toggle(); await RecommendationCard.togglesTable.tasks[0].memory.toggle(); @@ -320,7 +314,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { }) ); - await render(hbs``); + await render(hbs``); assert.equal(RecommendationCard.totalsTable.recommended.memory.text, '128 MiB'); assert.equal(RecommendationCard.totalsTable.unitDiff.memory, '0 MiB'); @@ -378,7 +372,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { }) ); - await render(hbs``); + await render(hbs``); assert.ok(RecommendationCard.togglesTable.toggleAllMemory.isDisabled); assert.notOk(RecommendationCard.togglesTable.toggleAllMemory.isActive); @@ -447,7 +441,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { }) ); - await render(hbs``); + await render(hbs``); const [cpuRec1, memRec1, cpuRec2, memRec2] = this.summary.recommendations; @@ -486,7 +480,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { assert.equal( RecommendationCard.narrative.trim(), - 'Applying the selected recommendations will save an aggregate 1000 MHz of CPU across 10 allocations.' + 'Applying the selected recommendations will save an aggregate 1 GHz of CPU across 10 allocations.' ); this.summary.toggleRecommendation(cpuRec1); @@ -499,7 +493,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { assert.equal( RecommendationCard.narrative.trim(), - 'Applying the selected recommendations will save an aggregate 1000 MHz of CPU across 10 allocations.' + 'Applying the selected recommendations will save an aggregate 1 GHz of CPU across 10 allocations.' ); this.summary.toggleRecommendation(memRec2); @@ -508,7 +502,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { assert.equal( RecommendationCard.narrative.trim(), - 'Applying the selected recommendations will save an aggregate 1000 MHz of CPU and 1.25 GiB of memory across 10 allocations.' + 'Applying the selected recommendations will save an aggregate 1 GHz of CPU and 1.25 GiB of memory across 10 allocations.' ); }); @@ -574,7 +568,7 @@ module('Integration | Component | das/recommendation-card', function(hooks) { }) ); - await render(hbs``); + await render(hbs``); assert.equal( RecommendationCard.narrative.trim(), diff --git a/ui/tests/integration/components/job-page/parts/task-groups-test.js b/ui/tests/integration/components/job-page/parts/task-groups-test.js index c662aca39..86722b026 100644 --- a/ui/tests/integration/components/job-page/parts/task-groups-test.js +++ b/ui/tests/integration/components/job-page/parts/task-groups-test.js @@ -6,6 +6,7 @@ import sinon from 'sinon'; import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; import { setupRenderingTest } from 'ember-qunit'; import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; +import { formatScheduledHertz, formatScheduledBytes } from 'nomad-ui/utils/units'; module('Integration | Component | job-page/parts/task-groups', function(hooks) { setupRenderingTest(hooks); @@ -46,10 +47,10 @@ module('Integration | Component | job-page/parts/task-groups', function(hooks) { await this.render(hbs` + @job={{this.job}} + @sortProperty={{this.sortProperty}} + @sortDescending={{this.sortDescending}} + @gotoTaskGroup={{this.gotoTaskGroup}} /> `); assert.equal( @@ -80,10 +81,10 @@ module('Integration | Component | job-page/parts/task-groups', function(hooks) { await this.render(hbs` + @job={{this.job}} + @sortProperty={{this.sortProperty}} + @sortDescending={{this.sortDescending}} + @gotoTaskGroup={{this.gotoTaskGroup}} /> `); const taskGroupRow = find('[data-test-task-group]'); @@ -105,17 +106,17 @@ module('Integration | Component | job-page/parts/task-groups', function(hooks) { ); assert.equal( taskGroupRow.querySelector('[data-test-task-group-cpu]').textContent.trim(), - `${taskGroup.get('reservedCPU')} MHz`, + `${formatScheduledHertz(taskGroup.get('reservedCPU'), 'MHz')}`, 'Reserved CPU' ); assert.equal( taskGroupRow.querySelector('[data-test-task-group-mem]').textContent.trim(), - `${taskGroup.get('reservedMemory')} MiB`, + `${formatScheduledBytes(taskGroup.get('reservedMemory'), 'MiB')}`, 'Reserved Memory' ); assert.equal( taskGroupRow.querySelector('[data-test-task-group-disk]').textContent.trim(), - `${taskGroup.get('reservedEphemeralDisk')} MiB`, + `${formatScheduledBytes(taskGroup.get('reservedEphemeralDisk'), 'MiB')}`, 'Reserved Disk' ); }); @@ -145,10 +146,10 @@ module('Integration | Component | job-page/parts/task-groups', function(hooks) { await this.render(hbs` + @job={{this.job}} + @sortProperty={{this.sortProperty}} + @sortDescending={{this.sortDescending}} + @gotoTaskGroup={{this.gotoTaskGroup}} /> `); await click('[data-test-task-group]'); diff --git a/ui/tests/integration/components/primary-metric/node-test.js b/ui/tests/integration/components/primary-metric/node-test.js index 17fbba87d..e444c79ac 100644 --- a/ui/tests/integration/components/primary-metric/node-test.js +++ b/ui/tests/integration/components/primary-metric/node-test.js @@ -6,6 +6,7 @@ import hbs from 'htmlbars-inline-precompile'; import { setupPrimaryMetricMocks, primaryMetric } from './primary-metric'; import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; +import { formatScheduledHertz } from 'nomad-ui/utils/units'; module('Integration | Component | PrimaryMetric::Node', function(hooks) { setupRenderingTest(hooks); @@ -57,7 +58,7 @@ module('Integration | Component | PrimaryMetric::Node', function(hooks) { assert.ok(find('[data-test-annotation]')); assert.equal( find('[data-test-annotation]').textContent.trim(), - `${resource.reserved.cpu} MHz reserved` + `${formatScheduledHertz(resource.reserved.cpu, 'MHz')} reserved` ); }); diff --git a/ui/tests/integration/components/topo-viz/datacenter-test.js b/ui/tests/integration/components/topo-viz/datacenter-test.js index 52da79c89..25e7c3b8f 100644 --- a/ui/tests/integration/components/topo-viz/datacenter-test.js +++ b/ui/tests/integration/components/topo-viz/datacenter-test.js @@ -8,6 +8,7 @@ import { create } from 'ember-cli-page-object'; import sinon from 'sinon'; import faker from 'nomad-ui/mirage/faker'; import topoVizDatacenterPageObject from 'nomad-ui/tests/pages/components/topo-viz/datacenter'; +import { formatBytes, formatHertz } from 'nomad-ui/utils/units'; const TopoVizDatacenter = create(topoVizDatacenterPageObject()); @@ -107,8 +108,16 @@ module('Integration | Component | TopoViz::Datacenter', function(hooks) { assert.ok(TopoVizDatacenter.label.includes(this.datacenter.name)); assert.ok(TopoVizDatacenter.label.includes(`${this.datacenter.nodes.length} Nodes`)); assert.ok(TopoVizDatacenter.label.includes(`${allocs.length} Allocs`)); - assert.ok(TopoVizDatacenter.label.includes(`${memoryReserved}/${memoryTotal} MiB`)); - assert.ok(TopoVizDatacenter.label.includes(`${cpuReserved}/${cpuTotal} MHz`)); + assert.ok( + TopoVizDatacenter.label.includes( + `${formatBytes(memoryReserved, 'MiB')}/${formatBytes(memoryTotal, 'MiB')}` + ) + ); + assert.ok( + TopoVizDatacenter.label.includes( + `${formatHertz(cpuReserved, 'MHz')}/${formatHertz(cpuTotal, 'MHz')}` + ) + ); }); test('when @isSingleColumn is true, the FlexMasonry layout gets one column, otherwise it gets two', async function(assert) { diff --git a/ui/tests/integration/components/topo-viz/node-test.js b/ui/tests/integration/components/topo-viz/node-test.js index e56d40645..a85df060d 100644 --- a/ui/tests/integration/components/topo-viz/node-test.js +++ b/ui/tests/integration/components/topo-viz/node-test.js @@ -8,6 +8,7 @@ import faker from 'nomad-ui/mirage/faker'; import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; import { setupMirage } from 'ember-cli-mirage/test-support'; import topoVisNodePageObject from 'nomad-ui/tests/pages/components/topo-viz/node'; +import { formatScheduledBytes, formatScheduledHertz } from 'nomad-ui/utils/units'; const TopoVizNode = create(topoVisNodePageObject()); @@ -110,8 +111,8 @@ module('Integration | Component | TopoViz::Node', function(hooks) { `${this.node.allocations.filterBy('allocation.isScheduled').length} Allocs` ) ); - assert.ok(TopoVizNode.label.includes(`${this.node.memory} MiB`)); - assert.ok(TopoVizNode.label.includes(`${this.node.cpu} MHz`)); + assert.ok(TopoVizNode.label.includes(`${formatScheduledBytes(this.node.memory, 'MiB')}`)); + assert.ok(TopoVizNode.label.includes(`${formatScheduledHertz(this.node.cpu, 'MHz')}`)); }); test('the status icon indicates when the node is draining', async function(assert) { diff --git a/ui/tests/unit/utils/units-test.js b/ui/tests/unit/utils/units-test.js index 8295c700a..bb2f06e02 100644 --- a/ui/tests/unit/utils/units-test.js +++ b/ui/tests/unit/utils/units-test.js @@ -31,6 +31,7 @@ module('Unit | Util | units#formatBytes', function() { out: '1 TiB', name: 'accepts a starting unit size as an optional argument', }, + { in: [1024 ** 2 * -1], out: '-1 MiB', name: 'negative values are still reduced' }, ]); }); @@ -54,6 +55,7 @@ module('Unit | Util | units#formatScheduledBytes', function() { out: '2,000 MiB', name: 'accepts a starting unit size as an optional argument', }, + { in: [1024 ** 3 * -1], out: '-1,024 MiB', name: 'negative values are still reduced' }, ]); }); @@ -78,6 +80,7 @@ module('Unit | Util | units#formatHertz', function() { out: '2 MHz', name: 'accepts a starting unit size as an optional argument', }, + { in: [1000 ** 3 * -1], out: '-1 GHz', name: 'negative values are still reduced' }, ]); }); @@ -101,6 +104,7 @@ module('Unit | Util | units#formatScheduledHertz', function() { out: '2,000 MHz', name: 'accepts a starting unit size as an optional argument', }, + { in: [1000 ** 3 * -1], out: '-1,000 MHz', name: 'negative values are still reduced' }, ]); }); @@ -123,6 +127,7 @@ module('Unit | Util | units#reduceBytes', function() { out: [1024, 'MiB'], name: 'accepts a starting unit size as an optional argument', }, + { in: [1024 ** 3 * -1], out: [-1, 'GiB'], name: 'negative values are still reduced' }, ]); }); @@ -145,5 +150,6 @@ module('Unit | Util | units#reduceHertz', function() { out: [2, 'GHz'], name: 'accepts a starting unit size as an optional argument', }, + { in: [1000 ** 3 * -1], out: [-1, 'GHz'], name: 'negative values are still reduced' }, ]); });