Skip to content

Commit

Permalink
Correctly sort tasks in alloc stat tracker so the main task takes pre…
Browse files Browse the repository at this point in the history
…cedence
  • Loading branch information
DingoEatingFuzz committed Mar 24, 2021
1 parent 1d8bc39 commit d9426df
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 71 deletions.
9 changes: 4 additions & 5 deletions ui/app/utils/classes/allocation-stats-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ const sortMap = [
return map;
}, {});

const taskPrioritySort = (a, b) => {
return sortMap[a.lifecycleName] - sortMap[b.lifecycleName];
};
const taskPrioritySort = (a, b) => sortMap[a.lifecycleName] - sortMap[b.lifecycleName];

@classic
class AllocationStatsTracker extends EmberObject.extend(AbstractStatsTracker) {
Expand Down Expand Up @@ -124,6 +122,8 @@ class AllocationStatsTracker extends EmberObject.extend(AbstractStatsTracker) {
const bufferSize = this.bufferSize;
const tasks = this.get('allocation.taskGroup.tasks') || [];
return tasks
.slice()
.sort(taskPrioritySort)
.map(task => ({
task: get(task, 'name'),

Expand All @@ -135,8 +135,7 @@ class AllocationStatsTracker extends EmberObject.extend(AbstractStatsTracker) {
// []{ timestamp: Date, used: Number, percent: Number }
cpu: RollingArray(bufferSize),
memory: RollingArray(bufferSize),
}))
.sort(taskPrioritySort);
}));
}
}

Expand Down
135 changes: 69 additions & 66 deletions ui/tests/unit/utils/allocation-stats-tracker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ module('Unit | Util | AllocationStatsTracker', function() {
reservedCPU: 200,
reservedMemory: 512,
tasks: [
{
name: 'service',
reservedCPU: 100,
reservedMemory: 256,
},
{
name: 'log-shipper',
reservedCPU: 50,
reservedMemory: 128,
lifecycleName: 'poststop',
},
{
name: 'service',
reservedCPU: 100,
reservedMemory: 256,
lifecycleName: 'main',
},
{
name: 'sidecar',
reservedCPU: 50,
reservedMemory: 128,
lifecycleName: 'prestart-sidecar',
},
],
},
Expand Down Expand Up @@ -190,8 +193,8 @@ module('Unit | Util | AllocationStatsTracker', function() {
tracker.get('tasks'),
[
{ task: 'service', reservedCPU: 100, reservedMemory: 256, cpu: [], memory: [] },
{ task: 'log-shipper', reservedCPU: 50, reservedMemory: 128, cpu: [], memory: [] },
{ task: 'sidecar', reservedCPU: 50, reservedMemory: 128, cpu: [], memory: [] },
{ task: 'log-shipper', reservedCPU: 50, reservedMemory: 128, cpu: [], memory: [] },
],
'tasks represents the tasks for the allocation with no stats yet'
);
Expand Down Expand Up @@ -242,48 +245,48 @@ module('Unit | Util | AllocationStatsTracker', function() {
],
},
{
task: 'log-shipper',
task: 'sidecar',
reservedCPU: 50,
reservedMemory: 128,
cpu: [
{
timestamp: makeDate(refDate + 10),
used: 26,
percent: 26 / 50,
percentStack: (26 + 51) / (100 + 50 + 50),
percentTotal: 26 / (100 + 50 + 50),
timestamp: makeDate(refDate + 100),
used: 27,
percent: 27 / 50,
percentStack: (27 + 51) / (100 + 50 + 50),
percentTotal: 27 / (100 + 50 + 50),
},
],
memory: [
{
timestamp: makeDate(refDate + 10),
used: 51 * 1024 * 1024,
percent: 51 / 128,
percentStack: (51 + 101) / (256 + 128 + 128),
percentTotal: 51 / (256 + 128 + 128),
timestamp: makeDate(refDate + 100),
used: 52 * 1024 * 1024,
percent: 52 / 128,
percentStack: (52 + 101) / (256 + 128 + 128),
percentTotal: 52 / (256 + 128 + 128),
},
],
},
{
task: 'sidecar',
task: 'log-shipper',
reservedCPU: 50,
reservedMemory: 128,
cpu: [
{
timestamp: makeDate(refDate + 100),
used: 27,
percent: 27 / 50,
percentStack: (27 + 26 + 51) / (100 + 50 + 50),
percentTotal: 27 / (100 + 50 + 50),
timestamp: makeDate(refDate + 10),
used: 26,
percent: 26 / 50,
percentStack: (26 + 27 + 51) / (100 + 50 + 50),
percentTotal: 26 / (100 + 50 + 50),
},
],
memory: [
{
timestamp: makeDate(refDate + 100),
used: 52 * 1024 * 1024,
percent: 52 / 128,
percentStack: (52 + 51 + 101) / (256 + 128 + 128),
percentTotal: 52 / (256 + 128 + 128),
timestamp: makeDate(refDate + 10),
used: 51 * 1024 * 1024,
percent: 51 / 128,
percentStack: (51 + 52 + 101) / (256 + 128 + 128),
percentTotal: 51 / (256 + 128 + 128),
},
],
},
Expand Down Expand Up @@ -351,77 +354,77 @@ module('Unit | Util | AllocationStatsTracker', function() {
],
},
{
task: 'log-shipper',
task: 'sidecar',
reservedCPU: 50,
reservedMemory: 128,
cpu: [
{
timestamp: makeDate(refDate + 10),
used: 26,
percent: 26 / 50,
percentStack: (26 + 51) / (100 + 50 + 50),
percentTotal: 26 / (100 + 50 + 50),
},
{
timestamp: makeDate(refDate + 20),
timestamp: makeDate(refDate + 100),
used: 27,
percent: 27 / 50,
percentStack: (27 + 52) / (100 + 50 + 50),
percentStack: (27 + 51) / (100 + 50 + 50),
percentTotal: 27 / (100 + 50 + 50),
},
],
memory: [
{
timestamp: makeDate(refDate + 10),
used: 51 * 1024 * 1024,
percent: 51 / 128,
percentStack: (51 + 101) / (256 + 128 + 128),
percentTotal: 51 / (256 + 128 + 128),
timestamp: makeDate(refDate + 200),
used: 28,
percent: 28 / 50,
percentStack: (28 + 52) / (100 + 50 + 50),
percentTotal: 28 / (100 + 50 + 50),
},
],
memory: [
{
timestamp: makeDate(refDate + 20),
timestamp: makeDate(refDate + 100),
used: 52 * 1024 * 1024,
percent: 52 / 128,
percentStack: (52 + 102) / (256 + 128 + 128),
percentStack: (52 + 101) / (256 + 128 + 128),
percentTotal: 52 / (256 + 128 + 128),
},
{
timestamp: makeDate(refDate + 200),
used: 53 * 1024 * 1024,
percent: 53 / 128,
percentStack: (53 + 102) / (256 + 128 + 128),
percentTotal: 53 / (256 + 128 + 128),
},
],
},
{
task: 'sidecar',
task: 'log-shipper',
reservedCPU: 50,
reservedMemory: 128,
cpu: [
{
timestamp: makeDate(refDate + 100),
timestamp: makeDate(refDate + 10),
used: 26,
percent: 26 / 50,
percentStack: (26 + 27 + 51) / (100 + 50 + 50),
percentTotal: 26 / (100 + 50 + 50),
},
{
timestamp: makeDate(refDate + 20),
used: 27,
percent: 27 / 50,
percentStack: (27 + 26 + 51) / (100 + 50 + 50),
percentStack: (27 + 28 + 52) / (100 + 50 + 50),
percentTotal: 27 / (100 + 50 + 50),
},
{
timestamp: makeDate(refDate + 200),
used: 28,
percent: 28 / 50,
percentStack: (28 + 27 + 52) / (100 + 50 + 50),
percentTotal: 28 / (100 + 50 + 50),
},
],
memory: [
{
timestamp: makeDate(refDate + 100),
timestamp: makeDate(refDate + 10),
used: 51 * 1024 * 1024,
percent: 51 / 128,
percentStack: (51 + 52 + 101) / (256 + 128 + 128),
percentTotal: 51 / (256 + 128 + 128),
},
{
timestamp: makeDate(refDate + 20),
used: 52 * 1024 * 1024,
percent: 52 / 128,
percentStack: (52 + 51 + 101) / (256 + 128 + 128),
percentStack: (52 + 53 + 102) / (256 + 128 + 128),
percentTotal: 52 / (256 + 128 + 128),
},
{
timestamp: makeDate(refDate + 200),
used: 53 * 1024 * 1024,
percent: 53 / 128,
percentStack: (53 + 52 + 102) / (256 + 128 + 128),
percentTotal: 53 / (256 + 128 + 128),
},
],
},
],
Expand Down

0 comments on commit d9426df

Please sign in to comment.