Add cancelation support to stats trackers

This commit is contained in:
Michael Lange
2018-09-17 16:59:09 -07:00
parent cf57ddc89e
commit 8de545c1b7
4 changed files with 39 additions and 2 deletions

View File

@@ -79,8 +79,8 @@ export default Component.extend({
poller: task(function*() {
do {
yield this.get('tracker.poll').perform();
yield timeout(10);
this.get('tracker.poll').perform();
yield timeout(100);
} while (!Ember.testing);
}),
@@ -92,5 +92,6 @@ export default Component.extend({
willDestroy() {
this.get('poller').cancelAll();
this.get('tracker.signalPause').perform();
},
});

View File

@@ -17,11 +17,20 @@ export default Mixin.create({
);
},
pause() {
assert(
'StatsTrackers need a pause method, which takes no arguments but adds a frame of data at the current timestamp with null as the value'
);
},
// Uses EC as a form of debounce to prevent multiple
// references to the same tracker from flooding the tracker,
// but also avoiding the issue where different places where the
// same tracker is used needs to coordinate.
poll: task(function*() {
// Interrupt any pause attempt
this.get('signalPause').cancelAll();
const url = this.get('url');
assert('Url must be defined', url);
@@ -31,4 +40,11 @@ export default Mixin.create({
yield timeout(2000);
}).drop(),
signalPause: task(function*() {
// wait 2 seconds
yield timeout(2000);
// if no poll called in 2 seconds, pause
this.pause();
}).drop(),
});

View File

@@ -10,6 +10,8 @@ const percent = (numerator, denominator) => {
return numerator / denominator;
};
const empty = ts => ({ timestamp: ts, used: null, percent: null });
const AllocationStatsTracker = EmberObject.extend(AbstractStatsTracker, {
// Set via the stats computed property macro
allocation: null,
@@ -61,6 +63,16 @@ const AllocationStatsTracker = EmberObject.extend(AbstractStatsTracker, {
}
},
pause() {
const ts = new Date();
this.get('memory').pushObject(empty(ts));
this.get('cpu').pushObject(empty(ts));
this.get('tasks').forEach(task => {
task.memory.pushObject(empty(ts));
task.cpu.pushObject(empty(ts));
});
},
// Static figures, denominators for stats
reservedCPU: alias('allocation.taskGroup.reservedCPU'),
reservedMemory: alias('allocation.taskGroup.reservedMemory'),

View File

@@ -10,6 +10,8 @@ const percent = (numerator, denominator) => {
return numerator / denominator;
};
const empty = ts => ({ timestamp: ts, used: null, percent: null });
const NodeStatsTracker = EmberObject.extend(AbstractStatsTracker, {
// Set via the stats computed property macro
node: null,
@@ -39,6 +41,12 @@ const NodeStatsTracker = EmberObject.extend(AbstractStatsTracker, {
// this.notifyPropertyChange('memory');
},
pause() {
const ts = new Date();
this.get('memory').pushObject(empty(ts));
this.get('cpu').pushObject(empty(ts));
},
// Static figures, denominators for stats
reservedCPU: alias('node.resources.cpu'),
reservedMemory: alias('node.resources.memory'),