On a cluster with alerting enabled, when alerts are triggered, even if they are silenced, the vertical navigation item (Cluster > Monitoring) displays the total number of alerts, including the ones suppressed.This PR intends to fix this issue.
Fixes: https://tracker.ceph.com/issues/48591
Signed-off-by: Aashish Sharma <aasharma@redhat.com>
(cherry picked from commit
b4e32461f1f8430f223965c245974b2a2dbab3aa)
*ngIf="permissions.prometheus.read">
<a routerLink="/monitoring">
<ng-container i18n>Monitoring</ng-container>
- <small *ngIf="prometheusAlertService.alerts.length > 0"
- class="badge badge-danger">{{ prometheusAlertService.alerts.length }}</small>
+ <small *ngIf="prometheusAlertService.activeAlerts > 0"
+ class="badge badge-danger">{{ prometheusAlertService.activeAlerts }}</small>
</a>
</li>
</ul>
expect(notificationService.show).toHaveBeenCalledTimes(2);
});
});
+
+ describe('alert badge', () => {
+ beforeEach(() => {
+ service = TestBed.get(PrometheusAlertService);
+
+ prometheusService = TestBed.get(PrometheusService);
+ spyOn(prometheusService, 'ifAlertmanagerConfigured').and.callFake((fn) => fn());
+ spyOn(prometheusService, 'getAlerts').and.callFake(() => of(alerts));
+
+ alerts = [
+ prometheus.createAlert('alert0', 'active'),
+ prometheus.createAlert('alert1', 'suppressed'),
+ prometheus.createAlert('alert2', 'suppressed')
+ ];
+ service.refresh();
+ });
+
+ it('should count active alerts', () => {
+ service.refresh();
+ expect(service.activeAlerts).toBe(1);
+ });
+ });
});
private canAlertsBeNotified = false;
alerts: AlertmanagerAlert[] = [];
rules: PrometheusRule[] = [];
+ activeAlerts: number;
constructor(
private alertFormatter: PrometheusAlertFormatter,
if (this.canAlertsBeNotified) {
this.notifyOnAlertChanges(alerts, this.alerts);
}
+ this.activeAlerts = _.reduce<AlertmanagerAlert, number>(
+ this.alerts,
+ (result, alert) => (alert.status.state === 'active' ? ++result : result),
+ 0
+ );
this.alerts = alerts;
this.canAlertsBeNotified = true;
}