From 8ff57811630b98730179d446cd8b89d029a7249f Mon Sep 17 00:00:00 2001 From: Ersin Erdal <92688503+ersin-erdal@users.noreply.github.com> Date: Wed, 3 Dec 2025 20:56:30 +0100 Subject: [PATCH] Add consecutiveMatches to action context (#244997) Fixes: #242572 (cherry picked from commit dd75acf58471952cd89bf0ed39963d3c077c59c4) --- .../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 98f1b162925fd..b5cf2d4585851 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 16ec3b2082312..d33724f89dd02 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()) {