Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to throw user type errors in the connector executor code #180419

Closed
mikecote opened this issue Apr 9, 2024 · 0 comments · Fixed by #184015
Closed

Unable to throw user type errors in the connector executor code #180419

mikecote opened this issue Apr 9, 2024 · 0 comments · Fixed by #184015
Assignees
Labels
bug Fixes for quality problems that affect the customer experience Feature:Actions Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@mikecote
Copy link
Contributor

mikecote commented Apr 9, 2024

I am unable to inject code in a connector executor that will mark an error as a user error, it gets flagged as a framework error instead.

Steps to reproduce

  1. Apply the following diff
diff --git a/x-pack/plugins/stack_connectors/server/connector_types/server_log/index.ts b/x-pack/plugins/stack_connectors/server/connector_types/server_log/index.ts
index 4d404369ba1..d3e74af6e36 100644
--- a/x-pack/plugins/stack_connectors/server/connector_types/server_log/index.ts
+++ b/x-pack/plugins/stack_connectors/server/connector_types/server_log/index.ts
@@ -14,6 +14,7 @@ import type {
   ActionTypeExecutorOptions as ConnectorTypeExecutorOptions,
   ActionTypeExecutorResult as ConnectorTypeExecutorResult,
 } from '@kbn/actions-plugin/server/types';
+import { createTaskRunError, TaskErrorSource } from '@kbn/task-manager-plugin/server';
 import {
   AlertingConnectorFeatureId,
   UptimeConnectorFeatureId,
@@ -74,6 +75,8 @@ async function executor(
 ): Promise<ConnectorTypeExecutorResult<void>> {
   const { actionId, params, logger } = execOptions;

+  throw createTaskRunError(new Error('fail'), TaskErrorSource.USER);
+
   const sanitizedMessage = withoutControlCharacters(params.message);
   try {
     (logger[params.level] as Logger['info'])<LogMeta>(`Server log: ${sanitizedMessage}`);
  1. Load the metrics via /api/task_manager/metrics
  2. Create a server log connector
  3. Create a rule that fires actions, and associate a server log action
  4. Wait for the server log to fail
  5. Load the metrics again via /api/task_manager/metrics
  6. Note the actions:.server-log has zero user_errors, but one framework_errors

Expected outcome

Errors thrown as user errors in connector executor code to be marked as user_errors in the task manager metrics.

cc @elastic/response-ops-execution @kobelb @heespi

@mikecote mikecote added the bug Fixes for quality problems that affect the customer experience label Apr 9, 2024
@botelastic botelastic bot added the needs-team Issues missing a team label label Apr 9, 2024
@mikecote mikecote added the Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) label Apr 9, 2024
@botelastic botelastic bot removed the needs-team Issues missing a team label label Apr 9, 2024
@mikecote mikecote added Feature:Actions needs-team Issues missing a team label labels Apr 9, 2024
@botelastic botelastic bot removed the needs-team Issues missing a team label label Apr 9, 2024
@ymao1 ymao1 self-assigned this May 20, 2024
ymao1 added a commit that referenced this issue May 24, 2024
…rs if defined. (#184015)

Resolves #180419

## Summary

Updates action executor to use error source from errors thrown within
the connector type executor, defaulting to framework error if no error
source is specified.

## To Verify

Modify the server log connector to throw a user error:

```
--- a/x-pack/plugins/stack_connectors/server/connector_types/server_log/index.ts
+++ b/x-pack/plugins/stack_connectors/server/connector_types/server_log/index.ts
@@ -14,6 +14,7 @@ import type {
   ActionTypeExecutorOptions as ConnectorTypeExecutorOptions,
   ActionTypeExecutorResult as ConnectorTypeExecutorResult,
 } from '@kbn/actions-plugin/server/types';
+import { createTaskRunError, TaskErrorSource } from '@kbn/task-manager-plugin/server';
 import {
   AlertingConnectorFeatureId,
   UptimeConnectorFeatureId,
@@ -78,6 +79,7 @@ async function executor(
   execOptions: ServerLogConnectorTypeExecutorOptions
 ): Promise<ConnectorTypeExecutorResult<void>> {
   const { actionId, params, logger } = execOptions;
+  throw createTaskRunError(new Error('fail'), TaskErrorSource.USER);

   const sanitizedMessage = withoutControlCharacters(params.message);
```

Create a rule that will trigger a server log action. Let the action run
and then check the metrics endpoint at
https://localhost:5601/api/task_manager/metrics?reset=false to see that
this error was captured as a user error.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
rshen91 pushed a commit to rshen91/kibana that referenced this issue May 30, 2024
…rs if defined. (elastic#184015)

Resolves elastic#180419

## Summary

Updates action executor to use error source from errors thrown within
the connector type executor, defaulting to framework error if no error
source is specified.

## To Verify

Modify the server log connector to throw a user error:

```
--- a/x-pack/plugins/stack_connectors/server/connector_types/server_log/index.ts
+++ b/x-pack/plugins/stack_connectors/server/connector_types/server_log/index.ts
@@ -14,6 +14,7 @@ import type {
   ActionTypeExecutorOptions as ConnectorTypeExecutorOptions,
   ActionTypeExecutorResult as ConnectorTypeExecutorResult,
 } from '@kbn/actions-plugin/server/types';
+import { createTaskRunError, TaskErrorSource } from '@kbn/task-manager-plugin/server';
 import {
   AlertingConnectorFeatureId,
   UptimeConnectorFeatureId,
@@ -78,6 +79,7 @@ async function executor(
   execOptions: ServerLogConnectorTypeExecutorOptions
 ): Promise<ConnectorTypeExecutorResult<void>> {
   const { actionId, params, logger } = execOptions;
+  throw createTaskRunError(new Error('fail'), TaskErrorSource.USER);

   const sanitizedMessage = withoutControlCharacters(params.message);
```

Create a rule that will trigger a server log action. Let the action run
and then check the metrics endpoint at
https://localhost:5601/api/task_manager/metrics?reset=false to see that
this error was captured as a user error.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Actions Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants