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: use task state to determine if task is active #14224

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .changelog/14224.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fixed a bug that caused the allocation details page to display the stats bar chart even if the task was pending.
```
8 changes: 6 additions & 2 deletions ui/app/models/task-state.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed } from '@ember/object';
import { alias, none, and } from '@ember/object/computed';
import { alias, and } from '@ember/object/computed';
import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
import {
Expand All @@ -19,7 +19,6 @@ export default class TaskState extends Fragment {
@attr('date') finishedAt;
@attr('boolean') failed;

@none('finishedAt') isActive;
@and('isActive', 'allocation.isRunning') isRunning;

@computed('task.kind')
Expand Down Expand Up @@ -58,6 +57,11 @@ export default class TaskState extends Fragment {
return classMap[this.state] || 'is-dark';
}

@computed('state')
get isActive() {
return this.state === 'running';
}
Comment on lines +60 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Very smart to map running to active. This will age well!


restart() {
return this.allocation.restart(this.name);
}
Expand Down
49 changes: 38 additions & 11 deletions ui/tests/acceptance/allocation-detail-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,47 @@ module('Acceptance | allocation detail', function (hooks) {
});

test('each task row should list high-level information for the task', async function (assert) {
const task = server.db.taskStates
.where({ allocationId: allocation.id })
.sortBy('name')[0];
const events = server.db.taskEvents.where({ taskStateId: task.id });
const event = events[events.length - 1];
const job = server.create('job', {
groupsCount: 1,
groupTaskCount: 3,
withGroupServices: true,
createAllocations: false,
});

const allocation = server.create('allocation', 'withTaskWithPorts', {
clientStatus: 'running',
jobId: job.id,
});

const taskGroup = server.schema.taskGroups.where({
jobId: allocation.jobId,
name: allocation.taskGroup,
}).models[0];

const jobTask = taskGroup.tasks.models.find((m) => m.name === task.name);
const volumes = jobTask.volumeMounts.map((volume) => ({
name: volume.Volume,
source: taskGroup.volumes[volume.Volume].Source,
}));
// Set the expected task states.
const states = ['running', 'pending', 'dead'];
server.db.taskStates
.where({ allocationId: allocation.id })
.sortBy('name')
.forEach((task, i) => {
server.db.taskStates.update(task.id, { state: states[i] });
});

await Allocation.visit({ id: allocation.id });

Allocation.tasks.forEach((taskRow, i) => {
const task = server.db.taskStates
.where({ allocationId: allocation.id })
.sortBy('name')[i];
const events = server.db.taskEvents.where({ taskStateId: task.id });
Comment on lines +190 to +193
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: excellent use of those Mirage APIs!

const event = events[events.length - 1];

const jobTask = taskGroup.tasks.models.find((m) => m.name === task.name);
const volumes = jobTask.volumeMounts.map((volume) => ({
name: volume.Volume,
source: taskGroup.volumes[volume.Volume].Source,
}));

Allocation.tasks[0].as((taskRow) => {
assert.equal(taskRow.name, task.name, 'Name');
assert.equal(taskRow.state, task.state, 'State');
assert.equal(taskRow.message, event.displayMessage, 'Event Message');
Expand All @@ -185,6 +208,10 @@ module('Acceptance | allocation detail', function (hooks) {
'Event Time'
);

const expectStats = task.state === 'running';
assert.equal(taskRow.hasCpuMetrics, expectStats, 'CPU metrics');
assert.equal(taskRow.hasMemoryMetrics, expectStats, 'Memory metrics');

const volumesText = taskRow.volumes;
volumes.forEach((volume) => {
assert.ok(
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/pages/allocations/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export default create({
time: text('[data-test-time]'),
volumes: text('[data-test-volumes]'),

hasCpuMetrics: isPresent('[data-test-cpu] .inline-chart progress'),
hasMemoryMetrics: isPresent('[data-test-mem] .inline-chart progress'),
hasUnhealthyDriver: isPresent('[data-test-icon="unhealthy-driver"]'),
hasProxyTag: isPresent('[data-test-proxy-tag]'),

Expand Down