Skip to content

Commit

Permalink
[ResponseOps][Connectors] add the "service message" to the message ge…
Browse files Browse the repository at this point in the history
…nerated for errors (elastic#194213)

Resolves elastic#187288

## Summary

When a connector fails we log the error message. In this PR I updated
the log message to include the error message followed by the
serviceMessage if it's populated. This change will help provide more
detailed info in the log messages when a connector fails.


### Checklist

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios


### To verify

- Create a connector and update the executor code to make it fail
- Create rule with your connector
- Verify that the log message includes more details about the error
instead of something like the following example for email connectors:
`Action '[email connector name]' failed: error sending email"`
  • Loading branch information
doakalexi authored Sep 30, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 18465e7 commit 7730eab
Showing 2 changed files with 55 additions and 1 deletion.
48 changes: 48 additions & 0 deletions x-pack/plugins/actions/server/lib/task_runner_factory.test.ts
Original file line number Diff line number Diff line change
@@ -890,6 +890,54 @@ describe('Task Runner Factory', () => {
expect(getErrorSource(err)).toBe(TaskErrorSource.FRAMEWORK);
});

test(`will throw an error and log the error message with the serviceMessage`, async () => {
const taskRunner = taskRunnerFactory.create({
taskInstance: {
...mockedTaskInstance,
attempts: 0,
},
});

mockedEncryptedSavedObjectsClient.getDecryptedAsInternalUser.mockResolvedValueOnce({
id: '3',
type: 'action_task_params',
attributes: {
actionId: '2',
params: { baz: true },
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
},
references: [
{
id: '2',
name: 'actionRef',
type: 'action',
},
],
});
mockedActionExecutor.execute.mockResolvedValueOnce({
status: 'error',
actionId: '2',
message: 'Error message',
serviceMessage: 'Service message',
data: { foo: true },
retry: false,
errorSource: TaskErrorSource.FRAMEWORK,
});

let err;
try {
await taskRunner.run();
} catch (e) {
err = e;
}

expect(err).toBeDefined();
expect(taskRunnerFactoryInitializerParams.logger.error as jest.Mock).toHaveBeenCalledWith(
`Action '2' failed: Error message: Service message`
);
});

test(`fallbacks to FRAMEWORK error if ActionExecutor does not return any type of source'`, async () => {
const taskRunner = taskRunnerFactory.create({
taskInstance: {
8 changes: 7 additions & 1 deletion x-pack/plugins/actions/server/lib/task_runner_factory.ts
Original file line number Diff line number Diff line change
@@ -150,7 +150,13 @@ export class TaskRunnerFactory {
inMemoryMetrics.increment(IN_MEMORY_METRICS.ACTION_EXECUTIONS);
if (executorResult.status === 'error') {
inMemoryMetrics.increment(IN_MEMORY_METRICS.ACTION_FAILURES);
logger.error(`Action '${actionId}' failed: ${executorResult.message}`);

let message = executorResult.message;
if (executorResult.serviceMessage) {
message = `${message}: ${executorResult.serviceMessage}`;
}
logger.error(`Action '${actionId}' failed: ${message}`);

// Task manager error handler only kicks in when an error thrown (at this time)
// So what we have to do is throw when the return status is `error`.
throw throwRetryableError(

0 comments on commit 7730eab

Please sign in to comment.