Skip to content

Commit

Permalink
Adding space id to warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Jun 9, 2021
1 parent 13de041 commit d314a54
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
40 changes: 40 additions & 0 deletions x-pack/plugins/alerting/server/task_runner/task_runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2238,6 +2238,46 @@ describe('Task Runner', () => {
});
});

test('correctly logs warning when Alert Task Runner throws due to failing to fetch the alert in a space', async () => {
alertsClient.get.mockImplementation(() => {
throw SavedObjectsErrorHelpers.createGenericNotFoundError('alert', '1');
});

const taskRunner = new TaskRunner(
alertType,
{
...mockedTaskInstance,
params: {
...mockedTaskInstance.params,
spaceId: 'test space',
},
},
taskRunnerFactoryInitializerParams
);

encryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValue({
id: '1',
type: 'alert',
attributes: {
apiKey: Buffer.from('123:abc').toString('base64'),
},
references: [],
});

const logger = taskRunnerFactoryInitializerParams.logger;
return taskRunner.run().catch((ex) => {
expect(ex).toMatchInlineSnapshot(`[Error: Saved object [alert/1] not found]`);
expect(logger.debug).toHaveBeenCalledWith(
`Executing Alert "1" has resulted in Error: Saved object [alert/1] not found`
);
expect(logger.warn).toHaveBeenCalledTimes(1);
expect(logger.warn).nthCalledWith(
1,
`Unable to execute rule "1" in the "test space" space because Saved object [alert/1] not found - this rule will not be rescheduled. To restart rule execution, try disabling and re-enabling this rule.`
);
});
});

test('start time is logged for new alerts', async () => {
taskRunnerFactoryInitializerParams.actionsPlugin.isActionTypeEnabled.mockReturnValue(true);
taskRunnerFactoryInitializerParams.actionsPlugin.isActionExecutable.mockReturnValue(true);
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,9 @@ export class TaskRunner<
),
schedule: resolveErr<IntervalSchedule | undefined, Error>(schedule, (error) => {
if (isAlertSavedObjectNotFoundError(error, alertId)) {
const spaceMessage = spaceId ? `in the "${spaceId}" space ` : '';
this.logger.warn(
`Unable to execute rule "${alertId}" because ${error.message} - this rule will not be rescheduled. To restart rule execution, try disabling and re-enabling this rule.`
`Unable to execute rule "${alertId}" ${spaceMessage}because ${error.message} - this rule will not be rescheduled. To restart rule execution, try disabling and re-enabling this rule.`
);
throwUnrecoverableError(error);
}
Expand Down

0 comments on commit d314a54

Please sign in to comment.