changeset 241:522b92fe4541

Fix system-memory data format inconsistencies Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-October/025353.html
author Andrew Azores <aazores@redhat.com>
date Tue, 10 Oct 2017 16:11:57 -0400
parents d2927fc17bd8
children 2d2b8cfc8091
files mock-api/endpoints/system-memory.endpoint.js src/app/components/system-info/system-memory/system-memory.controller.js src/app/components/system-info/system-memory/system-memory.controller.spec.js
diffstat 3 files changed, 79 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/mock-api/endpoints/system-memory.endpoint.js	Tue Oct 10 15:21:45 2017 -0400
+++ b/mock-api/endpoints/system-memory.endpoint.js	Tue Oct 10 16:11:57 2017 -0400
@@ -21,14 +21,14 @@
       var data = {
         systemId: systemId,
         agentId: 'foo-agentId',
-        timeStamp: new Date().getTime(),
-        total: 16 * gib,
-        free: _.round(Math.random() * (16 * gib / 4)),
-        buffers: 16 * gib / 32,
-        cached: 0,
-        swapTotal: 16 * gib / 2,
-        swapFree: 16 * gib / 2,
-        commitLimit: 0
+        timeStamp: { $numberLong: Date.now().toString() },
+        total: { $numberLong: (16 * gib).toString() },
+        free: { $numberLong: (_.round(Math.random() * (16 * gib / 4))).toString() },
+        buffers: { $numberLong: (16 * gib / 32).toString() },
+        cached: { $numberLong: '0' },
+        swapTotal: { $numberLong: (16 * gib / 2).toString() },
+        swapFree: { $numberLong: (16 * gib / 2).toString() },
+        commitLimit: { $numberLong: '0' }
       };
       response.push(data);
     }
--- a/src/app/components/system-info/system-memory/system-memory.controller.js	Tue Oct 10 15:21:45 2017 -0400
+++ b/src/app/components/system-info/system-memory/system-memory.controller.js	Tue Oct 10 16:11:57 2017 -0400
@@ -31,13 +31,14 @@
 
 class SystemMemoryController {
   constructor (systemMemoryService, $interval, pfUtils,
-    dateFilter, DATE_FORMAT, $translate) {
+    dateFilter, DATE_FORMAT, $translate, metricToNumberFilter) {
     'ngInject';
     this._svc = systemMemoryService;
     this._interval = $interval;
     this._dateFilter = dateFilter;
     this._dateFormat = DATE_FORMAT;
     this._translate = $translate;
+    this._metricToNumber = metricToNumberFilter;
 
     this._refreshRate = 1000;
     this._dataAgeLimit = 30000;
@@ -145,21 +146,21 @@
   _processData (resp) {
     for (let i = resp.data.response.length - 1; i >= 0; i--) {
       let data = resp.data.response[i];
-      let free = data.free;
-      let total = data.total;
+      let free = this._metricToNumber(data.free);
+      let total = this._metricToNumber(data.total);
       let used = total - free;
       let usage = Math.round((used) / total * 100);
 
       let mib = 1024 * 1024;
       // update the memory time series chart
       this.lineConfig.axis.y.max = total / mib;
-      this.lineData.xData.push(data.timeStamp);
+      this.lineData.xData.push(this._metricToNumber(data.timeStamp));
       this.lineData.yData0.push(total / mib);
       this.lineData.yData1.push(free / mib);
       this.lineData.yData2.push(used / mib);
-      this.lineData.yData3.push(data.swapTotal / mib);
-      this.lineData.yData4.push(data.swapFree / mib);
-      this.lineData.yData5.push(data.buffers / mib);
+      this.lineData.yData3.push(this._metricToNumber(data.swapTotal) / mib);
+      this.lineData.yData4.push(this._metricToNumber(data.swapFree) / mib);
+      this.lineData.yData5.push(this._metricToNumber(data.buffers) / mib);
       this._trimData();
 
       // update the memory donut chart
--- a/src/app/components/system-info/system-memory/system-memory.controller.spec.js	Tue Oct 10 15:21:45 2017 -0400
+++ b/src/app/components/system-info/system-memory/system-memory.controller.spec.js	Tue Oct 10 16:11:57 2017 -0400
@@ -100,13 +100,13 @@
           systemId: 'foo-systemId',
           agentId: 'mock-agentId',
           timeStamp: Date.now(),
-          total: 16 * 1024 * 1024,
-          free: 0,
-          buffers: 1 * 1024,
-          cached: 2 * 1024,
-          swapTotal: 3 * 1024,
-          swapFree: 4 * 1024,
-          commitLimit: 0
+          total: { $numberLong: (16 * 1024 * 1024).toString() },
+          free: { $numberLong: '0' },
+          buffers: { $numberLong: (1 * 1024).toString() },
+          cached: { $numberLong: (2 * 1024).toString() },
+          swapTotal: { $numberLong: (3 * 1024).toString() },
+          swapFree: { $numberLong: (4 * 1024).toString() },
+          commitLimit: { $numberLong: '0' }
         }
       }
     });
@@ -248,13 +248,13 @@
               systemId: 'foo-systemId',
               agentId: 'mock-agentId',
               timeStamp: timestamp,
-              total: 16 * 1024 * 1024 * 1024,
-              free: 0,
-              buffers: 1 * 1024 * 1024,
-              cached: 2 * 1024 * 1024,
-              swapTotal: 3 * 1024 * 1024,
-              swapFree: 4 * 1024 * 1024,
-              commitLimit: 0
+              total: { $numberLong: (16 * 1024 * 1024 * 1024).toString() },
+              free: { $numberLong: '0' },
+              buffers: { $numberLong: (1 * 1024 * 1024).toString() },
+              cached: { $numberLong: (2 * 1024 * 1024).toString() },
+              swapTotal: { $numberLong: (3 * 1024 * 1024).toString() },
+              swapFree: { $numberLong: (4 * 1024 * 1024).toString() },
+              commitLimit: { $numberLong: '0' }
             }
           ]
         }
@@ -296,26 +296,26 @@
             {
               systemId: 'foo-systemId',
               agentId: 'mock-agentId',
-              timeStamp: timestampA,
-              total: 16384,
-              free: 0,
-              buffers: 0,
-              cached: 0,
-              swapTotal: 0,
-              swapFree: 0,
-              commitLimit: 0
+              timeStamp: { $numberLong: timestampA.toString() },
+              total: { $numberLong: '16384' },
+              free: { $numberLong: '0' },
+              buffers: { $numberLong: '0' },
+              cached: { $numberLong: '0' },
+              swapTotal: { $numberLong: '0' },
+              swapFree: { $numberLong: '0' },
+              commitLimit: { $numberLong: '0' }
             },
             {
               systemId: 'foo-systemId',
               agentId: 'mock-agentId',
-              timeStamp: timestampB,
-              total: 16384,
-              free: 0,
-              buffers: 0,
-              cached: 0,
-              swapTotal: 0,
-              swapFree: 0,
-              commitLimit: 0
+              timeStamp: { $numberLong: timestampB.toString() },
+              total: { $numberLong: '16384' },
+              free: { $numberLong: '0' },
+              buffers: { $numberLong: '0' },
+              cached: { $numberLong: '0' },
+              swapTotal: { $numberLong: '0' },
+              swapFree: { $numberLong: '0' },
+              commitLimit: { $numberLong: '0' }
             }
           ]
         }
@@ -334,14 +334,14 @@
             {
               systemId: 'foo-systemId',
               agentId: 'mock-agentId',
-              timeStamp: timestampA,
-              total: 16384,
-              free: 0,
-              buffers: 0,
-              cached: 0,
-              swapTotal: 0,
-              swapFree: 0,
-              commitLimit: 0
+              timeStamp: { $numberLong: timestampA.toString() },
+              total: { $numberLong: '16384' },
+              free: { $numberLong: '0' },
+              buffers: { $numberLong: '0' },
+              cached: { $numberLong: '0' },
+              swapTotal: { $numberLong: '0' },
+              swapFree: { $numberLong: '0' },
+              commitLimit: { $numberLong: '0' }
             }
           ]
         }
@@ -352,14 +352,14 @@
             {
               systemId: 'foo-systemId',
               agentId: 'mock-agentId',
-              timeStamp: timestampB,
-              total: 16384,
-              free: 0,
-              buffers: 0,
-              cached: 0,
-              swapTotal: 0,
-              swapFree: 0,
-              commitLimit: 0
+              timeStamp: { $numberLong: timestampB.toString() },
+              total: { $numberLong: '16384' },
+              free: { $numberLong: '0' },
+              buffers: { $numberLong: '0' },
+              cached: { $numberLong: '0' },
+              swapTotal: { $numberLong: '0' },
+              swapFree: { $numberLong: '0' },
+              commitLimit: { $numberLong: '0' }
             }
           ]
         }
@@ -372,21 +372,21 @@
     it('should remove data that is older than dataAgeLimit', () => {
       controller.dataAgeLimit = 30000;
       let timestampA = Date.now() - 30001;
-      let timestampB = Date.now;
+      let timestampB = Date.now();
       controller._processData({
         data: {
           response: [
             {
               systemId: 'foo-systemId',
               agentId: 'mock-agentId',
-              timeStamp: timestampA,
-              total: 16384,
-              free: 0,
-              buffers: 0,
-              cached: 0,
-              swapTotal: 0,
-              swapFree: 0,
-              commitLimit: 0
+              timeStamp: { $numberLong: timestampA.toString() },
+              total: { $numberLong: '16384' },
+              free: { $numberLong: '0' },
+              buffers: { $numberLong: '0' },
+              cached: { $numberLong: '0' },
+              swapTotal: { $numberLong: '0' },
+              swapFree: { $numberLong: '0' },
+              commitLimit: { $numberLong: '0' }
             }
           ]
         }
@@ -397,14 +397,14 @@
             {
               systemId: 'foo-systemId',
               agentId: 'mock-agentId',
-              timeStamp: timestampB,
-              total: 16384,
-              free: 0,
-              buffers: 0,
-              cached: 0,
-              swapTotal: 0,
-              swapFree: 0,
-              commitLimit: 0
+              timeStamp: { $numberLong: timestampB.toString() },
+              total: { $numberLong: '16384' },
+              free: { $numberLong: '0' },
+              buffers: { $numberLong: '0' },
+              cached: { $numberLong: '0' },
+              swapTotal: { $numberLong: '0' },
+              swapFree: { $numberLong: '0' },
+              commitLimit: { $numberLong: '0' }
             }
           ]
         }