Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Add optional memory max to task details ribbon #10459

Merged
merged 7 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ IMPROVEMENTS:
* networking: Added support for interpolating host network names with node attributes. [[GH-10196](https://github.com/hashicorp/nomad/issues/10196)]
* nomad/structs: Removed deprecated Node.Drain field, added API extensions to restore it [[GH-10202](https://github.com/hashicorp/nomad/issues/10202)]
* ui: Added a job reversion button [[GH-10336](https://github.com/hashicorp/nomad/pull/10336)]
* ui: Added memory maximum to task group ribbon [[GH-10459](https://github.com/hashicorp/nomad/pull/10459)]
* ui: Updated global search to use fuzzy search API [[GH-10412](https://github.com/hashicorp/nomad/pull/10412)]

BUG FIXES:
Expand Down
1 change: 1 addition & 0 deletions ui/app/models/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { fragmentArray } from 'ember-data-model-fragments/attributes';
export default class Resources extends Fragment {
@attr('number') cpu;
@attr('number') memory;
@attr('number') memoryMax;
@attr('number') disk;
@attr('number') iops;
@fragmentArray('network', { defaultValue: () => [] }) networks;
Expand Down
7 changes: 7 additions & 0 deletions ui/app/models/task-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export default class TaskGroup extends Fragment {
@sumAggregation('tasks', 'reservedMemory') reservedMemory;
@sumAggregation('tasks', 'reservedDisk') reservedDisk;

@computed('tasks.@each.{reservedMemory,reservedMemoryMax}')
get reservedMemoryMax() {
return this.get('tasks')
.map(t => t.get('reservedMemoryMax') || t.get('reservedMemory'))
.reduce((sum, count) => sum + count, 0);
}

@attr('number') reservedEphemeralDisk;

@computed('job.latestFailureEvaluation.failedTGAllocs.[]', 'name')
Expand Down
1 change: 1 addition & 0 deletions ui/app/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class Task extends Fragment {
}

@attr('number') reservedMemory;
@attr('number') reservedMemoryMax;
@attr('number') reservedCPU;
@attr('number') reservedDisk;
@attr('number') reservedEphemeralDisk;
Expand Down
1 change: 1 addition & 0 deletions ui/app/serializers/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class Task extends ApplicationSerializer {
const resources = hash.Resources;
if (resources) {
hash.ReservedMemory = resources.MemoryMB;
hash.ReservedMemoryMax = resources.MemoryMaxMB;
hash.ReservedCPU = resources.CPU;
hash.ReservedDisk = resources.DiskMB;
hash.ReservedEphemeralDisk = hash.EphemeralDisk.SizeMB;
Expand Down
8 changes: 7 additions & 1 deletion ui/app/templates/jobs/job/task-group.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@

<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> {{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-mem>
<span class="term">Reserved Memory</span>
{{format-scheduled-bytes this.model.reservedMemory start="MiB"}}
{{#if (gt this.model.reservedMemoryMax this.model.reservedMemory)}}
({{format-scheduled-bytes this.model.reservedMemoryMax start="MiB"}} Max)
{{/if}}
</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>
Expand Down
11 changes: 10 additions & 1 deletion ui/mirage/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const HOSTS = provide(100, () => {
export const STORAGE_PROVIDERS = ['ebs', 'zfs', 'nfs', 'cow', 'moo'];

export function generateResources(options = {}) {
return {
const resources = {
Cpu: {
CpuShares: options.CPU || faker.helpers.randomize(CPU_RESERVATIONS),
},
Expand All @@ -37,6 +37,15 @@ export function generateResources(options = {}) {
Networks: generateNetworks(options.networks),
Ports: generatePorts(options.networks),
};

if (faker.random.boolean()) {
const higherMemoryReservations = MEMORY_RESERVATIONS.filter(mb => mb > resources.Memory.MemoryMB);
resources.Memory.MemoryMaxMB = faker.helpers.randomize(higherMemoryReservations) || resources.Memory.MemoryMB + 1;
} else {
resources.Memory.MemoryMaxMB = 0;
}

return resources;
}

export function generateNetworks(options = {}) {
Expand Down
1 change: 1 addition & 0 deletions ui/mirage/factories/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default Factory.extend({
return {
CPU: resources.Cpu.CpuShares,
MemoryMB: resources.Memory.MemoryMB,
MemoryMaxMB: resources.Memory.MemoryMaxMB,
DiskMB: resources.Disk.DiskMB,
};
},
Expand Down
10 changes: 9 additions & 1 deletion ui/tests/acceptance/task-group-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module('Acceptance | task group detail', function(hooks) {
test('/jobs/:id/:task-group should list high-level metrics for the allocation', async function(assert) {
const totalCPU = tasks.mapBy('resources.CPU').reduce(sum, 0);
const totalMemory = tasks.mapBy('resources.MemoryMB').reduce(sum, 0);
const totalMemoryMax = tasks.map(t => t.resources.MemoryMaxMB || t.resources.MemoryMB).reduce(sum, 0);
const totalDisk = taskGroup.ephemeralDisk.SizeMB;

await TaskGroup.visit({ id: job.id, name: taskGroup.name });
Expand All @@ -92,9 +93,16 @@ module('Acceptance | task group detail', function(hooks) {
`Reserved CPU ${formatScheduledHertz(totalCPU, 'MHz')}`,
'Aggregated CPU reservation for all tasks'
);

let totalMemoryMaxAddendum = '';

if (totalMemoryMax > totalMemory) {
totalMemoryMaxAddendum = ` (${formatScheduledBytes(totalMemoryMax, 'MiB')} Max)`;
}

assert.equal(
TaskGroup.mem,
`Reserved Memory ${formatScheduledBytes(totalMemory, 'MiB')}`,
`Reserved Memory ${formatScheduledBytes(totalMemory, 'MiB')}${totalMemoryMaxAddendum}`,
'Aggregated Memory reservation for all tasks'
);
assert.equal(
Expand Down