mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 17:05:43 +03:00
Add cancelation support to stats trackers
This commit is contained in:
@@ -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();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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(),
|
||||
});
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user