Use common helpers and utils for formatting hertz
This commit is contained in:
parent
bf6fb48ca6
commit
a0e59f81ab
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<li>
|
||||
<span class="label"><span class="color-swatch swatch-{{this.colorScale}} swatch-{{this.colorScale}}-{{idx}}" />{{series.name}}</span>
|
||||
{{#if (eq this.metric "cpu")}}
|
||||
<span class="value">{{datum.datum.used}} MHz</span>
|
||||
<span class="value">{{format-scheduled-hertz datum.datum.used}}</span>
|
||||
{{else if (eq this.metric "memory")}}
|
||||
<span class="value">{{format-scheduled-bytes datum.datum.used}}</span>
|
||||
{{else}}
|
||||
|
@ -32,7 +32,7 @@
|
|||
<PrimaryMetric::CurrentValue @chartClass={{this.chartClass}} @percent={{this.data.lastObject.percent}} />
|
||||
<div class="annotation" data-test-absolute-value>
|
||||
{{#if (eq this.metric "cpu")}}
|
||||
<strong>{{this.data.lastObject.used}} MHz</strong> / {{this.reservedAmount}} MHz Total
|
||||
<strong>{{format-scheduled-hertz this.data.lastObject.used}}</strong> / {{format-scheduled-hertz this.reservedAmount}} Total
|
||||
{{else if (eq this.metric "memory")}}
|
||||
<strong>{{format-scheduled-bytes this.data.lastObject.used}}</strong> / {{format-scheduled-bytes this.reservedAmount start="MiB"}} Total
|
||||
{{else}}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<PrimaryMetric::CurrentValue @chartClass={{this.chartClass}} @percent={{this.data.lastObject.percent}} />
|
||||
<div class="annotation" data-test-absolute-value>
|
||||
{{#if (eq this.metric "cpu")}}
|
||||
<strong>{{this.data.lastObject.used}} MHz</strong> / {{this.reservedAmount}} MHz Total
|
||||
<strong>{{format-scheduled-hertz this.data.lastObject.used}}</strong> / {{format-scheduled-hertz this.reservedAmount}} Total
|
||||
{{else if (eq this.metric "memory")}}
|
||||
<strong>{{format-scheduled-bytes this.data.lastObject.used}}</strong> / {{format-scheduled-bytes this.reservedAmount start="MiB"}} Total
|
||||
{{else}}
|
||||
|
|
|
@ -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 [];
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<PrimaryMetric::CurrentValue @chartClass={{this.chartClass}} @percent={{this.data.lastObject.percent}} />
|
||||
<div class="annotation" data-test-absolute-value>
|
||||
{{#if (eq this.metric "cpu")}}
|
||||
<strong>{{this.data.lastObject.used}} MHz</strong> / {{this.reservedAmount}} MHz Total
|
||||
<strong>{{format-scheduled-hertz this.data.lastObject.used}}</strong> / {{format-scheduled-hertz this.reservedAmount}} Total
|
||||
{{else if (eq this.metric "memory")}}
|
||||
<strong>{{format-scheduled-bytes this.data.lastObject.used}}</strong> / {{format-scheduled-bytes this.reservedAmount start="MiB"}} Total
|
||||
{{else}}
|
||||
|
|
16
ui/app/helpers/format-hertz.js
Normal file
16
ui/app/helpers/format-hertz.js
Normal file
|
@ -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);
|
16
ui/app/helpers/format-scheduled-hertz.js
Normal file
16
ui/app/helpers/format-scheduled-hertz.js
Normal file
|
@ -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);
|
|
@ -225,10 +225,10 @@
|
|||
<LinkTo @route="clients.client" @model={{this.preempter.node}} data-test-client-link>{{this.preempter.node.shortId}}</LinkTo>
|
||||
</span>
|
||||
<span class="pair"><span class="term">Reserved CPU</span>
|
||||
<span data-test-allocation-cpu>{{this.preempter.resources.cpu}} MHz</span>
|
||||
<span data-test-allocation-cpu>{{format-scheduled-hertz this.preempter.resources.cpu}}</span>
|
||||
</span>
|
||||
<span class="pair"><span class="term">Reserved Memory</span>
|
||||
<span data-test-allocation-memory>{{this.preempter.resources.memory}} MiB</span>
|
||||
<span data-test-allocation-memory>{{format-scheduled-bytes this.preempter.resources.memory start="MiB"}}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -37,6 +37,6 @@
|
|||
<div class="inline-chart"><AllocationStatusBar @allocationContainer={{this.taskGroup.summary}} @isNarrow={{true}} /></div>
|
||||
</td>
|
||||
<td data-test-task-group-volume>{{if this.taskGroup.volumes.length "Yes"}}</td>
|
||||
<td data-test-task-group-cpu>{{this.taskGroup.reservedCPU}} MHz</td>
|
||||
<td data-test-task-group-mem>{{this.taskGroup.reservedMemory}} MiB</td>
|
||||
<td data-test-task-group-disk>{{this.taskGroup.reservedEphemeralDisk}} MiB</td>
|
||||
<td data-test-task-group-cpu>{{format-scheduled-hertz this.taskGroup.reservedCPU}}</td>
|
||||
<td data-test-task-group-mem>{{format-scheduled-bytes this.taskGroup.reservedMemory start="MiB"}}</td>
|
||||
<td data-test-task-group-disk>{{format-scheduled-bytes this.taskGroup.reservedEphemeralDisk start="MiB"}}</td>
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
{{x-icon "alert-triangle" class="is-warning"}}
|
||||
</span>
|
||||
{{else}}
|
||||
<div class="inline-chart is-small tooltip" role="tooltip" aria-label="{{this.cpu.used}} / {{this.taskStats.reservedCPU}} MHz">
|
||||
<div class="inline-chart is-small tooltip" role="tooltip" aria-label="{{format-hertz this.cpu.used}} / {{format-hertz this.taskStats.reservedCPU}}">
|
||||
<progress
|
||||
class="progress is-info is-small"
|
||||
value="{{this.cpu.percent}}"
|
||||
|
@ -67,7 +67,7 @@
|
|||
{{x-icon "alert-triangle" class="is-warning"}}
|
||||
</span>
|
||||
{{else}}
|
||||
<div class="inline-chart tooltip" role="tooltip" aria-label="{{format-scheduled-bytes this.memory.used}} / {{this.taskStats.reservedMemory}} MiB">
|
||||
<div class="inline-chart tooltip" role="tooltip" aria-label="{{format-scheduled-bytes this.memory.used}} / {{format-scheduled-bytes this.taskStats.reservedMemory}}">
|
||||
<progress
|
||||
class="progress is-danger is-small"
|
||||
value="{{this.memory.percent}}"
|
||||
|
|
|
@ -34,11 +34,11 @@
|
|||
{{/if}}
|
||||
<li>
|
||||
<span class="label">Memory</span>
|
||||
<span class="value">{{allocation.memory}} MiB</span>
|
||||
<span class="value">{{format-scheduled-bytes allocation.memory start="MiB"}}</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="label">CPU</span>
|
||||
<span class="value">{{allocation.cpu}} MHz</span>
|
||||
<span class="value">{{format-scheduled-hertz allocation.cpu}}</span>
|
||||
</li>
|
||||
</ol>
|
||||
{{/let}}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
<strong>{{@datacenter.name}}</strong>
|
||||
<span class="bumper-left">{{this.scheduledAllocations.length}} Allocs</span>
|
||||
<span class="bumper-left">{{@datacenter.nodes.length}} Nodes</span>
|
||||
<span class="bumper-left is-faded">{{this.aggregatedAllocationResources.memory}}/{{this.aggregatedNodeResources.memory}} MiB,
|
||||
{{this.aggregatedAllocationResources.cpu}}/{{this.aggregatedNodeResources.cpu}} MHz</span>
|
||||
<span class="bumper-left is-faded">{{format-bytes this.aggregatedAllocationResources.memory start="MiB"}}/{{format-bytes this.aggregatedNodeResources.memory start="MiB"}},
|
||||
{{format-hertz this.aggregatedAllocationResources.cpu}}/{{format-hertz this.aggregatedNodeResources.cpu}}</span>
|
||||
</div>
|
||||
<div class="boxed-section-body">
|
||||
<FlexMasonry @columns={{if @isSingleColumn 1 2}} @items={{@datacenter.nodes}} as |node|>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
{{/if}}
|
||||
<strong>{{@node.node.name}}</strong>
|
||||
<span class="bumper-left">{{this.count}} Allocs</span>
|
||||
<span class="bumper-left is-faded">{{@node.memory}} MiB, {{@node.cpu}} MHz</span>
|
||||
<span class="bumper-left is-faded">{{format-scheduled-bytes @node.memory start="MiB"}}, {{format-scheduled-hertz @node.cpu}}</span>
|
||||
</p>
|
||||
{{/unless}}
|
||||
<svg
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
<span class="label">Task Group Details</span>
|
||||
|
||||
<span class="pair" data-test-task-group-tasks><span class="term"># Tasks</span> {{this.model.tasks.length}}</span>
|
||||
<span class="pair" data-test-task-group-cpu><span class="term">Reserved CPU</span> {{this.model.reservedCPU}} MHz</span>
|
||||
<span class="pair" data-test-task-group-mem><span class="term">Reserved Memory</span> {{this.model.reservedMemory}} MiB</span>
|
||||
<span class="pair" data-test-task-group-disk><span class="term">Reserved Disk</span> {{this.model.reservedEphemeralDisk}} MiB</span>
|
||||
<span class="pair" data-test-task-group-cpu><span class="term">Reserved CPU</span> {{format-scheduled-hertz this.model.reservedCPU}}</span>
|
||||
<span class="pair" data-test-task-group-mem><span class="term">Reserved Memory</span> {{format-scheduled-bytes this.model.reservedMemory start="MiB"}}</span>
|
||||
<span class="pair" data-test-task-group-disk><span class="term">Reserved Disk</span> {{format-scheduled-bytes this.model.reservedEphemeralDisk start="MiB"}}</span>
|
||||
{{#if this.model.scaling}}
|
||||
<span class="pair" data-test-task-group-min><span class="term">Count Range</span>
|
||||
{{this.model.scaling.min}} to {{this.model.scaling.max}}
|
||||
|
|
|
@ -130,7 +130,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="annotation" data-test-cpu-absolute-value>
|
||||
<strong>{{this.nodeUtilization.totalReservedCPU}} MHz</strong> / {{this.nodeUtilization.totalCPU}} MHz reserved
|
||||
<strong>{{format-scheduled-hertz this.nodeUtilization.totalReservedCPU}}</strong> / {{format-scheduled-hertz this.nodeUtilization.totalCPU}} reserved
|
||||
</div>
|
||||
</div>
|
||||
{{/let}}
|
||||
|
@ -223,7 +223,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="annotation" data-test-cpu-absolute-value>
|
||||
<strong>{{this.totalReservedCPU}} MHz</strong> / {{this.totalCPU}} MHz reserved
|
||||
<strong>{{format-hertz this.totalReservedCPU}}</strong> / {{format-hertz this.totalCPU}} reserved
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
|
|
@ -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}`;
|
||||
}
|
||||
|
|
|
@ -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]];
|
||||
};
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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'
|
||||
);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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`<Das::RecommendationCard @summary={{summary}} />`);
|
||||
await render(hbs`<Das::RecommendationCard @summary={{this.summary}} />`);
|
||||
|
||||
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`<Das::RecommendationCard @summary={{summary}} />`);
|
||||
await render(hbs`<Das::RecommendationCard @summary={{this.summary}} />`);
|
||||
|
||||
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`<Das::RecommendationCard @summary={{summary}} />`);
|
||||
await render(hbs`<Das::RecommendationCard @summary={{this.summary}} />`);
|
||||
|
||||
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`<Das::RecommendationCard @summary={{summary}} />`);
|
||||
await render(hbs`<Das::RecommendationCard @summary={{this.summary}} />`);
|
||||
|
||||
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`<Das::RecommendationCard @summary={{summary}} />`);
|
||||
await render(hbs`<Das::RecommendationCard @summary={{this.summary}} />`);
|
||||
|
||||
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`<Das::RecommendationCard @summary={{summary}} />`);
|
||||
await render(hbs`<Das::RecommendationCard @summary={{this.summary}} />`);
|
||||
|
||||
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`<Das::RecommendationCard @summary={{summary}} />`);
|
||||
await render(hbs`<Das::RecommendationCard @summary={{this.summary}} />`);
|
||||
|
||||
assert.equal(
|
||||
RecommendationCard.narrative.trim(),
|
||||
|
|
|
@ -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`
|
||||
<JobPage::Parts::TaskGroups
|
||||
@job={{job}}
|
||||
@sortProperty={{sortProperty}}
|
||||
@sortDescending={{sortDescending}}
|
||||
@gotoTaskGroup={{gotoTaskGroup}} />
|
||||
@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`
|
||||
<JobPage::Parts::TaskGroups
|
||||
@job={{job}}
|
||||
@sortProperty={{sortProperty}}
|
||||
@sortDescending={{sortDescending}}
|
||||
@gotoTaskGroup={{gotoTaskGroup}} />
|
||||
@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`
|
||||
<JobPage::Parts::TaskGroups
|
||||
@job={{job}}
|
||||
@sortProperty={{sortProperty}}
|
||||
@sortDescending={{sortDescending}}
|
||||
@gotoTaskGroup={{gotoTaskGroup}} />
|
||||
@job={{this.job}}
|
||||
@sortProperty={{this.sortProperty}}
|
||||
@sortDescending={{this.sortDescending}}
|
||||
@gotoTaskGroup={{this.gotoTaskGroup}} />
|
||||
`);
|
||||
|
||||
await click('[data-test-task-group]');
|
||||
|
|
|
@ -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`
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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' },
|
||||
]);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue