diff --git a/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts b/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts index 9b061bb3898ca..106f55d2c0915 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts @@ -57,7 +57,7 @@ describe('checking migration metadata changes on all registered SO types', () => Object { "action": "7858e6d5a9f231bf23f6f2e57328eb0095b26735", "action_task_params": "bbd38cbfd74bf6713586fe078e3fa92db2234299", - "alert": "c29c5e28a6f1d075e528a9273a1a07b080625565", + "alert": "f2e81863be0b50966b876b88b906c962e30b8c9c", "api_key_pending_invalidation": "9b4bc1235337da9a87ef05a1d1f4858b2a3b77c6", "apm-indices": "ceb0870f3a74e2ffc3a1cd3a3c73af76baca0999", "apm-server-schema": "2bfd2998d3873872e1366458ce553def85418f91", diff --git a/x-pack/plugins/alerting/common/rule.ts b/x-pack/plugins/alerting/common/rule.ts index 17cfa1fbf4a05..3bfddd79af10d 100644 --- a/x-pack/plugins/alerting/common/rule.ts +++ b/x-pack/plugins/alerting/common/rule.ts @@ -139,6 +139,7 @@ export interface Rule { isSnoozedUntil?: Date | null; lastRun?: RuleLastRun | null; nextRun?: Date | null; + running?: boolean | null; } export type SanitizedRule = Omit, 'apiKey'>; diff --git a/x-pack/plugins/alerting/server/rules_client/methods/clone.ts b/x-pack/plugins/alerting/server/rules_client/methods/clone.ts index e1cabc50280e6..7f06778142527 100644 --- a/x-pack/plugins/alerting/server/rules_client/methods/clone.ts +++ b/x-pack/plugins/alerting/server/rules_client/methods/clone.ts @@ -118,6 +118,7 @@ export async function clone( executionStatus: getRuleExecutionStatusPending(lastRunTimestamp.toISOString()), monitoring: getDefaultMonitoring(lastRunTimestamp.toISOString()), scheduledTaskId: null, + running: false, }; context.auditLogger?.log( diff --git a/x-pack/plugins/alerting/server/rules_client/methods/create.ts b/x-pack/plugins/alerting/server/rules_client/methods/create.ts index a0b5e26061a8d..fa7766d9a6740 100644 --- a/x-pack/plugins/alerting/server/rules_client/methods/create.ts +++ b/x-pack/plugins/alerting/server/rules_client/methods/create.ts @@ -138,6 +138,7 @@ export async function create( throttle, executionStatus: getRuleExecutionStatusPending(lastRunTimestamp.toISOString()), monitoring: getDefaultMonitoring(lastRunTimestamp.toISOString()), + running: false, }; const mappedParams = getMappedParams(updatedParams); diff --git a/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts index 6205b4bb4ba6a..53f4dafa0aeaf 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/create.test.ts @@ -96,6 +96,7 @@ function getMockData(overwrites: Record = {}): CreateOptions<{ }, }, ], + running: false, ...overwrites, }; } @@ -377,6 +378,7 @@ describe('create()', () => { "params": Object { "bar": true, }, + "running": false, "schedule": Object { "interval": "1m", }, @@ -446,6 +448,7 @@ describe('create()', () => { "params": Object { "bar": true, }, + "running": false, "schedule": Object { "interval": "1m", }, @@ -663,6 +666,7 @@ describe('create()', () => { "params": Object { "bar": true, }, + "running": false, "schedule": Object { "interval": "1m", }, @@ -968,6 +972,7 @@ describe('create()', () => { }, }, ], + running: false, }, references: [ { @@ -1027,6 +1032,7 @@ describe('create()', () => { "params": Object { "bar": true, }, + "running": false, "schedule": Object { "interval": "1m", }, @@ -1085,6 +1091,7 @@ describe('create()', () => { name: 'abc', notifyWhen: 'onActiveAlert', params: { bar: true }, + running: false, schedule: { interval: '1m' }, tags: ['foo'], throttle: null, @@ -1230,6 +1237,7 @@ describe('create()', () => { }, }, ], + running: false, }, references: [ { @@ -1284,6 +1292,7 @@ describe('create()', () => { name: 'abc', notifyWhen: 'onActiveAlert', params: { bar: true, parameterThatIsSavedObjectRef: 'soRef_0' }, + running: false, schedule: { interval: '1m' }, tags: ['foo'], throttle: null, @@ -1326,6 +1335,7 @@ describe('create()', () => { "bar": true, "parameterThatIsSavedObjectId": "9", }, + "running": false, "schedule": Object { "interval": "1m", }, @@ -1398,6 +1408,7 @@ describe('create()', () => { }, }, ], + running: false, }, references: [ { @@ -1452,6 +1463,7 @@ describe('create()', () => { name: 'abc', notifyWhen: 'onActiveAlert', params: { bar: true, parameterThatIsSavedObjectRef: 'action_0' }, + running: false, schedule: { interval: '1m' }, tags: ['foo'], throttle: null, @@ -1494,6 +1506,7 @@ describe('create()', () => { "bar": true, "parameterThatIsSavedObjectId": "8", }, + "running": false, "schedule": Object { "interval": "1m", }, @@ -1569,6 +1582,7 @@ describe('create()', () => { }, }, ], + running: false, }; unsecuredSavedObjectsClient.create.mockResolvedValueOnce({ id: '1', @@ -1623,6 +1637,7 @@ describe('create()', () => { warning: null, }, monitoring: getDefaultMonitoring('2019-02-12T21:01:22.479Z'), + running: false, }, { id: 'mock-saved-object-id', @@ -1660,6 +1675,7 @@ describe('create()', () => { "params": Object { "bar": true, }, + "running": false, "schedule": Object { "interval": "1m", }, @@ -1701,6 +1717,7 @@ describe('create()', () => { }, }, ], + running: false, }; unsecuredSavedObjectsClient.create.mockResolvedValueOnce({ id: '1', @@ -1755,6 +1772,7 @@ describe('create()', () => { warning: null, }, monitoring: getDefaultMonitoring('2019-02-12T21:01:22.479Z'), + running: false, }, { id: 'mock-saved-object-id', @@ -1792,6 +1810,7 @@ describe('create()', () => { "params": Object { "bar": true, }, + "running": false, "schedule": Object { "interval": "1m", }, @@ -1833,6 +1852,7 @@ describe('create()', () => { }, }, ], + running: false, }; unsecuredSavedObjectsClient.create.mockResolvedValueOnce({ id: '1', @@ -1887,6 +1907,7 @@ describe('create()', () => { warning: null, }, monitoring: getDefaultMonitoring('2019-02-12T21:01:22.479Z'), + running: false, }, { id: 'mock-saved-object-id', @@ -1924,6 +1945,7 @@ describe('create()', () => { "params": Object { "bar": true, }, + "running": false, "schedule": Object { "interval": "1m", }, @@ -1973,6 +1995,7 @@ describe('create()', () => { }, }, ], + running: false, }; unsecuredSavedObjectsClient.create.mockResolvedValueOnce({ id: '123', @@ -2058,6 +2081,7 @@ describe('create()', () => { meta: { versionApiKeyLastmodified: 'v8.0.0', }, + running: false, }, { references: [ @@ -2098,6 +2122,7 @@ describe('create()', () => { "risk_score": 42, "severity": "low", }, + "running": false, "schedule": Object { "interval": "10s", }, @@ -2407,6 +2432,7 @@ describe('create()', () => { warning: null, }, monitoring: getDefaultMonitoring('2019-02-12T21:01:22.479Z'), + running: false, }, { id: 'mock-saved-object-id', @@ -2442,6 +2468,7 @@ describe('create()', () => { }, }, ], + running: false, }, references: [ { @@ -2509,6 +2536,7 @@ describe('create()', () => { warning: null, }, monitoring: getDefaultMonitoring('2019-02-12T21:01:22.479Z'), + running: false, }, { id: 'mock-saved-object-id', @@ -2612,6 +2640,7 @@ describe('create()', () => { }, }, ], + running: false, }; unsecuredSavedObjectsClient.create.mockResolvedValueOnce({ id: '1', diff --git a/x-pack/plugins/alerting/server/saved_objects/index.ts b/x-pack/plugins/alerting/server/saved_objects/index.ts index 76fc730409294..d8d53f4978d55 100644 --- a/x-pack/plugins/alerting/server/saved_objects/index.ts +++ b/x-pack/plugins/alerting/server/saved_objects/index.ts @@ -38,6 +38,7 @@ export const AlertAttributesExcludedFromAAD = [ 'isSnoozedUntil', 'lastRun', 'nextRun', + 'running', ]; // useful for Pick which is a @@ -56,7 +57,8 @@ export type AlertAttributesExcludedFromAADType = | 'snoozeSchedule' | 'isSnoozedUntil' | 'lastRun' - | 'nextRun'; + | 'nextRun' + | 'running'; export function setupSavedObjects( savedObjects: SavedObjectsServiceSetup, diff --git a/x-pack/plugins/alerting/server/saved_objects/mappings.ts b/x-pack/plugins/alerting/server/saved_objects/mappings.ts index a45dc78170ddb..75c3185db7ef4 100644 --- a/x-pack/plugins/alerting/server/saved_objects/mappings.ts +++ b/x-pack/plugins/alerting/server/saved_objects/mappings.ts @@ -339,5 +339,8 @@ export const alertMappings: SavedObjectsTypeMappingDefinition = { }, }, }, + running: { + type: 'boolean', + }, }, }; diff --git a/x-pack/plugins/alerting/server/task_runner/fixtures.ts b/x-pack/plugins/alerting/server/task_runner/fixtures.ts index 3b77714d76119..f226ac94d7f63 100644 --- a/x-pack/plugins/alerting/server/task_runner/fixtures.ts +++ b/x-pack/plugins/alerting/server/task_runner/fixtures.ts @@ -122,6 +122,7 @@ export const generateSavedObjectParams = ({ }, }, nextRun, + running: false, }, { refresh: false, namespace: undefined }, ]; diff --git a/x-pack/plugins/alerting/server/task_runner/running_handler.test.ts b/x-pack/plugins/alerting/server/task_runner/running_handler.test.ts new file mode 100644 index 0000000000000..ce3a3c6680e7b --- /dev/null +++ b/x-pack/plugins/alerting/server/task_runner/running_handler.test.ts @@ -0,0 +1,78 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { ISavedObjectsRepository, Logger } from '@kbn/core/server'; + +import { partiallyUpdateAlert } from '../saved_objects/partially_update_alert'; +import { RunningHandler } from './running_handler'; + +jest.mock('../saved_objects/partially_update_alert', () => ({ + partiallyUpdateAlert: jest.fn(), +})); + +describe('isRunning handler', () => { + const soClient = jest.fn() as unknown as ISavedObjectsRepository; + const logger = { + error: jest.fn(), + } as unknown as Logger; + const ruleTypeId = 'myType'; + beforeEach(() => { + (partiallyUpdateAlert as jest.Mock).mockClear(); + (logger.error as jest.Mock).mockClear(); + jest.useFakeTimers(); + }); + afterEach(() => { + jest.useRealTimers(); + }); + + test('Should resolve if nothing got started', async () => { + (partiallyUpdateAlert as jest.Mock).mockImplementation(() => Promise.resolve('resolve')); + const runHandler = new RunningHandler(soClient, logger, ruleTypeId); + const resp = await runHandler.waitFor(); + expect(partiallyUpdateAlert).toHaveBeenCalledTimes(0); + expect(logger.error).toHaveBeenCalledTimes(0); + expect(resp).toBe(undefined); + }); + + test('Should return the promise from partiallyUpdateAlert when the update isRunning has been a success', async () => { + (partiallyUpdateAlert as jest.Mock).mockImplementation(() => Promise.resolve('resolve')); + const runHandler = new RunningHandler(soClient, logger, ruleTypeId); + runHandler.start('9876543210'); + jest.runAllTimers(); + const resp = await runHandler.waitFor(); + + expect(partiallyUpdateAlert).toHaveBeenCalledTimes(1); + expect((partiallyUpdateAlert as jest.Mock).mock.calls[0]).toMatchInlineSnapshot(` + Array [ + [MockFunction], + "9876543210", + Object { + "running": true, + }, + Object { + "ignore404": true, + "namespace": undefined, + "refresh": false, + }, + ] + `); + expect(logger.error).toHaveBeenCalledTimes(0); + expect(resp).toBe('resolve'); + }); + + test('Should reject when the update isRunning has been a failure', async () => { + (partiallyUpdateAlert as jest.Mock).mockImplementation(() => + Promise.reject(new Error('error')) + ); + const runHandler = new RunningHandler(soClient, logger, ruleTypeId); + runHandler.start('9876543210'); + jest.runAllTimers(); + + await expect(runHandler.waitFor()).rejects.toThrow(); + expect(partiallyUpdateAlert).toHaveBeenCalledTimes(1); + expect(logger.error).toHaveBeenCalledTimes(1); + }); +}); diff --git a/x-pack/plugins/alerting/server/task_runner/running_handler.ts b/x-pack/plugins/alerting/server/task_runner/running_handler.ts new file mode 100644 index 0000000000000..118f13ab6eed9 --- /dev/null +++ b/x-pack/plugins/alerting/server/task_runner/running_handler.ts @@ -0,0 +1,71 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { ISavedObjectsRepository, Logger } from '@kbn/core/server'; +import { partiallyUpdateAlert } from '../saved_objects/partially_update_alert'; + +const TIME_TO_WAIT = 2000; + +export class RunningHandler { + private client: ISavedObjectsRepository; + private logger: Logger; + private ruleTypeId: string; + + private runningTimeoutId?: NodeJS.Timeout; + private isUpdating: boolean = false; + private runningPromise?: Promise; + + constructor(client: ISavedObjectsRepository, logger: Logger, ruleTypeId: string) { + this.client = client; + this.logger = logger; + this.ruleTypeId = ruleTypeId; + } + + public start(ruleId: string, namespace?: string) { + this.runningTimeoutId = setTimeout(() => { + this.setRunning(ruleId, namespace); + }, TIME_TO_WAIT); + } + + public stop() { + if (this.runningTimeoutId) { + clearTimeout(this.runningTimeoutId); + } + } + + public async waitFor(): Promise { + this.stop(); + if (this.isUpdating && this.runningPromise) return this.runningPromise; + else return Promise.resolve(); + } + + private setRunning(ruleId: string, namespace?: string) { + this.isUpdating = true; + this.runningPromise = partiallyUpdateAlert( + this.client, + ruleId, + { running: true }, + { + ignore404: true, + namespace, + refresh: false, + } + ); + this.runningPromise + .then(() => { + this.runningPromise = undefined; + this.isUpdating = false; + }) + .catch((err) => { + this.runningPromise = undefined; + this.isUpdating = false; + this.logger.error( + `error updating running attribute rule for ${this.ruleTypeId}:${ruleId} ${err.message}` + ); + }); + } +} diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.ts index 426ae7b2554e4..9f72b7a02d651 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts @@ -70,6 +70,7 @@ import { getPublicAlertFactory } from '../alert/create_alert_factory'; import { TaskRunnerTimer, TaskRunnerTimerSpan } from './task_runner_timer'; import { RuleMonitoringService } from '../monitoring/rule_monitoring_service'; import { ILastRun, lastRunFromState, lastRunToRaw } from '../lib/last_run_status'; +import { RunningHandler } from './running_handler'; import { RuleResultService } from '../monitoring/rule_result_service'; const FALLBACK_RETRY_INTERVAL = '5m'; @@ -114,6 +115,7 @@ export class TaskRunner< private cancelled: boolean; private stackTraceLog: StackTraceLog | null; private ruleMonitoring: RuleMonitoringService; + private ruleRunning: RunningHandler; private ruleResult: RuleResultService; constructor( @@ -148,10 +150,15 @@ export class TaskRunner< this.alertingEventLogger = new AlertingEventLogger(this.context.eventLogger); this.stackTraceLog = null; this.ruleMonitoring = new RuleMonitoringService(); + this.ruleRunning = new RunningHandler( + this.context.internalSavedObjectsRepository, + this.logger, + loggerId + ); this.ruleResult = new RuleResultService(); } - private async updateRuleSavedObject( + private async updateRuleSavedObjectPostRun( ruleId: string, namespace: string | undefined, attributes: { @@ -163,11 +170,25 @@ export class TaskRunner< ) { const client = this.context.internalSavedObjectsRepository; try { - await partiallyUpdateAlert(client, ruleId, attributes, { - ignore404: true, - namespace, - refresh: false, - }); + // Future engineer -> Here we are just checking if we need to wait for + // the update of the attribute `running` in the rule's saved object + // and we are swallowing the error because we still want to move forward + // with the update of our rule since we are putting back the running attribute + // back to false + await this.ruleRunning.waitFor(); + // eslint-disable-next-line no-empty + } catch {} + try { + await partiallyUpdateAlert( + client, + ruleId, + { ...attributes, running: false }, + { + ignore404: true, + namespace, + refresh: false, + } + ); } catch (err) { this.logger.error(`error updating rule for ${this.ruleType.id}:${ruleId} ${err.message}`); } @@ -648,8 +669,7 @@ export class TaskRunner< executionStatus )} - ${JSON.stringify(lastRun)}` ); - - await this.updateRuleSavedObject(ruleId, namespace, { + await this.updateRuleSavedObjectPostRun(ruleId, namespace, { executionStatus: ruleExecutionStatusToRaw(executionStatus), nextRun, lastRun: lastRunToRaw(lastRun), @@ -668,6 +688,7 @@ export class TaskRunner< schedule: taskSchedule, } = this.taskInstance; + this.ruleRunning.start(ruleId, this.context.spaceIdToNamespace(spaceId)); const runDate = new Date(); this.logger.debug(`executing rule ${this.ruleType.id}:${ruleId} at ${runDate.toISOString()}`); @@ -846,7 +867,7 @@ export class TaskRunner< this.logger.debug( `Updating rule task for ${this.ruleType.id} rule with id ${ruleId} - execution error due to timeout` ); - await this.updateRuleSavedObject(ruleId, namespace, { + await this.updateRuleSavedObjectPostRun(ruleId, namespace, { executionStatus: ruleExecutionStatusToRaw(executionStatus), lastRun: { outcome: 'failed', diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner_cancel.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner_cancel.test.ts index b21a8852a701f..e36968197bb41 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner_cancel.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner_cancel.test.ts @@ -251,6 +251,7 @@ describe('Task Runner Cancel', () => { }, }, nextRun: '1970-01-01T00:00:10.000Z', + running: false, }, { refresh: false, namespace: undefined } ); diff --git a/x-pack/plugins/alerting/server/types.ts b/x-pack/plugins/alerting/server/types.ts index b1b55066836c3..30e8d864b4871 100644 --- a/x-pack/plugins/alerting/server/types.ts +++ b/x-pack/plugins/alerting/server/types.ts @@ -290,6 +290,7 @@ export interface RawRule extends SavedObjectAttributes { isSnoozedUntil?: string | null; lastRun?: RawRuleLastRun | null; nextRun?: string | null; + running?: boolean | null; } export interface AlertingPlugin { diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/create.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/create.ts index cebfe68e279b0..066ae0303d2b5 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/create.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/create.ts @@ -110,6 +110,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) { ], enabled: true, rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', params: {}, created_by: user.username, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts index b8460e84202c9..74363bb0222d6 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/find.ts @@ -68,6 +68,7 @@ const findTestUtils = ( name: 'abc', tags: ['foo'], rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', schedule: { interval: '1m' }, enabled: true, @@ -271,6 +272,7 @@ const findTestUtils = ( name: 'abc', tags: ['foo'], rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', schedule: { interval: '1m' }, enabled: false, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/get.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/get.ts index b0900f74993cb..d6de374d2524b 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/get.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group1/tests/alerting/get.ts @@ -65,6 +65,7 @@ const getTestUtils = ( name: 'abc', tags: ['foo'], rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', schedule: { interval: '1m' }, enabled: true, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/update.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/update.ts index 430d69274041a..25cc8384f14e4 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/update.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/alerting/update.ts @@ -113,6 +113,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { ...updatedData, id: createdAlert.id, rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', created_by: 'elastic', enabled: true, @@ -210,6 +211,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { ...updatedData, id: createdAlert.id, rule_type_id: 'test.restricted-noop', + running: false, consumer: 'alertsRestrictedFixture', created_by: 'elastic', enabled: true, @@ -310,6 +312,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { ...updatedData, id: createdAlert.id, rule_type_id: 'test.unrestricted-noop', + running: false, consumer: 'alertsFixture', created_by: 'elastic', enabled: true, @@ -410,6 +413,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { ...updatedData, id: createdAlert.id, rule_type_id: 'test.restricted-noop', + running: false, consumer: 'alerts', created_by: 'elastic', enabled: true, @@ -508,6 +512,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { ...updatedData, id: createdAlert.id, rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', created_by: 'elastic', enabled: true, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_delete.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_delete.ts index b69b62e4b4a40..cb5cc4b1d5687 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_delete.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_delete.ts @@ -28,6 +28,7 @@ const getDefaultRules = (response: any) => ({ schedule: { interval: '1m' }, actions: [], params: {}, + running: false, snoozeSchedule: [], updatedAt: response.body.rules[0].updatedAt, createdAt: response.body.rules[0].createdAt, @@ -59,6 +60,7 @@ const getThreeRules = (response: any) => { schedule: { interval: '1m' }, actions: [], params: {}, + running: false, snoozeSchedule: [], updatedAt: response.body.rules[i].updatedAt, createdAt: response.body.rules[i].createdAt, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_disable.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_disable.ts index f584772a07eb4..ee2e6c27b58a4 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_disable.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_disable.ts @@ -27,6 +27,7 @@ const getDefaultRules = (response: any) => ({ schedule: { interval: '1m' }, actions: [], params: {}, + running: false, snoozeSchedule: [], updatedAt: response.body.rules[0].updatedAt, createdAt: response.body.rules[0].createdAt, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_enable.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_enable.ts index 2f5db78b96c5b..d16cfe0a77720 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_enable.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/bulk_enable.ts @@ -91,6 +91,7 @@ export default ({ getService }: FtrProviderContext) => { schedule: { interval: '1m' }, actions: [], params: {}, + running: false, snoozeSchedule: [], updatedAt: response.body.rules[0].updatedAt, createdAt: response.body.rules[0].createdAt, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/clone.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/clone.ts index e99aa177d8a78..9bb87db3c7e30 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/clone.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/alerting/clone.ts @@ -149,6 +149,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) { ], enabled: true, rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', params: {}, created_by: user.username, diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/create.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/create.ts index 5cc7316f1c6e3..5e07ec90aa7c3 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/create.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/create.ts @@ -80,6 +80,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) { ], enabled: true, rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', params: {}, created_by: null, @@ -180,6 +181,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) { ], enabled: true, rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', params: {}, created_by: null, @@ -495,6 +497,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) { createdAt: response.body.createdAt, updatedAt: response.body.updatedAt, executionStatus: response.body.executionStatus, + running: false, ...(response.body.next_run ? { next_run: response.body.next_run } : {}), ...(response.body.last_run ? { last_run: response.body.last_run } : {}), }); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/find.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/find.ts index d10518aca575f..bcf1a3d09ca50 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/find.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/find.ts @@ -59,6 +59,7 @@ const findTestUtils = ( name: 'abc', tags: ['foo'], rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', schedule: { interval: '1m' }, enabled: true, @@ -327,6 +328,7 @@ export default function createFindTests({ getService }: FtrProviderContext) { createdAt: match.createdAt, updatedAt: match.updatedAt, executionStatus: match.executionStatus, + running: false, ...(match.nextRun ? { nextRun: match.nextRun } : {}), ...(match.lastRun ? { lastRun: match.lastRun } : {}), }); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/get.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/get.ts index c91467f698dc1..6cd28d0202465 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/get.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/get.ts @@ -38,6 +38,7 @@ const getTestUtils = ( name: 'abc', tags: ['foo'], rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', schedule: { interval: '1m' }, enabled: true, @@ -154,6 +155,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { createdAt: response.body.createdAt, updatedAt: response.body.updatedAt, executionStatus: response.body.executionStatus, + running: false, ...(response.body.nextRun ? { nextRun: response.body.nextRun } : {}), ...(response.body.lastRun ? { lastRun: response.body.lastRun } : {}), }); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/update.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/update.ts index 4c740b3be9b97..21008836bf5eb 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/update.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/update.ts @@ -51,6 +51,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { id: createdAlert.id, tags: ['bar'], rule_type_id: 'test.noop', + running: false, consumer: 'alertsFixture', created_by: null, enabled: true, @@ -168,6 +169,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { createdAt: response.body.createdAt, updatedAt: response.body.updatedAt, executionStatus: response.body.executionStatus, + running: false, ...(response.body.nextRun ? { nextRun: response.body.nextRun } : {}), ...(response.body.lastRun ? { lastRun: response.body.lastRun } : {}), }); diff --git a/x-pack/test/api_integration/apis/synthetics/enable_default_alerting.ts b/x-pack/test/api_integration/apis/synthetics/enable_default_alerting.ts index f28d1e0f1463b..ad47a031f0628 100644 --- a/x-pack/test/api_integration/apis/synthetics/enable_default_alerting.ts +++ b/x-pack/test/api_integration/apis/synthetics/enable_default_alerting.ts @@ -80,6 +80,7 @@ export default function ({ getService }: FtrProviderContext) { scheduledTaskId: '1d72eb10-8046-11ed-9c27-7d79cab2e477', executionStatus: { status: 'pending', lastExecutionDate: '2022-12-20T09:10:15.500Z' }, ruleTypeId: 'xpack.synthetics.alerts.monitorStatus', + running: false, }, omitFields )