Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
doakalexi committed Feb 23, 2023
1 parent b923644 commit 0980e2d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ export class LegacyAlertsClient<
canSetRecoveryContext: this.options.ruleType.doesSetRecoveryContext ?? false,
shouldPersistAlerts: shouldLogAndScheduleActionsForAlerts,
});

setFlapping<State, Context, ActionGroupIds, RecoveryActionGroupId>(
flappingSettings,
this.processedAlerts.active,
this.processedAlerts.recovered
);
}

public getProcessedAlerts(type: 'new' | 'active' | 'recovered' | 'recoveredCurrent') {
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,6 @@ export class TaskRunner<
}
});

this.legacyAlertsClient.setFlapping(flappingSettings);

let alertsToReturn: Record<string, RawAlertInstance> = {};
let recoveredAlertsToReturn: Record<string, RawAlertInstance> = {};
// Only serialize alerts into task state if we're auto-recovering, otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import expect from '@kbn/expect';
import { IValidatedEvent, nanosToMillis } from '@kbn/event-log-plugin/server';
import { ESTestIndexTool } from '@kbn/alerting-api-integration-helpers';
import { RuleNotifyWhen } from '@kbn/alerting-plugin/common';
import { Spaces } from '../../../scenarios';
import {
getUrlPrefix,
Expand Down Expand Up @@ -546,8 +547,8 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
.auth('superuser', 'superuser')
.send({
enabled: true,
look_back_window: 3,
status_change_threshold: 2,
look_back_window: 6,
status_change_threshold: 4,
})
.expect(200);
const { body: createdAction } = await supertest
Expand All @@ -562,7 +563,10 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
.expect(200);

// pattern of when the alert should fire
const instance = [true, false, true, true, true, true, true];
const instance = [true, false, false, true, false, true, false, true, false].concat(
...new Array(8).fill(true),
false
);
const pattern = {
instance,
};
Expand All @@ -584,7 +588,13 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
group: 'default',
params: {},
},
{
id: createdAction.id,
group: 'recovered',
params: {},
},
],
notify_when: RuleNotifyWhen.CHANGE,
})
);

Expand All @@ -604,10 +614,10 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
// make sure the counts of the # of events per type are as expected
['execute-start', { gte: 6 }],
['execute', { gte: 6 }],
['execute-action', { equal: 7 }],
['new-instance', { equal: 1 }],
['execute-action', { equal: 6 }],
['new-instance', { equal: 3 }],
['active-instance', { gte: 6 }],
['recovered-instance', { equal: 1 }],
['recovered-instance', { equal: 3 }],
]),
});
});
Expand All @@ -619,7 +629,12 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
event?.event?.action === 'recovered-instance'
)
.map((event) => event?.kibana?.alert?.flapping);
const result = [false, true, true, true, false, false, false, false];
const result = [false, false, false, false, false].concat(
new Array(9).fill(true),
false,
false,
false
);
expect(flapping).to.eql(result);
});

Expand All @@ -630,8 +645,8 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
.auth('superuser', 'superuser')
.send({
enabled: true,
look_back_window: 3,
status_change_threshold: 2,
look_back_window: 6,
status_change_threshold: 4,
})
.expect(200);
const { body: createdAction } = await supertest
Expand All @@ -646,7 +661,9 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
.expect(200);

// pattern of when the alert should fire
const instance = [true, false, true, false, false, false, true];
const instance = [true, false, false, true, false, true, false, true, false, true].concat(
new Array(11).fill(false)
);
const pattern = {
instance,
};
Expand All @@ -668,7 +685,13 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
group: 'default',
params: {},
},
{
id: createdAction.id,
group: 'recovered',
params: {},
},
],
notify_when: RuleNotifyWhen.CHANGE,
})
);

Expand All @@ -689,9 +712,9 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
['execute-start', { gte: 6 }],
['execute', { gte: 6 }],
['execute-action', { equal: 6 }],
['new-instance', { equal: 2 }],
['active-instance', { gte: 6 }],
['recovered-instance', { equal: 2 }],
['new-instance', { equal: 3 }],
['active-instance', { gte: 3 }],
['recovered-instance', { equal: 3 }],
]),
});
});
Expand All @@ -703,7 +726,9 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
event?.event?.action === 'recovered-instance'
)
.map((event) => event?.kibana?.alert?.flapping);
expect(flapping).to.eql([false, true, true, true, true, true, true, true]);
expect(flapping).to.eql(
[false, false, false, false, false].concat(new Array(8).fill(true))
);
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default function eventLogAlertTests({ getService }: FtrProviderContext) {
// make sure the counts of the # of events per type are as expected
['execute', { gte: 12 }],
['new-instance', { equal: 2 }],
['active-instance', { gte: 8 }],
['active-instance', { gte: 5 }],
['recovered-instance', { equal: 2 }],
]),
});
Expand Down Expand Up @@ -132,9 +132,7 @@ export default function eventLogAlertTests({ getService }: FtrProviderContext) {
break;
}
}
expect(flapping).to.eql(
new Array(instanceEvents.length - 4).fill(false).concat([true, true, true, true])
);
expect(flapping).to.eql(new Array(instanceEvents.length - 1).fill(false).concat([true]));
});
});
}

0 comments on commit 0980e2d

Please sign in to comment.