From e5adbbde1397c0db5c93f8e2a125476cb38a30da Mon Sep 17 00:00:00 2001 From: Ersin Erdal <92688503+ersin-erdal@users.noreply.github.com> Date: Fri, 5 Apr 2024 19:23:06 +0200 Subject: [PATCH] Log the errors reported by addLastRunError to the console (#179962) Fixes: #179924 ## To verify Please follow the steps in the issue to reproduce. --- .../alerting/server/task_runner/task_runner.test.ts | 8 +++++++- .../plugins/alerting/server/task_runner/task_runner.ts | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts index 893670d906cea..c8b5cbb999743 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts @@ -3333,7 +3333,13 @@ describe('Task Runner', () => { }); expect(getErrorSource(runnerResult.taskRunError as Error)).toBe(TaskErrorSource.FRAMEWORK); - expect(runnerResult.taskRunError).toEqual(new Error('an error occurred,second error occurred')); + expect(runnerResult.taskRunError?.message).toBe( + 'Executing Rule test:1 has resulted in the following error(s): an error occurred,second error occurred' + ); + expect(logger.error).toHaveBeenCalledWith( + 'Executing Rule test:1 has resulted in the following error(s): an error occurred,second error occurred', + { tags: ['test', '1', 'rule-run-failed'] } + ); }); test('returns user error if all the errors are user error', async () => { 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 edfe77e1502c7..1f3d752f6dffb 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts @@ -716,9 +716,16 @@ export class TaskRunner< const { errors: errorsFromLastRun } = this.ruleResult.getLastRunResults(); if (errorsFromLastRun.length > 0) { const isUserError = !errorsFromLastRun.some((lastRunError) => !lastRunError.userError); + const lasRunErrorMessages = errorsFromLastRun + .map((lastRunError) => lastRunError.message) + .join(','); + const errorMessage = `Executing Rule ${this.ruleType.id}:${ruleId} has resulted in the following error(s): ${lasRunErrorMessages}`; + this.logger.error(errorMessage, { + tags: [this.ruleType.id, ruleId, 'rule-run-failed'], + }); return { taskRunError: createTaskRunError( - new Error(errorsFromLastRun.map((lastRunError) => lastRunError.message).join(',')), + new Error(errorMessage), isUserError ? TaskErrorSource.USER : TaskErrorSource.FRAMEWORK ), };