From 6cb0679aaf28b5f128ca3cae5f962cac50d084af Mon Sep 17 00:00:00 2001 From: Nizamudeen A Date: Wed, 22 Feb 2023 22:22:56 +0530 Subject: [PATCH] mgr/dashboard: improve the logic on the alert viewer only fetch the alerts when you toggle the alert viewer. don't fetch it every 5 second cause its going to cause a heavy toll on the api. Fixes: https://tracker.ceph.com/issues/58867 Signed-off-by: Nizamudeen A --- .../dashboard/dashboard.component.html | 10 +++---- .../dashboard/dashboard.component.spec.ts | 27 ++++++++++++------- .../dashboard/dashboard.component.ts | 16 +++-------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.html index 1c1db13bc56ce..bab03a1704c2c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.html @@ -27,7 +27,7 @@ i18n>Cluster
+ *ngIf="isAlertmanagerConfigured && (prometheusAlertService.activeCriticalAlerts || prometheusAlertService.activeWarningAlerts)">
Alerts @@ -38,9 +38,9 @@ (click)="toggleAlertsWindow('danger')" id="dangerAlerts" i18n-title - *ngIf="crticialActiveAlerts"> + *ngIf="prometheusAlertService?.activeCriticalAlerts > 0"> - {{ crticialActiveAlerts }} + {{ prometheusAlertService.activeCriticalAlerts }}
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.spec.ts index 68ee9b5486c19..fa24090976e12 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.spec.ts @@ -15,6 +15,7 @@ import { PrometheusService } from '~/app/shared/api/prometheus.service'; import { CssHelper } from '~/app/shared/classes/css-helper'; import { AlertmanagerAlert } from '~/app/shared/models/prometheus-alerts'; import { FeatureTogglesService } from '~/app/shared/services/feature-toggles.service'; +import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service'; import { SummaryService } from '~/app/shared/services/summary.service'; import { SharedModule } from '~/app/shared/shared.module'; import { configureTestBed } from '~/testing/unit-test-helper'; @@ -161,6 +162,13 @@ describe('Dashbord Component', () => { schemas: [NO_ERRORS_SCHEMA], providers: [ { provide: SummaryService, useClass: SummaryServiceMock }, + { + provide: PrometheusAlertService, + useValue: { + activeCriticalAlerts: 2, + activeWarningAlerts: 1 + } + }, CssHelper, PgCategoryService ] @@ -244,12 +252,12 @@ describe('Dashbord Component', () => { it('should show the actual alert count on each alerts pill', () => { fixture.detectChanges(); - const successNotification = fixture.debugElement.query(By.css('button[id=warningAlerts] span')); + const warningAlerts = fixture.debugElement.query(By.css('button[id=warningAlerts] span')); - const dangerNotification = fixture.debugElement.query(By.css('button[id=dangerAlerts] span')); + const dangerAlerts = fixture.debugElement.query(By.css('button[id=dangerAlerts] span')); - expect(successNotification.nativeElement.textContent).toBe('1'); - expect(dangerNotification.nativeElement.textContent).toBe('2'); + expect(warningAlerts.nativeElement.textContent).toBe('1'); + expect(dangerAlerts.nativeElement.textContent).toBe('2'); }); it('should show the critical alerts window and its content', () => { @@ -275,15 +283,16 @@ describe('Dashbord Component', () => { }); it('should only show the pills when the alerts are not empty', () => { - getAlertsSpy.and.returnValue(of({})); + spyOn(TestBed.inject(PrometheusAlertService), 'activeCriticalAlerts').and.returnValue(0); + spyOn(TestBed.inject(PrometheusAlertService), 'activeWarningAlerts').and.returnValue(0); fixture.detectChanges(); - const successNotification = fixture.debugElement.query(By.css('button[id=warningAlerts]')); + const warningAlerts = fixture.debugElement.query(By.css('button[id=warningAlerts]')); - const dangerNotification = fixture.debugElement.query(By.css('button[id=dangerAlerts]')); + const dangerAlerts = fixture.debugElement.query(By.css('button[id=dangerAlerts]')); - expect(successNotification).toBe(null); - expect(dangerNotification).toBe(null); + expect(warningAlerts).toBe(null); + expect(dangerAlerts).toBe(null); }); describe('features disabled', () => { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.ts index df4d8775d5b74..8615444665a13 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.ts @@ -24,6 +24,7 @@ import { import { RefreshIntervalService } from '~/app/shared/services/refresh-interval.service'; import { SummaryService } from '~/app/shared/services/summary.service'; import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper'; +import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service'; @Component({ selector: 'cd-dashboard', @@ -53,8 +54,6 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit, borderClass: string; alertType: string; alerts: AlertmanagerAlert[]; - crticialActiveAlerts: number; - warningActiveAlerts: number; healthData: any; categoryPgAmount: Record = {}; totalPgs = 0; @@ -86,7 +85,8 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit, private featureToggles: FeatureTogglesService, private healthService: HealthService, public prometheusService: PrometheusService, - private refreshIntervalService: RefreshIntervalService + private refreshIntervalService: RefreshIntervalService, + public prometheusAlertService: PrometheusAlertService ) { super(prometheusService); this.permissions = this.authStorageService.getPermissions(); @@ -97,7 +97,6 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit, super.ngOnInit(); this.interval = this.refreshIntervalService.intervalData$.subscribe(() => { this.getHealth(); - this.triggerPrometheusAlerts(); this.getCapacityCardData(); }); this.getPrometheusData(this.lastHourDateObject); @@ -115,6 +114,7 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit, } toggleAlertsWindow(type: string, isToggleButton: boolean = false) { + this.triggerPrometheusAlerts(); if (isToggleButton) { this.showAlerts = !this.showAlerts; this.flexHeight = !this.flexHeight; @@ -163,14 +163,6 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit, this.prometheusService.ifAlertmanagerConfigured(() => { this.prometheusService.getAlerts().subscribe((alerts) => { this.alerts = alerts; - this.crticialActiveAlerts = alerts.filter( - (alert: AlertmanagerAlert) => - alert.status.state === 'active' && alert.labels.severity === 'critical' - ).length; - this.warningActiveAlerts = alerts.filter( - (alert: AlertmanagerAlert) => - alert.status.state === 'active' && alert.labels.severity === 'warning' - ).length; }); }); } -- 2.39.5