]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard/telemetry: add test for formatReport() 44523/head
authorLaura Flores <lflores@redhat.com>
Fri, 14 Jan 2022 14:37:10 +0000 (14:37 +0000)
committerLaura Flores <lflores@redhat.com>
Fri, 14 Jan 2022 14:37:10 +0000 (14:37 +0000)
Tests a scenario where all keys are removed, and one
where a key is ignored.

Signed-off-by: Laura Flores <lflores@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts

index a59b05624207590ffbd2a9ddd9accf36f3560a86..72215f6176f9a71c9ccf4c3782d02c367af260a4 100644 (file)
@@ -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');
index 0ede45731a5c519b2d829be0ad0eed6dd552d535..050772f3a19cc7e22d7bef6c18fcecae55791c43 100644 (file)
@@ -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(),