From 68df65081819138690ef9c3953823046bfd4f5e0 Mon Sep 17 00:00:00 2001 From: Laura Flores Date: Fri, 14 Jan 2022 14:37:10 +0000 Subject: [PATCH] mgr/dashboard/telemetry: add test for formatReport() Tests a scenario where all keys are removed, and one where a key is ignored. Signed-off-by: Laura Flores --- .../telemetry/telemetry.component.spec.ts | 35 +++++++++++++++++++ .../cluster/telemetry/telemetry.component.ts | 22 ++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts index a59b056242075..72215f6176f9a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts @@ -268,6 +268,41 @@ describe('TelemetryComponent', () => { }); }); + it('should remove perf channel fields from a report', () => { + expect( + JSON.parse( + component.formatReportTest({ + perf_counters: {}, + stats_per_pool: {}, + stats_per_pg: {}, + io_rate: {}, + osd_perf_histograms: {}, + mempool: {}, + heap_stats: {}, + rocksdb_stats: {} + }) + ) + ).toStrictEqual({}); + + expect( + JSON.parse( + component.formatReportTest({ + perf_counters: {}, + stats_per_pool: {}, + stats_per_pg: {}, + io_rate: {}, + osd_perf_histograms: {}, + mempool: {}, + heap_stats: {}, + rocksdb_stats: {}, + other: {} + }) + ) + ).toStrictEqual({ + other: {} + }); + }); + it('should submit', () => { component.onSubmit(); const req = httpTesting.expectOne('api/telemetry'); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts index 0ede45731a5c5..050772f3a19cc 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts @@ -128,6 +128,28 @@ export class TelemetryComponent extends CdForm implements OnInit { return JSON.stringify(copy, null, 2); } + formatReportTest(report: object) { + let copy = {}; + copy = JSON.parse(JSON.stringify(report)); + const perf_keys = [ + 'perf_counters', + 'stats_per_pool', + 'stats_per_pg', + 'io_rate', + 'osd_perf_histograms', + 'mempool', + 'heap_stats', + 'rocksdb_stats' + ]; + for (let i = 0; i < perf_keys.length; i++) { + const key = perf_keys[i]; + if (key in copy) { + delete copy[key]; + } + } + return JSON.stringify(copy, null, 2); + } + private createPreviewForm() { const controls = { report: this.formatReport(), -- 2.39.5