From 8de545c1b73fb4ce5b62022bda18287c2a6b1384 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Mon, 17 Sep 2018 16:59:09 -0700 Subject: [PATCH] Add cancelation support to stats trackers --- ui/app/components/primary-metric.js | 5 +++-- ui/app/utils/classes/abstract-stats-tracker.js | 16 ++++++++++++++++ ui/app/utils/classes/allocation-stats-tracker.js | 12 ++++++++++++ ui/app/utils/classes/node-stats-tracker.js | 8 ++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ui/app/components/primary-metric.js b/ui/app/components/primary-metric.js index 7aae5f33d..c6df40daf 100644 --- a/ui/app/components/primary-metric.js +++ b/ui/app/components/primary-metric.js @@ -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(); }, }); diff --git a/ui/app/utils/classes/abstract-stats-tracker.js b/ui/app/utils/classes/abstract-stats-tracker.js index f730936e0..6ffb5ee4d 100644 --- a/ui/app/utils/classes/abstract-stats-tracker.js +++ b/ui/app/utils/classes/abstract-stats-tracker.js @@ -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(), }); diff --git a/ui/app/utils/classes/allocation-stats-tracker.js b/ui/app/utils/classes/allocation-stats-tracker.js index 5053ccea4..ecc88fbdc 100644 --- a/ui/app/utils/classes/allocation-stats-tracker.js +++ b/ui/app/utils/classes/allocation-stats-tracker.js @@ -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'), diff --git a/ui/app/utils/classes/node-stats-tracker.js b/ui/app/utils/classes/node-stats-tracker.js index 3b2702d23..b4ec9603d 100644 --- a/ui/app/utils/classes/node-stats-tracker.js +++ b/ui/app/utils/classes/node-stats-tracker.js @@ -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'),