Merge pull request #42768 from s0nea/wip-dashboard-suppressed-alerts

mgr/dashboard: don't notify for suppressed alerts
This commit is contained in:
Alfonso Martínez 2021-08-18 08:32:49 +02:00 committed by GitHub
commit 6d7dfefafb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -131,19 +131,25 @@ describe('PrometheusAlertService', () => {
});
it('should notify on alert change', () => {
alerts = [prometheus.createAlert('alert0', 'suppressed')];
alerts = [prometheus.createAlert('alert0', 'resolved')];
service.refresh();
expect(notificationService.show).toHaveBeenCalledWith(
new CdNotificationConfig(
NotificationType.info,
'alert0 (suppressed)',
'alert0 is suppressed ' + prometheus.createLink('http://alert0'),
NotificationType.success,
'alert0 (resolved)',
'alert0 is resolved ' + prometheus.createLink('http://alert0'),
undefined,
'Prometheus'
)
);
});
it('should not notify on change to suppressed', () => {
alerts = [prometheus.createAlert('alert0', 'suppressed')];
service.refresh();
expect(notificationService.show).not.toHaveBeenCalled();
});
it('should notify on a new alert', () => {
alerts = [prometheus.createAlert('alert1'), prometheus.createAlert('alert0')];
service.refresh();

View File

@ -75,7 +75,10 @@ export class PrometheusAlertService {
this.alertFormatter.convertToCustomAlerts(alerts),
this.alertFormatter.convertToCustomAlerts(oldAlerts)
);
const notifications = changedAlerts.map((alert) =>
const suppressedFiltered = _.filter(changedAlerts, (alert) => {
return alert.status !== 'suppressed';
});
const notifications = suppressedFiltered.map((alert) =>
this.alertFormatter.convertAlertToNotification(alert)
);
this.alertFormatter.sendNotifications(notifications);