Skip to content

Commit 6752f47

Browse files
committed
Merge branches 'w/128.0/bugfix/alert-filtering' and 'q/4334/127.0/bugfix/alert-filtering' into tmp/octopus/q/128.0
3 parents a390fc6 + 1d6fc56 + 358aca4 commit 6752f47

File tree

5 files changed

+456
-35
lines changed

5 files changed

+456
-35
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@
125125
- Following to Alert Manager Bump the test email feature from the
126126
UI wasn't working correctly.
127127
(PR[#4322](https://github.com/scality/metalk8s/pull/4322))
128+
- Alert filtering in the UI when both a critical and warning alert
129+
wasn't working properly.
130+
(PR[#4334](https://github.com/scality/metalk8s/pull/4334))
128131

129132
## Release 127.0.1
130133

shell-ui/src/alerts/services/alertUtils.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,20 @@ const isSameAlertWithDiffSeverity = (
5656
or where we resolve the promise with `react-query`
5757
*/
5858
export const removeWarningAlerts = (alerts: Alert[]): Alert[] => {
59-
const len = alerts.length;
60-
const removeIndex = [];
61-
62-
for (let i = 0; i < len - 1; i++) {
63-
for (let j = i + 1; j < len; j++) {
64-
if (isSameAlertWithDiffSeverity(alerts[i].labels, alerts[j].labels)) {
65-
if (alerts[i].labels.severity === STATUS_WARNING) {
66-
removeIndex.push(i);
67-
} else if (alerts[j].labels.severity === STATUS_WARNING) {
68-
removeIndex.push(j);
69-
}
70-
}
59+
const criticalAlerts = alerts.filter((alert) => {
60+
if (alert.severity === STATUS_CRITICAL) {
61+
return true;
7162
}
72-
}
73-
74-
let removedWarningAlerts = [...alerts];
75-
removeIndex.forEach((index) => removedWarningAlerts.splice(index, 1));
76-
return removedWarningAlerts;
63+
// check if there is a critical alert with the same labels
64+
const isSameAlert = alerts.find((a) => {
65+
return (
66+
a.severity === STATUS_CRITICAL &&
67+
isSameAlertWithDiffSeverity(a.labels, alert.labels)
68+
);
69+
});
70+
return !isSameAlert;
71+
});
72+
return criticalAlerts;
7773
};
7874
// Sort the alerts base on the `severity`
7975
export const sortAlerts = (alerts: Alert[]): Alert[] => {

0 commit comments

Comments
 (0)