[Inventory rule] Fix alerts not being visible when number of alerts are more than max alert limit (#178019)

Fixes #171976

## Summary

Fixes issue when the number of alerts is more than the max number in the
inventory rule similar to what was done in
https://github.com/elastic/kibana/pull/171960.


![image](e99c05b0-20c3-4ee9-8500-ffb6f8975d19)


![image](5ee856e2-1af1-41bb-b5a3-4008f089be78)
This commit is contained in:
Maryam Saeidi 2024-03-05 19:16:08 +01:00 committed by GitHub
parent 4cc38e7025
commit f2de74259f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -104,6 +104,7 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) =
getAlertStartedDate,
getAlertUuid,
getAlertByAlertUuid,
alertFactory: baseAlertFactory,
} = services;
const alertFactory: InventoryMetricThresholdAlertFactory = (
id,
@ -194,8 +195,15 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) =
);
let scheduledActionsCount = 0;
const alertLimit = baseAlertFactory.alertLimit.getValue();
let hasReachedLimit = false;
const inventoryItems = Object.keys(first(results)!);
for (const group of inventoryItems) {
if (scheduledActionsCount >= alertLimit) {
// need to set this so that warning is displayed in the UI and in the logs
hasReachedLimit = true;
break; // once limit is reached, we break out of the loop and don't schedule any more alerts
}
// AND logic; all criteria must be across the threshold
const shouldAlertFire = results.every((result) => result[group]?.shouldFire);
const shouldAlertWarn = results.every((result) => result[group]?.shouldWarn);
@ -300,6 +308,7 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) =
}
}
baseAlertFactory.alertLimit.setLimitReached(hasReachedLimit);
const { getRecoveredAlerts } = services.alertFactory.done();
const recoveredAlerts = getRecoveredAlerts();