Skip to content

Commit 1fbde9e

Browse files
committed
Add consecutiveMatches to action context (elastic#244997)
Fixes: elastic#242572 (cherry picked from commit dd75acf)
1 parent ac5fa74 commit 1fbde9e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Alert } from '../../../alert';
2020
import type { AlertInstanceContext, AlertInstanceState } from '@kbn/alerting-state-types';
2121
import { ActionsCompletion } from '@kbn/alerting-state-types';
2222
import { TaskPriority } from '@kbn/task-manager-plugin/server';
23+
import { transformActionParams } from '../../transform_action_params';
2324

2425
const alertingEventLogger = alertingEventLoggerMock.create();
2526
const actionsClient = actionsClientMock.create();
@@ -112,6 +113,10 @@ const getResult = (
112113
actionToLog: { alertGroup: 'default', alertId, id: actionId, uuid: actionUuid, typeId: 'test' },
113114
});
114115

116+
jest.mock('../../transform_action_params', () => ({
117+
transformActionParams: jest.fn(),
118+
}));
119+
115120
let clock: sinon.SinonFakeTimers;
116121

117122
describe('Per-Alert Action Scheduler', () => {
@@ -211,8 +216,8 @@ describe('Per-Alert Action Scheduler', () => {
211216
>;
212217

213218
beforeEach(() => {
214-
newAlert1 = generateAlert({ id: 1 });
215-
newAlert2 = generateAlert({ id: 2 });
219+
newAlert1 = generateAlert({ id: 1, activeCount: 3 });
220+
newAlert2 = generateAlert({ id: 2, activeCount: 5 });
216221
alerts = { ...newAlert1, ...newAlert2 };
217222
});
218223

@@ -240,6 +245,16 @@ describe('Per-Alert Action Scheduler', () => {
240245
getResult('action-2', '1', '222-222'),
241246
getResult('action-2', '2', '222-222'),
242247
]);
248+
249+
expect(transformActionParams).toHaveBeenCalledTimes(4);
250+
expect(transformActionParams).toHaveBeenCalledWith(
251+
expect.objectContaining({
252+
actionId: 'action-1',
253+
alertId: 'rule-id-1',
254+
consecutiveMatches: 3,
255+
alertUuid: expect.any(String),
256+
})
257+
);
243258
});
244259

245260
test('test should create action to schedule with priority if specified for each alert and each action', async () => {

x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export class PerAlertActionScheduler<
223223
actionParams: action.params,
224224
flapping: alert.getFlapping(),
225225
ruleUrl: ruleUrl?.absoluteUrl,
226+
consecutiveMatches: alert.getActiveCount(),
226227
};
227228

228229
if (alert.isAlertAsData()) {

0 commit comments

Comments
 (0)