Skip to content

Commit

Permalink
[Alerting] optimize calculation of unmuted alert instances (#78021)
Browse files Browse the repository at this point in the history
This PR optimizes the calculation of instances which should be executed, by optimizing the way the muted instances are removed from the collection of triggered instances.
  • Loading branch information
pmuellr authored Sep 22, 2020
1 parent ef86fbc commit 3f5243e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions x-pack/plugins/alerts/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { pickBy, mapValues, omit, without } from 'lodash';
import { pickBy, mapValues, without } from 'lodash';
import { Logger, KibanaRequest } from '../../../../../src/core/server';
import { TaskRunnerContext } from './task_runner_factory';
import { ConcreteTaskInstance } from '../../../task_manager/server';
Expand Down Expand Up @@ -228,12 +228,13 @@ export class TaskRunner {
});

if (!muteAll) {
const enabledAlertInstances = omit(instancesWithScheduledActions, ...mutedInstanceIds);
const mutedInstanceIdsSet = new Set(mutedInstanceIds);

await Promise.all(
Object.entries(enabledAlertInstances)
Object.entries(instancesWithScheduledActions)
.filter(
([, alertInstance]: [string, AlertInstance]) => !alertInstance.isThrottled(throttle)
([alertInstanceName, alertInstance]: [string, AlertInstance]) =>
!alertInstance.isThrottled(throttle) && !mutedInstanceIdsSet.has(alertInstanceName)
)
.map(([id, alertInstance]: [string, AlertInstance]) =>
this.executeAlertInstance(id, alertInstance, executionHandler)
Expand Down

0 comments on commit 3f5243e

Please sign in to comment.