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: Fix bug where task logs would suddenly switch to another task's logs #8833

Merged
merged 1 commit into from
Sep 8, 2020
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
16 changes: 9 additions & 7 deletions ui/app/serializers/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export default class AllocationSerializer extends ApplicationSerializer {
// Transform the map-based TaskStates object into an array-based
// TaskState fragment list
const states = hash.TaskStates || {};
hash.TaskStates = Object.keys(states).map(key => {
const state = states[key] || {};
const summary = { Name: key };
Object.keys(state).forEach(stateKey => (summary[stateKey] = state[stateKey]));
summary.Resources = hash.TaskResources && hash.TaskResources[key];
return summary;
});
hash.TaskStates = Object.keys(states)
.sort()
.map(key => {
const state = states[key] || {};
const summary = { Name: key };
Object.keys(state).forEach(stateKey => (summary[stateKey] = state[stateKey]));
summary.Resources = hash.TaskResources && hash.TaskResources[key];
return summary;
});

hash.JobVersion = hash.JobVersion != null ? hash.JobVersion : get(hash, 'Job.Version');

Expand Down
14 changes: 8 additions & 6 deletions ui/app/serializers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,16 @@ export default class Application extends JSONSerializer {

const map = hash[apiKey] || {};

hash[uiKey] = Object.keys(map).map(mapKey => {
const propertiesForKey = map[mapKey] || {};
const convertedMap = { Name: mapKey };
hash[uiKey] = Object.keys(map)
.sort()
.map(mapKey => {
const propertiesForKey = map[mapKey] || {};
const convertedMap = { Name: mapKey };

assign(convertedMap, propertiesForKey);
assign(convertedMap, propertiesForKey);

return convertedMap;
});
return convertedMap;
});
});
}

Expand Down
18 changes: 10 additions & 8 deletions ui/app/serializers/job-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ export default class JobSummary extends ApplicationSerializer {
// TaskGroupSummary fragment list

const fullSummary = hash.Summary || {};
hash.TaskGroupSummaries = Object.keys(fullSummary).map(key => {
const allocStats = fullSummary[key] || {};
const summary = { Name: key };
hash.TaskGroupSummaries = Object.keys(fullSummary)
.sort()
.map(key => {
const allocStats = fullSummary[key] || {};
const summary = { Name: key };

Object.keys(allocStats).forEach(
allocKey => (summary[`${allocKey}Allocs`] = allocStats[allocKey])
);
Object.keys(allocStats).forEach(
allocKey => (summary[`${allocKey}Allocs`] = allocStats[allocKey])
);

return summary;
});
return summary;
});

// Lift the children stats out of the Children object
const childrenStats = get(hash, 'Children');
Expand Down
12 changes: 7 additions & 5 deletions ui/app/serializers/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import ApplicationSerializer from './application';
// excessive copies of the originals which would otherwise just
// be garbage collected.
const unmap = (hash, propKey) =>
Object.keys(hash).map(key => {
const record = hash[key];
record[propKey] = key;
return record;
});
Object.keys(hash)
.sort()
.map(key => {
const record = hash[key];
record[propKey] = key;
return record;
});

export default class Plugin extends ApplicationSerializer {
normalize(typeHash, hash) {
Expand Down
72 changes: 72 additions & 0 deletions ui/tests/unit/serializers/allocation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,78 @@ module('Unit | Serializer | Allocation', function(hooks) {
},
},
},

{
name: 'TaskStates are sorted for stable fragments',
in: {
ID: 'test-allocation',
JobID: 'test-summary',
Name: 'test-summary[1]',
Namespace: 'test-namespace',
TaskGroup: 'test-group',
CreateTime: +sampleDate * 1000000,
ModifyTime: +sampleDate * 1000000,
TaskStates: {
xyz: {
State: 'running',
Failed: false,
},
abc: {
State: 'running',
Failed: false,
},
},
},
out: {
data: {
id: 'test-allocation',
type: 'allocation',
attributes: {
taskGroupName: 'test-group',
name: 'test-summary[1]',
modifyTime: sampleDate,
createTime: sampleDate,
states: [
{
name: 'abc',
state: 'running',
failed: false,
},
{
name: 'xyz',
state: 'running',
failed: false,
},
],
wasPreempted: false,
allocationTaskGroup: null,
},
relationships: {
followUpEvaluation: {
data: null,
},
nextAllocation: {
data: null,
},
previousAllocation: {
data: null,
},
preemptedAllocations: {
data: [],
},
preemptedByAllocation: {
data: null,
},
job: {
data: {
id: '["test-summary","test-namespace"]',
type: 'job',
},
},
},
},
},
},
];

normalizationTestCases.forEach(testCase => {
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/unit/serializers/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ module('Unit | Serializer | Application', function(hooks) {
ID: 'test-test',
Things: [1, 2, 3],
ArrayableMap: {
a: { Order: 1 },
b: { Order: 2 },
a: { Order: 1 },
'c.d': { Order: 3 },
},
OriginalNameArrayableMap: {
Expand Down