Skip to content

Commit

Permalink
Fix alert filtering when both a critical and warning alert are raised
Browse files Browse the repository at this point in the history
  • Loading branch information
JBWatenbergScality committed Jun 5, 2024
1 parent 7e2eece commit 1af2c6f
Show file tree
Hide file tree
Showing 5 changed files with 456 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
- Following to Alert Manager Bump the test email feature from the
UI wasn't working correctly.
(PR[#4322](https://github.com/scality/metalk8s/pull/4322))
- Alert filtering in the UI when both a critical and warning alert
wasn't working properly.
(PR[#4334](https://github.com/scality/metalk8s/pull/4334))

## Release 127.0.1

Expand Down
30 changes: 13 additions & 17 deletions shell-ui/src/alerts/services/alertUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,20 @@ const isSameAlertWithDiffSeverity = (
or where we resolve the promise with `react-query`
*/
export const removeWarningAlerts = (alerts: Alert[]): Alert[] => {
const len = alerts.length;
const removeIndex = [];

for (let i = 0; i < len - 1; i++) {
for (let j = i + 1; j < len; j++) {
if (isSameAlertWithDiffSeverity(alerts[i].labels, alerts[j].labels)) {
if (alerts[i].labels.severity === STATUS_WARNING) {
removeIndex.push(i);
} else if (alerts[j].labels.severity === STATUS_WARNING) {
removeIndex.push(j);
}
}
const criticalAlerts = alerts.filter((alert) => {
if (alert.severity === STATUS_CRITICAL) {
return true;
}
}

let removedWarningAlerts = [...alerts];
removeIndex.forEach((index) => removedWarningAlerts.splice(index, 1));
return removedWarningAlerts;
// check if there is a critical alert with the same labels
const isSameAlert = alerts.find((a) => {
return (
a.severity === STATUS_CRITICAL &&
isSameAlertWithDiffSeverity(a.labels, alert.labels)
);
});
return !isSameAlert;
});
return criticalAlerts;
};
// Sort the alerts base on the `severity`
export const sortAlerts = (alerts: Alert[]): Alert[] => {
Expand Down
Loading

0 comments on commit 1af2c6f

Please sign in to comment.