From 5004cc5fd29267e39e02f2748d14013a07bc6be4 Mon Sep 17 00:00:00 2001 From: Christina Wang Date: Mon, 10 May 2021 17:44:39 +0900 Subject: [PATCH] Add `SUPERVISOR_HARDWARE_METRICS` to config documentation Signed-off-by: Christina Wang --- docs/configurations.md | 1 + test/src/lib/system-info.spec.ts | 49 ++++++++++++++++---------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/docs/configurations.md b/docs/configurations.md index 587ed669..b459756a 100644 --- a/docs/configurations.md +++ b/docs/configurations.md @@ -26,6 +26,7 @@ This list contains configuration variables that can be used with all balena devi | BALENA_HOST_FIREWALL_MODE | string | false | off | Toggle firewall modes between on, off, and auto. | v11.9.1 | | BALENA_HOST_DISCOVERABILITY | boolean | false | true | Enable / Disable Avahi to run which will allow the device to respond to requests such as network scans. | v11.9.2 | | BALENA_HOST_SPLASH_IMAGE | integer | true | /boot/splash/balena-logo-default.png | Allows changing splash screen on boot to user defined file from userspace. | v12.3.0 | +| BALENA_SUPERVISOR_HARDWARE_METRICS | boolean | false | true | Toggle hardware metrics reporting to the cloud, which occurs every 10 seconds when there are changes. Metrics include CPU utilization, CPU temperature, memory usage, and disk space. Useful for devices with bandwith sensitivity. | v12.8.0 | --- diff --git a/test/src/lib/system-info.spec.ts b/test/src/lib/system-info.spec.ts index 6f3f6384..c01e3054 100644 --- a/test/src/lib/system-info.spec.ts +++ b/test/src/lib/system-info.spec.ts @@ -26,41 +26,42 @@ describe('System information', () => { (fsUtils.exec as SinonStub).restore(); }); - describe('filterNonSignificantChanges', () => { + describe('isSignificantChange', () => { it('should correctly filter cpu usage', () => { - expect(sysInfo.isSignificantChange('cpu_usage', 21, 20)).to.equal(false); - - expect(sysInfo.isSignificantChange('cpu_usage', 10, 20)).to.equal(true); + expect(sysInfo.isSignificantChange('cpu_usage', 21, 20)).to.be.false; + expect(sysInfo.isSignificantChange('cpu_usage', 10, 20)).to.be.true; }); it('should correctly filter cpu temperature', () => { - expect(sysInfo.isSignificantChange('cpu_temp', 21, 22)).to.equal(false); - - expect(sysInfo.isSignificantChange('cpu_temp', 10, 20)).to.equal(true); + expect(sysInfo.isSignificantChange('cpu_temp', 21, 22)).to.be.false; + expect(sysInfo.isSignificantChange('cpu_temp', 10, 20)).to.be.true; }); it('should correctly filter memory usage', () => { - expect(sysInfo.isSignificantChange('memory_usage', 21, 22)).to.equal( - false, - ); - - expect(sysInfo.isSignificantChange('memory_usage', 10, 20)).to.equal( - true, - ); + expect(sysInfo.isSignificantChange('memory_usage', 21, 22)).to.be.false; + expect(sysInfo.isSignificantChange('memory_usage', 10, 20)).to.be.true; }); it("should not filter if we didn't have a past value", () => { - expect(sysInfo.isSignificantChange('cpu_usage', undefined, 22)).to.equal( - true, - ); + expect(sysInfo.isSignificantChange('cpu_usage', undefined, 22)).to.be + .true; + expect(sysInfo.isSignificantChange('cpu_temp', undefined, 10)).to.be.true; + expect(sysInfo.isSignificantChange('memory_usage', undefined, 5)).to.be + .true; + }); - expect(sysInfo.isSignificantChange('cpu_temp', undefined, 10)).to.equal( - true, - ); - - expect( - sysInfo.isSignificantChange('memory_usage', undefined, 5), - ).to.equal(true); + it('should not filter if the current value is null', () => { + // When the current value is null, we're sending a null patch to the + // API in response to setting DISABLE_HARDWARE_METRICS to true, so + // we need to include null for all values. None of the individual metrics + // in systemMetrics return null (only number/undefined), so the only + // reason for current to be null is when a null patch is happening. + expect(sysInfo.isSignificantChange('cpu_usage', 15, null as any)).to.be + .true; + expect(sysInfo.isSignificantChange('cpu_temp', 55, null as any)).to.be + .true; + expect(sysInfo.isSignificantChange('memory_usage', 760, null as any)).to + .be.true; }); it('should not filter if the current value is null', () => {