Skip to content

Commit 6cb0679

Browse files
committed
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 <nia@redhat.com>
1 parent 2d80e57 commit 6cb0679

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
i18n>Cluster</span>
2828
</div>
2929
<section class="border-top mt-5"
30-
*ngIf="isAlertmanagerConfigured && (crticialActiveAlerts || warningActiveAlerts)">
30+
*ngIf="isAlertmanagerConfigured && (prometheusAlertService.activeCriticalAlerts || prometheusAlertService.activeWarningAlerts)">
3131
<div class="d-flex flex-wrap ms-4 me-4">
3232
<span class="pt-2"
3333
i18n>Alerts</span>
@@ -38,9 +38,9 @@
3838
(click)="toggleAlertsWindow('danger')"
3939
id="dangerAlerts"
4040
i18n-title
41-
*ngIf="crticialActiveAlerts">
41+
*ngIf="prometheusAlertService?.activeCriticalAlerts > 0">
4242
<i [ngClass]="[icons.danger]"></i>
43-
<span>{{ crticialActiveAlerts }}</span>
43+
<span>{{ prometheusAlertService.activeCriticalAlerts }}</span>
4444
</button>
4545

4646
<button class="btn btn-outline-warning rounded-pill ms-2"
@@ -49,9 +49,9 @@
4949
(click)="toggleAlertsWindow('warning')"
5050
id="warningAlerts"
5151
i18n-title
52-
*ngIf="warningActiveAlerts">
52+
*ngIf="prometheusAlertService?.activeWarningAlerts > 0">
5353
<i [ngClass]="[icons.infoCircle]"></i>
54-
<span>{{ warningActiveAlerts }}</span>
54+
<span>{{ prometheusAlertService.activeWarningAlerts }}</span>
5555
</button>
5656

5757
<div class="pt-0 position-right">

src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.spec.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { PrometheusService } from '~/app/shared/api/prometheus.service';
1515
import { CssHelper } from '~/app/shared/classes/css-helper';
1616
import { AlertmanagerAlert } from '~/app/shared/models/prometheus-alerts';
1717
import { FeatureTogglesService } from '~/app/shared/services/feature-toggles.service';
18+
import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
1819
import { SummaryService } from '~/app/shared/services/summary.service';
1920
import { SharedModule } from '~/app/shared/shared.module';
2021
import { configureTestBed } from '~/testing/unit-test-helper';
@@ -161,6 +162,13 @@ describe('Dashbord Component', () => {
161162
schemas: [NO_ERRORS_SCHEMA],
162163
providers: [
163164
{ provide: SummaryService, useClass: SummaryServiceMock },
165+
{
166+
provide: PrometheusAlertService,
167+
useValue: {
168+
activeCriticalAlerts: 2,
169+
activeWarningAlerts: 1
170+
}
171+
},
164172
CssHelper,
165173
PgCategoryService
166174
]
@@ -244,12 +252,12 @@ describe('Dashbord Component', () => {
244252
it('should show the actual alert count on each alerts pill', () => {
245253
fixture.detectChanges();
246254

247-
const successNotification = fixture.debugElement.query(By.css('button[id=warningAlerts] span'));
255+
const warningAlerts = fixture.debugElement.query(By.css('button[id=warningAlerts] span'));
248256

249-
const dangerNotification = fixture.debugElement.query(By.css('button[id=dangerAlerts] span'));
257+
const dangerAlerts = fixture.debugElement.query(By.css('button[id=dangerAlerts] span'));
250258

251-
expect(successNotification.nativeElement.textContent).toBe('1');
252-
expect(dangerNotification.nativeElement.textContent).toBe('2');
259+
expect(warningAlerts.nativeElement.textContent).toBe('1');
260+
expect(dangerAlerts.nativeElement.textContent).toBe('2');
253261
});
254262

255263
it('should show the critical alerts window and its content', () => {
@@ -275,15 +283,16 @@ describe('Dashbord Component', () => {
275283
});
276284

277285
it('should only show the pills when the alerts are not empty', () => {
278-
getAlertsSpy.and.returnValue(of({}));
286+
spyOn(TestBed.inject(PrometheusAlertService), 'activeCriticalAlerts').and.returnValue(0);
287+
spyOn(TestBed.inject(PrometheusAlertService), 'activeWarningAlerts').and.returnValue(0);
279288
fixture.detectChanges();
280289

281-
const successNotification = fixture.debugElement.query(By.css('button[id=warningAlerts]'));
290+
const warningAlerts = fixture.debugElement.query(By.css('button[id=warningAlerts]'));
282291

283-
const dangerNotification = fixture.debugElement.query(By.css('button[id=dangerAlerts]'));
292+
const dangerAlerts = fixture.debugElement.query(By.css('button[id=dangerAlerts]'));
284293

285-
expect(successNotification).toBe(null);
286-
expect(dangerNotification).toBe(null);
294+
expect(warningAlerts).toBe(null);
295+
expect(dangerAlerts).toBe(null);
287296
});
288297

289298
describe('features disabled', () => {

src/pybind/mgr/dashboard/frontend/src/app/ceph/new-dashboard/dashboard/dashboard.component.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import { RefreshIntervalService } from '~/app/shared/services/refresh-interval.service';
2525
import { SummaryService } from '~/app/shared/services/summary.service';
2626
import { PrometheusListHelper } from '~/app/shared/helpers/prometheus-list-helper';
27+
import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
2728

2829
@Component({
2930
selector: 'cd-dashboard',
@@ -53,8 +54,6 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit,
5354
borderClass: string;
5455
alertType: string;
5556
alerts: AlertmanagerAlert[];
56-
crticialActiveAlerts: number;
57-
warningActiveAlerts: number;
5857
healthData: any;
5958
categoryPgAmount: Record<string, number> = {};
6059
totalPgs = 0;
@@ -86,7 +85,8 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit,
8685
private featureToggles: FeatureTogglesService,
8786
private healthService: HealthService,
8887
public prometheusService: PrometheusService,
89-
private refreshIntervalService: RefreshIntervalService
88+
private refreshIntervalService: RefreshIntervalService,
89+
public prometheusAlertService: PrometheusAlertService
9090
) {
9191
super(prometheusService);
9292
this.permissions = this.authStorageService.getPermissions();
@@ -97,7 +97,6 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit,
9797
super.ngOnInit();
9898
this.interval = this.refreshIntervalService.intervalData$.subscribe(() => {
9999
this.getHealth();
100-
this.triggerPrometheusAlerts();
101100
this.getCapacityCardData();
102101
});
103102
this.getPrometheusData(this.lastHourDateObject);
@@ -115,6 +114,7 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit,
115114
}
116115

117116
toggleAlertsWindow(type: string, isToggleButton: boolean = false) {
117+
this.triggerPrometheusAlerts();
118118
if (isToggleButton) {
119119
this.showAlerts = !this.showAlerts;
120120
this.flexHeight = !this.flexHeight;
@@ -163,14 +163,6 @@ export class DashboardComponent extends PrometheusListHelper implements OnInit,
163163
this.prometheusService.ifAlertmanagerConfigured(() => {
164164
this.prometheusService.getAlerts().subscribe((alerts) => {
165165
this.alerts = alerts;
166-
this.crticialActiveAlerts = alerts.filter(
167-
(alert: AlertmanagerAlert) =>
168-
alert.status.state === 'active' && alert.labels.severity === 'critical'
169-
).length;
170-
this.warningActiveAlerts = alerts.filter(
171-
(alert: AlertmanagerAlert) =>
172-
alert.status.state === 'active' && alert.labels.severity === 'warning'
173-
).length;
174166
});
175167
});
176168
}

0 commit comments

Comments
 (0)