From 1be47eb2aea68acffff7c25581e764a12ccdd4e7 Mon Sep 17 00:00:00 2001 From: Tiago Melo Date: Wed, 11 Sep 2019 14:53:23 +0000 Subject: [PATCH] mgr/dashboard: Fix calculation of PG Status percentage We were reading a wrong value for the total of PGs. Fixes: https://tracker.ceph.com/issues/41536 Signed-off-by: Tiago Melo --- .../dashboard/health/health.component.spec.ts | 3 +-- .../ceph/dashboard/health/health.component.ts | 22 +++++-------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts index 8c89000ca37..de7892a07a6 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts @@ -272,7 +272,7 @@ describe('HealthComponent', () => { it('gets no data', () => { const chart = { dataset: [{}], options: {} }; component.preparePgStatus(chart, { - pg_info: { pgs_per_osd: 0 } + pg_info: {} }); expect(chart).toEqual(expectedChart([undefined, undefined, undefined, undefined])); }); @@ -281,7 +281,6 @@ describe('HealthComponent', () => { const chart = { dataset: [{}], options: {} }; component.preparePgStatus(chart, { pg_info: { - pgs_per_osd: 10, statuses: { 'clean+active+scrubbing+nonMappedState': 4, 'clean+active+scrubbing': 2, diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts index c41bc4f9d78..3906e559cf8 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts @@ -148,6 +148,7 @@ export class HealthComponent implements OnInit, OnDestroy { preparePgStatus(chart, data) { const categoryPgAmount = {}; + let totalPgs = 0; _.forEach(data.pg_info.statuses, (pgAmount, pgStatesText) => { const categoryType = this.pgCategoryService.getTypeByStates(pgStatesText); @@ -156,6 +157,7 @@ export class HealthComponent implements OnInit, OnDestroy { categoryPgAmount[categoryType] = 0; } categoryPgAmount[categoryType] += pgAmount; + totalPgs += pgAmount; }); chart.dataset[0].data = this.pgCategoryService @@ -163,22 +165,10 @@ export class HealthComponent implements OnInit, OnDestroy { .map((categoryType) => categoryPgAmount[categoryType]); chart.labels = [ - `${this.i18n('Clean')} (${this.calcPercentage( - categoryPgAmount['clean'], - data.pg_info.pgs_per_osd - )}%)`, - `${this.i18n('Working')} (${this.calcPercentage( - categoryPgAmount['working'], - data.pg_info.pgs_per_osd - )}%)`, - `${this.i18n('Warning')} (${this.calcPercentage( - categoryPgAmount['warning'], - data.pg_info.pgs_per_osd - )}%)`, - `${this.i18n('Unknown')} (${this.calcPercentage( - categoryPgAmount['unknown'], - data.pg_info.pgs_per_osd - )}%)` + `${this.i18n('Clean')} (${this.calcPercentage(categoryPgAmount['clean'], totalPgs)}%)`, + `${this.i18n('Working')} (${this.calcPercentage(categoryPgAmount['working'], totalPgs)}%)`, + `${this.i18n('Warning')} (${this.calcPercentage(categoryPgAmount['warning'], totalPgs)}%)`, + `${this.i18n('Unknown')} (${this.calcPercentage(categoryPgAmount['unknown'], totalPgs)}%)` ]; } -- 2.39.5