[8.12] [SLos] Slo burn rules accounts for max alert limit (#173379) (#173412)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[SLos] Slo burn rules accounts for max alert limit
(#173379)](https://github.com/elastic/kibana/pull/173379)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2023-12-14T14:50:17Z","message":"[SLos]
Slo burn rules accounts for max alert limit
(#173379)","sha":"1555f16f703819cdf2fd89042c66616e8eba0b99","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","auto-backport","v8.12.0","Team:obs-ux-management","v8.13.0"],"number":173379,"url":"https://github.com/elastic/kibana/pull/173379","mergeCommit":{"message":"[SLos]
Slo burn rules accounts for max alert limit
(#173379)","sha":"1555f16f703819cdf2fd89042c66616e8eba0b99"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/173379","number":173379,"mergeCommit":{"message":"[SLos]
Slo burn rules accounts for max alert limit
(#173379)","sha":"1555f16f703819cdf2fd89042c66616e8eba0b99"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
Kibana Machine 2023-12-14 13:43:24 -05:00 committed by GitHub
parent 471055ffe8
commit fdf4f2307b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -95,6 +95,10 @@ export const getRuleExecutor = ({
const results = await evaluate(esClient.asCurrentUser, slo, params, new Date(dateEnd));
if (results.length > 0) {
const alertLimit = alertFactory.alertLimit.getValue();
let hasReachedLimit = false;
let scheduledActionsCount = 0;
for (const result of results) {
const {
instanceId,
@ -113,6 +117,11 @@ export const getRuleExecutor = ({
`/app/observability/slos/${slo.id}${urlQuery}`
);
if (shouldAlert) {
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
}
const reason = buildReason(
instanceId,
windowDef.actionGroup,
@ -160,6 +169,7 @@ export const getRuleExecutor = ({
alert.scheduleActions(windowDef.actionGroup, context);
alert.replaceState({ alertState: AlertStates.ALERT });
scheduledActionsCount++;
}
}
@ -195,6 +205,7 @@ export const getRuleExecutor = ({
recoveredAlert.setContext(context);
}
alertFactory.alertLimit.setLimitReached(hasReachedLimit);
}
return { state: {} };