mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 00:45:43 +03:00
Correctly sort tasks in alloc stat tracker so the main task takes precedence
This commit is contained in:
@@ -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) {
|
||||
@@ -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'),
|
||||
|
||||
@@ -135,8 +135,7 @@ class AllocationStatsTracker extends EmberObject.extend(AbstractStatsTracker) {
|
||||
// []{ timestamp: Date, used: Number, percent: Number }
|
||||
cpu: RollingArray(bufferSize),
|
||||
memory: RollingArray(bufferSize),
|
||||
}))
|
||||
.sort(taskPrioritySort);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -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'
|
||||
);
|
||||
@@ -241,29 +244,6 @@ module('Unit | Util | AllocationStatsTracker', function() {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
task: 'log-shipper',
|
||||
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),
|
||||
},
|
||||
],
|
||||
memory: [
|
||||
{
|
||||
timestamp: makeDate(refDate + 10),
|
||||
used: 51 * 1024 * 1024,
|
||||
percent: 51 / 128,
|
||||
percentStack: (51 + 101) / (256 + 128 + 128),
|
||||
percentTotal: 51 / (256 + 128 + 128),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
task: 'sidecar',
|
||||
reservedCPU: 50,
|
||||
@@ -273,7 +253,7 @@ module('Unit | Util | AllocationStatsTracker', function() {
|
||||
timestamp: makeDate(refDate + 100),
|
||||
used: 27,
|
||||
percent: 27 / 50,
|
||||
percentStack: (27 + 26 + 51) / (100 + 50 + 50),
|
||||
percentStack: (27 + 51) / (100 + 50 + 50),
|
||||
percentTotal: 27 / (100 + 50 + 50),
|
||||
},
|
||||
],
|
||||
@@ -282,11 +262,34 @@ module('Unit | Util | AllocationStatsTracker', function() {
|
||||
timestamp: makeDate(refDate + 100),
|
||||
used: 52 * 1024 * 1024,
|
||||
percent: 52 / 128,
|
||||
percentStack: (52 + 51 + 101) / (256 + 128 + 128),
|
||||
percentStack: (52 + 101) / (256 + 128 + 128),
|
||||
percentTotal: 52 / (256 + 128 + 128),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
task: 'log-shipper',
|
||||
reservedCPU: 50,
|
||||
reservedMemory: 128,
|
||||
cpu: [
|
||||
{
|
||||
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 + 10),
|
||||
used: 51 * 1024 * 1024,
|
||||
percent: 51 / 128,
|
||||
percentStack: (51 + 52 + 101) / (256 + 128 + 128),
|
||||
percentTotal: 51 / (256 + 128 + 128),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'tasks represents the tasks for the allocation, each with one frame of stats'
|
||||
);
|
||||
@@ -350,43 +353,6 @@ module('Unit | Util | AllocationStatsTracker', function() {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
task: 'log-shipper',
|
||||
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),
|
||||
used: 27,
|
||||
percent: 27 / 50,
|
||||
percentStack: (27 + 52) / (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 + 20),
|
||||
used: 52 * 1024 * 1024,
|
||||
percent: 52 / 128,
|
||||
percentStack: (52 + 102) / (256 + 128 + 128),
|
||||
percentTotal: 52 / (256 + 128 + 128),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
task: 'sidecar',
|
||||
reservedCPU: 50,
|
||||
@@ -396,14 +362,14 @@ module('Unit | Util | AllocationStatsTracker', function() {
|
||||
timestamp: makeDate(refDate + 100),
|
||||
used: 27,
|
||||
percent: 27 / 50,
|
||||
percentStack: (27 + 26 + 51) / (100 + 50 + 50),
|
||||
percentStack: (27 + 51) / (100 + 50 + 50),
|
||||
percentTotal: 27 / (100 + 50 + 50),
|
||||
},
|
||||
{
|
||||
timestamp: makeDate(refDate + 200),
|
||||
used: 28,
|
||||
percent: 28 / 50,
|
||||
percentStack: (28 + 27 + 52) / (100 + 50 + 50),
|
||||
percentStack: (28 + 52) / (100 + 50 + 50),
|
||||
percentTotal: 28 / (100 + 50 + 50),
|
||||
},
|
||||
],
|
||||
@@ -412,18 +378,55 @@ module('Unit | Util | AllocationStatsTracker', function() {
|
||||
timestamp: makeDate(refDate + 100),
|
||||
used: 52 * 1024 * 1024,
|
||||
percent: 52 / 128,
|
||||
percentStack: (52 + 51 + 101) / (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 + 52 + 102) / (256 + 128 + 128),
|
||||
percentStack: (53 + 102) / (256 + 128 + 128),
|
||||
percentTotal: 53 / (256 + 128 + 128),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
task: 'log-shipper',
|
||||
reservedCPU: 50,
|
||||
reservedMemory: 128,
|
||||
cpu: [
|
||||
{
|
||||
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 + 28 + 52) / (100 + 50 + 50),
|
||||
percentTotal: 27 / (100 + 50 + 50),
|
||||
},
|
||||
],
|
||||
memory: [
|
||||
{
|
||||
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 + 53 + 102) / (256 + 128 + 128),
|
||||
percentTotal: 52 / (256 + 128 + 128),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'tasks represents the tasks for the allocation, each with two frames of stats'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user