Skip to content

Commit 280d8f6

Browse files
author
Abhishek Desai
committed
mgr/dashboard : Hide suppressed alert on landing page
fixes : https://tracker.ceph.com/issues/72944 Signed-off-by: Abhishek Desai <[email protected]>
1 parent c454342 commit 280d8f6

File tree

7 files changed

+56
-19
lines changed

7 files changed

+56
-19
lines changed

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<cd-table
1212
[data]="prometheusAlertService.alerts"
1313
[columns]="columns"
14+
[extraFilterableColumns]="filters"
1415
identifier="fingerprint"
1516
[forceIdentifier]="true"
1617
[customCss]="customCss"

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/active-alert-list/active-alert-list.component.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { CdTableAction } from '~/app/shared/models/cd-table-action';
88
import { CdTableColumn } from '~/app/shared/models/cd-table-column';
99
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
1010
import { Permission } from '~/app/shared/models/permissions';
11+
import { AlertState } from '~/app/shared/models/prometheus-alerts';
1112
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
1213
import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
1314
import { URLBuilderService } from '~/app/shared/services/url-builder.service';
@@ -31,6 +32,21 @@ export class ActiveAlertListComponent extends PrometheusListHelper implements On
3132
icons = Icons;
3233
expandedInnerRow: any;
3334

35+
filters: CdTableColumn[] = [
36+
{
37+
name: $localize`State`,
38+
prop: 'status.state',
39+
filterOptions: [$localize`All`, $localize`Active`, $localize`Suppressed`],
40+
filterInitValue: $localize`Active`,
41+
filterPredicate: (row, value) => {
42+
if (value === 'Active') return row.status?.state === AlertState.ACTIVE;
43+
else if (value === 'Suppressed') return row.status?.state === AlertState.SUPPRESSED;
44+
if (value === 'All') return true;
45+
return false;
46+
}
47+
}
48+
];
49+
3450
constructor(
3551
// NotificationsComponent will refresh all alerts every 5s (No need to do it here as well)
3652
private authStorageService: AuthStorageService,

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/silence-form/silence-form.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('SilenceFormComponent', () => {
102102

103103
prometheus = new PrometheusHelper();
104104
prometheusService = TestBed.inject(PrometheusService);
105-
spyOn(prometheusService, 'getGroupedAlerts').and.callFake(() => {
105+
spyOn(prometheusService, 'getAlerts').and.callFake(() => {
106106
const name = _.split(router.url, '/').pop();
107107
return of([prometheus.createAlert(name)]);
108108
});
@@ -285,7 +285,7 @@ describe('SilenceFormComponent', () => {
285285
params = { id: 'alert0' };
286286
expectMode('alertAdd', false, false, 'Create');
287287
expect(prometheusService.getSilences).not.toHaveBeenCalled();
288-
expect(prometheusService.getGroupedAlerts).toHaveBeenCalled();
288+
expect(prometheusService.getAlerts).toHaveBeenCalled();
289289
expect(component.matchers).toEqual([createMatcher('alertname', 'alert0', false)]);
290290
expect(component.matcherMatch).toEqual({
291291
cssClass: 'has-success',

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/prometheus/silence-form/silence-form.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
AlertmanagerSilenceMatcherMatch
2020
} from '~/app/shared/models/alertmanager-silence';
2121
import { Permission } from '~/app/shared/models/permissions';
22-
import { GroupAlertmanagerAlert, PrometheusRule } from '~/app/shared/models/prometheus-alerts';
22+
import { AlertmanagerAlert, PrometheusRule } from '~/app/shared/models/prometheus-alerts';
2323
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
2424
import { ModalService } from '~/app/shared/services/modal.service';
2525
import { NotificationService } from '~/app/shared/services/notification.service';
@@ -225,7 +225,7 @@ export class SilenceFormComponent {
225225
}
226226
});
227227
} else {
228-
this.prometheusService.getGroupedAlerts().subscribe((alerts) => {
228+
this.prometheusService.getAlerts().subscribe((alerts) => {
229229
const alert = _.find(alerts, ['fingerprint', params.id]);
230230
if (!_.isUndefined(alert)) {
231231
this.fillFormByAlert(alert);
@@ -258,7 +258,7 @@ export class SilenceFormComponent {
258258
this.form.updateValueAndValidity();
259259
}
260260

261-
private fillFormByAlert(alert: GroupAlertmanagerAlert) {
261+
private fillFormByAlert(alert: AlertmanagerAlert) {
262262
const labels = alert.labels;
263263
this.setMatcher({
264264
name: 'alertname',

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@
288288
<ng-container *ngFor="let alert of prometheusAlertService.alerts; let i = index; trackBy: trackByFn">
289289
<div [ngClass]="['border-'+alertClass[alert.labels.severity]]"
290290
*ngIf="alert.status.state === 'active' &&
291-
alert.labels.severity === alertType ||
292-
!alertType">
291+
(alert.labels.severity === alertType ||
292+
!alertType)">
293293
<div class="card tc_alerts border-0 pt-3">
294294
<div class="row no-gutters ps-2">
295295
<div class="col-sm-1 text-center">
@@ -309,6 +309,7 @@ <h6 class="card-title bold">{{ alert.labels.alertname }}</h6>
309309
[title]="alert.startsAt | cdDate"
310310
i18n>Active since: {{ alert.startsAt | relativeDate }}</small>
311311
<small class="alert_count"
312+
*ngIf="alert.alert_count > 1"
312313
[title]="alert.alert_count"
313314
i18n>Total occurrences: {{ alert.alert_count }}</small>
314315
</p>

src/pybind/mgr/dashboard/frontend/src/app/shared/models/prometheus-alerts.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
type AlertState = 'active' | 'suppressed' | 'resolved' | 'unprocessed';
2+
13
export class PrometheusAlertLabels {
24
alertname: string;
35
instance: string;
@@ -48,7 +50,7 @@ export class PrometheusRule {
4850

4951
export class AlertmanagerAlert extends CommonAlertmanagerAlert {
5052
status: {
51-
state: 'unprocessed' | 'active' | 'suppressed';
53+
state: AlertState;
5254
silencedBy: null | string[];
5355
inhibitedBy: null | string[];
5456
};
@@ -84,10 +86,17 @@ export class AlertmanagerNotification {
8486
}
8587

8688
export class PrometheusCustomAlert {
87-
status: 'resolved' | 'unprocessed' | 'active' | 'suppressed';
89+
status: AlertState;
8890
name: string;
8991
url: string;
9092
description: string;
9193
fingerprint?: string | boolean;
9294
severity?: string;
9395
}
96+
97+
export const AlertState = {
98+
ACTIVE: 'active' as AlertState,
99+
SUPPRESSED: 'suppressed' as AlertState,
100+
RESOLVED: 'resolved' as AlertState,
101+
UNPROCCESSED: 'unprocessed' as AlertState
102+
};

src/pybind/mgr/dashboard/frontend/src/app/shared/services/prometheus-alert.service.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
AlertmanagerAlert,
88
PrometheusCustomAlert,
99
PrometheusRule,
10-
GroupAlertmanagerAlert
10+
GroupAlertmanagerAlert,
11+
AlertState
1112
} from '../models/prometheus-alerts';
1213
import { PrometheusAlertFormatter } from './prometheus-alert-formatter';
1314
import { BehaviorSubject } from 'rxjs';
@@ -64,10 +65,15 @@ export class PrometheusAlertService {
6465

6566
private handleAlerts(alertGroups: GroupAlertmanagerAlert[]) {
6667
const alerts: AlertmanagerAlert[] = alertGroups
67-
.map((g) => {
68-
if (!g.alerts.length) return null;
69-
if (g.alerts.length === 1) return { ...g.alerts[0], alert_count: 1 };
70-
return { ...g.alerts[0], alert_count: g.alerts.length, subalerts: g.alerts };
68+
.map((group) => {
69+
if (!group.alerts.length) return null;
70+
if (group.alerts.length === 1) return { ...group.alerts[0], alert_count: 1 };
71+
const hasActive = group.alerts.some(
72+
(alert: AlertmanagerAlert) => alert.status.state === AlertState.ACTIVE
73+
);
74+
const parent = { ...group.alerts[0] };
75+
if (hasActive) parent.status.state = AlertState.ACTIVE;
76+
return { ...parent, alert_count: group.alerts.length, subalerts: group.alerts };
7177
})
7278
.filter(Boolean) as AlertmanagerAlert[];
7379

@@ -78,19 +84,23 @@ export class PrometheusAlertService {
7884
}
7985
this.activeAlerts = _.reduce<AlertmanagerAlert, number>(
8086
alerts,
81-
(result, alert) => (alert.status.state === 'active' ? ++result : result),
87+
(result, alert) => (alert.status.state === AlertState.ACTIVE ? ++result : result),
8288
0
8389
);
8490
this.activeCriticalAlerts = _.reduce<AlertmanagerAlert, number>(
8591
alerts,
8692
(result, alert) =>
87-
alert.status.state === 'active' && alert.labels.severity === 'critical' ? ++result : result,
93+
alert.status.state === AlertState.ACTIVE && alert.labels.severity === 'critical'
94+
? ++result
95+
: result,
8896
0
8997
);
9098
this.activeWarningAlerts = _.reduce<AlertmanagerAlert, number>(
9199
alerts,
92100
(result, alert) =>
93-
alert.status.state === 'active' && alert.labels.severity === 'warning' ? ++result : result,
101+
alert.status.state === AlertState.ACTIVE && alert.labels.severity === 'warning'
102+
? ++result
103+
: result,
94104
0
95105
);
96106
this.alerts = alerts
@@ -105,7 +115,7 @@ export class PrometheusAlertService {
105115
this.alertFormatter.convertToCustomAlerts(oldAlerts)
106116
);
107117
const suppressedFiltered = _.filter(changedAlerts, (alert) => {
108-
return alert.status !== 'suppressed';
118+
return alert.status !== AlertState.SUPPRESSED;
109119
});
110120
const notifications = suppressedFiltered.map((alert) =>
111121
this.alertFormatter.convertAlertToNotification(alert)
@@ -121,7 +131,7 @@ export class PrometheusAlertService {
121131
private getVanishedAlerts(alerts: PrometheusCustomAlert[], oldAlerts: PrometheusCustomAlert[]) {
122132
return _.differenceWith(oldAlerts, alerts, (a, b) => a.fingerprint === b.fingerprint).map(
123133
(alert) => {
124-
alert.status = 'resolved';
134+
alert.status = AlertState.RESOLVED;
125135
return alert;
126136
}
127137
);

0 commit comments

Comments
 (0)