Skip to content

Commit

Permalink
Fixed tests and added skip for muted resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Nov 11, 2020
1 parent 8f48a39 commit 676d8f1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
30 changes: 19 additions & 11 deletions x-pack/plugins/alerts/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,15 @@ export class TaskRunner {
alertInstance.hasScheduledActions()
);

scheduleActionsForResolvedInstances(
alertInstances,
executionHandler,
originalAlertInstanceIds,
instancesWithScheduledActions
);
if (!alert.muteAll) {
scheduleActionsForResolvedInstances(
alertInstances,
executionHandler,
originalAlertInstanceIds,
instancesWithScheduledActions,
alert.mutedInstanceIds
);
}

generateNewAndResolvedInstanceEvents({
eventLogger,
Expand Down Expand Up @@ -464,20 +467,25 @@ function scheduleActionsForResolvedInstances(
},
executionHandler: ReturnType<typeof createExecutionHandler>,
originalAlertInstanceIds: string[],
currentAlertInstances: Dictionary<AlertInstance>
currentAlertInstances: Dictionary<AlertInstance>,
mutedInstanceIds: string[]
) {
const currentAlertInstanceIds = Object.keys(currentAlertInstances);
const resolvedIds = without(originalAlertInstanceIds, ...currentAlertInstanceIds);
const resolvedIds = without(
originalAlertInstanceIds,
...[...currentAlertInstanceIds, ...mutedInstanceIds]
);
for (const id of resolvedIds) {
alertInstancesMap[id].updateLastScheduledActions(ResolvedActionGroup.id);
alertInstancesMap[id].unscheduleActions();
const instance = alertInstancesMap[id];
instance.updateLastScheduledActions(ResolvedActionGroup.id);
instance.unscheduleActions();
executionHandler({
actionGroup: ResolvedActionGroup.id,
context: {},
state: {},
alertInstanceId: id,
});
alertInstancesMap[id].scheduleActions(ResolvedActionGroup.id);
instance.scheduleActions(ResolvedActionGroup.id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export default function listAlertTypes({ getService }: FtrProviderContext) {
const supertestWithoutAuth = getService('supertestWithoutAuth');

const expectedNoOpType = {
actionGroups: [{ id: 'default', name: 'Default' }],
actionGroups: [
{ id: 'default', name: 'Default' },
{ id: 'resolved', name: 'Resolved' },
],
defaultActionGroupId: 'default',
id: 'test.noop',
name: 'Test: Noop',
Expand All @@ -28,7 +31,10 @@ export default function listAlertTypes({ getService }: FtrProviderContext) {
};

const expectedRestrictedNoOpType = {
actionGroups: [{ id: 'default', name: 'Default' }],
actionGroups: [
{ id: 'default', name: 'Default' },
{ id: 'resolved', name: 'Resolved' },
],
defaultActionGroupId: 'default',
id: 'test.restricted-noop',
name: 'Test: Restricted Noop',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ instanceStateValue: true
})
.expect(200);

// pattern of when the alert should fire
// pattern of when the alert should fire.
const pattern = {
instance: [false, true, true],
};
Expand Down Expand Up @@ -189,18 +189,6 @@ instanceStateValue: true
const alertId = createdAlert.body.id;
objectRemover.add(space.id, alertId, 'alert', 'alerts');

const instancesSummary = await supertestWithoutAuth.post(
`${getUrlPrefix(space.id)}/api/alerts/alert/${createdAlert.id}/_instance_summary`
);

expect(instancesSummary.status).to.eql(200);
expect(instancesSummary.body.instances).to.eql({
'1': {
status: 'OK',
muted: true,
},
});

const actionTestRecord = (
await esTestIndexTool.waitForDocs('action:test.index-record', reference)
)[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export default function listAlertTypes({ getService }: FtrProviderContext) {
(alertType: any) => alertType.id === 'test.noop'
);
expect(fixtureAlertType).to.eql({
actionGroups: [{ id: 'default', name: 'Default' }],
actionGroups: [
{ id: 'default', name: 'Default' },
{ id: 'resolved', name: 'Resolved' },
],
defaultActionGroupId: 'default',
id: 'test.noop',
name: 'Test: Noop',
Expand Down

0 comments on commit 676d8f1

Please sign in to comment.