From d58a6751a3c1e30a41e85e84c29cecd966855856 Mon Sep 17 00:00:00 2001 From: Ersin Erdal Date: Wed, 3 Dec 2025 00:33:11 +0100 Subject: [PATCH] Add consecutiveMatches to action context --- .../per_alert_action_scheduler.test.ts | 19 +++++++++++++++++-- .../schedulers/per_alert_action_scheduler.ts | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.test.ts b/x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.test.ts index a39f863448e37..0da15839e61eb 100644 --- a/x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.test.ts +++ b/x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.test.ts @@ -20,6 +20,7 @@ import { Alert } from '../../../alert'; import type { AlertInstanceContext, AlertInstanceState } from '@kbn/alerting-state-types'; import { ActionsCompletion } from '@kbn/alerting-state-types'; import { TaskPriority } from '@kbn/task-manager-plugin/server'; +import { transformActionParams } from '../../transform_action_params'; const alertingEventLogger = alertingEventLoggerMock.create(); const actionsClient = actionsClientMock.create(); @@ -112,6 +113,10 @@ const getResult = ( actionToLog: { alertGroup: 'default', alertId, id: actionId, uuid: actionUuid, typeId: 'test' }, }); +jest.mock('../../transform_action_params', () => ({ + transformActionParams: jest.fn(), +})); + let clock: sinon.SinonFakeTimers; describe('Per-Alert Action Scheduler', () => { @@ -211,8 +216,8 @@ describe('Per-Alert Action Scheduler', () => { >; beforeEach(() => { - newAlert1 = generateAlert({ id: 1 }); - newAlert2 = generateAlert({ id: 2 }); + newAlert1 = generateAlert({ id: 1, activeCount: 3 }); + newAlert2 = generateAlert({ id: 2, activeCount: 5 }); alerts = { ...newAlert1, ...newAlert2 }; }); @@ -240,6 +245,16 @@ describe('Per-Alert Action Scheduler', () => { getResult('action-2', '1', '222-222'), getResult('action-2', '2', '222-222'), ]); + + expect(transformActionParams).toHaveBeenCalledTimes(4); + expect(transformActionParams).toHaveBeenCalledWith( + expect.objectContaining({ + actionId: 'action-1', + alertId: 'rule-id-1', + consecutiveMatches: 3, + alertUuid: expect.any(String), + }) + ); }); test('test should create action to schedule with priority if specified for each alert and each action', async () => { diff --git a/x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.ts b/x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.ts index 94c3e317e9977..3fa671fe95590 100644 --- a/x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.ts +++ b/x-pack/platform/plugins/shared/alerting/server/task_runner/action_scheduler/schedulers/per_alert_action_scheduler.ts @@ -223,6 +223,7 @@ export class PerAlertActionScheduler< actionParams: action.params, flapping: alert.getFlapping(), ruleUrl: ruleUrl?.absoluteUrl, + consecutiveMatches: alert.getActiveCount(), }; if (alert.isAlertAsData()) {