Skip to content

Commit aa1506e

Browse files
[9.2] Add consecutiveMatches to action context (#244997) (#245167)
# Backport This will backport the following commits from `main` to `9.2`: - [Add consecutiveMatches to action context (#244997)](#244997) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Ersin Erdal","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-12-03T19:56:30Z","message":"Add consecutiveMatches to action context (#244997)\n\nFixes: #242572","sha":"dd75acf58471952cd89bf0ed39963d3c077c59c4","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:ResponseOps","backport:version","v9.1.0","v9.2.0","v9.3.0"],"title":"Add consecutiveMatches to action context","number":244997,"url":"https://github.com/elastic/kibana/pull/244997","mergeCommit":{"message":"Add consecutiveMatches to action context (#244997)\n\nFixes: #242572","sha":"dd75acf58471952cd89bf0ed39963d3c077c59c4"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","9.2"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/244997","number":244997,"mergeCommit":{"message":"Add consecutiveMatches to action context (#244997)\n\nFixes: #242572","sha":"dd75acf58471952cd89bf0ed39963d3c077c59c4"}}]}] BACKPORT--> Co-authored-by: Ersin Erdal <[email protected]>
1 parent 0f59626 commit aa1506e

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)