Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 };
});

Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export class PerAlertActionScheduler<
actionParams: action.params,
flapping: alert.getFlapping(),
ruleUrl: ruleUrl?.absoluteUrl,
consecutiveMatches: alert.getActiveCount(),
};

if (alert.isAlertAsData()) {
Expand Down