]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: alert badge includes suppressed alerts 39511/head
authorAashish Sharma <aashishsharma@localhost.localdomain>
Mon, 4 Jan 2021 05:09:16 +0000 (10:39 +0530)
committerAvan Thakkar <athakkar@localhost.localdomain>
Wed, 17 Feb 2021 06:17:36 +0000 (11:47 +0530)
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)

 Conflicts:
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html
      - Adopt the master branch changes.

src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/services/prometheus-alert.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/prometheus-alert.service.ts

index 62331bb9112fe105549c8cce1c71282958444b0b..4aad3b94a837a56f1b1f9365d795d575df41e3ce 100644 (file)
               *ngIf="(isAlertmanagerConfigured || isPrometheusConfigured) && 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>
index 100c8299d12116a44d925b346e1f00e603045078..e3c1471baddada33990c70316c951b1222125281 100644 (file)
@@ -187,4 +187,26 @@ describe('PrometheusAlertService', () => {
       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);
+    });
+  });
 });
index dc1731b92665796168dc31f6acba908040295e8e..365ad007ccb0e7f4e6774919adfdc0165c923ec5 100644 (file)
@@ -17,6 +17,7 @@ export class PrometheusAlertService {
   private canAlertsBeNotified = false;
   alerts: AlertmanagerAlert[] = [];
   rules: PrometheusRule[] = [];
+  activeAlerts: number;
 
   constructor(
     private alertFormatter: PrometheusAlertFormatter,
@@ -60,6 +61,11 @@ export class PrometheusAlertService {
     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;
   }