[8.x] [ResponseOps][Connectors] add the "service message" to the message generated for errors (#194213) (#194466)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][Connectors] add the "service message" to the
message generated for errors
(#194213)](https://github.com/elastic/kibana/pull/194213)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Alexi
Doak","email":"109488926+doakalexi@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-09-30T17:43:02Z","message":"[ResponseOps][Connectors]
add the \"service message\" to the message generated for errors
(#194213)\n\nResolves
https://github.com/elastic/kibana/issues/187288\r\n\r\n##
Summary\r\n\r\nWhen a connector fails we log the error message. In this
PR I updated\r\nthe log message to include the error message followed by
the\r\nserviceMessage if it's populated. This change will help provide
more\r\ndetailed info in the log messages when a connector
fails.\r\n\r\n\r\n### Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\r\n### To
verify\r\n\r\n- Create a connector and update the executor code to make
it fail\r\n- Create rule with your connector\r\n- Verify that the log
message includes more details about the error\r\ninstead of something
like the following example for email connectors:\r\n`Action '[email
connector name]' failed: error sending
email\"`","sha":"7730eaba8d631c56df92e206aafd82084e4351cc","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.16.0"],"title":"[ResponseOps][Connectors]
add the \"service message\" to the message generated for
errors","number":194213,"url":"https://github.com/elastic/kibana/pull/194213","mergeCommit":{"message":"[ResponseOps][Connectors]
add the \"service message\" to the message generated for errors
(#194213)\n\nResolves
https://github.com/elastic/kibana/issues/187288\r\n\r\n##
Summary\r\n\r\nWhen a connector fails we log the error message. In this
PR I updated\r\nthe log message to include the error message followed by
the\r\nserviceMessage if it's populated. This change will help provide
more\r\ndetailed info in the log messages when a connector
fails.\r\n\r\n\r\n### Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\r\n### To
verify\r\n\r\n- Create a connector and update the executor code to make
it fail\r\n- Create rule with your connector\r\n- Verify that the log
message includes more details about the error\r\ninstead of something
like the following example for email connectors:\r\n`Action '[email
connector name]' failed: error sending
email\"`","sha":"7730eaba8d631c56df92e206aafd82084e4351cc"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194213","number":194213,"mergeCommit":{"message":"[ResponseOps][Connectors]
add the \"service message\" to the message generated for errors
(#194213)\n\nResolves
https://github.com/elastic/kibana/issues/187288\r\n\r\n##
Summary\r\n\r\nWhen a connector fails we log the error message. In this
PR I updated\r\nthe log message to include the error message followed by
the\r\nserviceMessage if it's populated. This change will help provide
more\r\ndetailed info in the log messages when a connector
fails.\r\n\r\n\r\n### Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n\r\n### To
verify\r\n\r\n- Create a connector and update the executor code to make
it fail\r\n- Create rule with your connector\r\n- Verify that the log
message includes more details about the error\r\ninstead of something
like the following example for email connectors:\r\n`Action '[email
connector name]' failed: error sending
email\"`","sha":"7730eaba8d631c56df92e206aafd82084e4351cc"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Alexi Doak <109488926+doakalexi@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2024-10-01 05:22:31 +10:00 committed by GitHub
parent f026cdd57d
commit 8d9e16b7dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 1 deletions

View file

@ -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: {

View file

@ -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(