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

Enhance task failure log to include error source in tags #199406

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

mikecote
Copy link
Contributor

@mikecote mikecote commented Nov 8, 2024

Resolves #199346

In this PR I'm adding user-error and framework-error tags to the associated task failure logs.

To verify

You can either use the jest test to observe the returned flags or set your logging to JSON and use the following code samples to test various types of errors.

kibana.yml to set logging to JSON

logging:
  appenders:
    json-layout:
      type: console
      layout:
        type: json
  root:
    appenders: [json-layout]

Code samples throwing various types of errors.

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 89432e18220..129b53f71b4 100644
--- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts
@@ -649,6 +649,10 @@ export class TaskRunner<
       schedule: taskSchedule,
     } = this.taskInstance;

+    // throw createTaskRunError(new Error('foo'), TaskErrorSource.USER);
+    // throw createTaskRunError(new Error('foo'), TaskErrorSource.FRAMEWORK);
+    // throw new Error('foo');
+
     this.logger = createTaskRunnerLogger({ logger: this.logger, tags: [ruleId, this.ruleType.id] });

     let stateWithMetrics: Result<RuleTaskStateAndMetrics, Error>;

@mikecote mikecote added Feature:Task Manager Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) labels Nov 8, 2024
@mikecote mikecote self-assigned this Nov 8, 2024
@mikecote mikecote added release_note:skip Skip the PR/issue when compiling release notes v9.0.0 backport:version Backport to applied version labels v8.17.0 labels Nov 8, 2024
@mikecote mikecote marked this pull request as ready for review November 8, 2024 12:39
@mikecote mikecote requested a review from a team as a code owner November 8, 2024 12:39
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Though I'm a little surprised some existing tests didn't fail. I guess we didn't have any testing exhaustive tags on these messages, that would be failing with a new framework-error tag in them (the default).

@elasticmachine
Copy link
Contributor

💔 Build Failed

Failed CI Steps

History

cc @mikecote

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @mikecote

@mikecote
Copy link
Contributor Author

Though I'm a little surprised some existing tests didn't fail. I guess we didn't have any testing exhaustive tags on these messages, that would be failing with a new framework-error tag in them (the default).

The tests I updated were to only ones covering the error thrown during task run phase. Everything else seemed to cover the happy paths.

@mikecote mikecote merged commit 544525d into elastic:main Nov 13, 2024
40 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11824702329

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 13, 2024
)

Resolves elastic#199346

In this PR I'm adding `user-error` and `framework-error` tags to the
associated task failure logs.

## To verify

You can either use the jest test to observe the returned flags or set
your logging to JSON and use the following code samples to test various
types of errors.

kibana.yml to set logging to JSON
```
logging:
  appenders:
    json-layout:
      type: console
      layout:
        type: json
  root:
    appenders: [json-layout]
```

Code samples throwing various types of errors.
```
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 89432e18220..129b53f71b4 100644
--- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts
@@ -649,6 +649,10 @@ export class TaskRunner<
       schedule: taskSchedule,
     } = this.taskInstance;

+    // throw createTaskRunError(new Error('foo'), TaskErrorSource.USER);
+    // throw createTaskRunError(new Error('foo'), TaskErrorSource.FRAMEWORK);
+    // throw new Error('foo');
+
     this.logger = createTaskRunnerLogger({ logger: this.logger, tags: [ruleId, this.ruleType.id] });

     let stateWithMetrics: Result<RuleTaskStateAndMetrics, Error>;
```

(cherry picked from commit 544525d)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Nov 14, 2024
…) (#200082)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Enhance task failure log to include error source in tags
(#199406)](#199406)

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

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

<!--BACKPORT [{"author":{"name":"Mike
Côté","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-13T19:48:18Z","message":"Enhance
task failure log to include error source in tags (#199406)\n\nResolves
https://github.com/elastic/kibana/issues/199346\r\n\r\nIn this PR I'm
adding `user-error` and `framework-error` tags to the\r\nassociated task
failure logs.\r\n\r\n## To verify\r\n\r\nYou can either use the jest
test to observe the returned flags or set\r\nyour logging to JSON and
use the following code samples to test various\r\ntypes of
errors.\r\n\r\nkibana.yml to set logging to JSON\r\n```\r\nlogging:\r\n
appenders:\r\n json-layout:\r\n type: console\r\n layout:\r\n type:
json\r\n root:\r\n appenders: [json-layout]\r\n```\r\n\r\nCode samples
throwing various types of errors.\r\n```\r\ndiff --git
a/x-pack/plugins/alerting/server/task_runner/task_runner.ts
b/x-pack/plugins/alerting/server/task_runner/task_runner.ts\r\nindex
89432e18220..129b53f71b4 100644\r\n---
a/x-pack/plugins/alerting/server/task_runner/task_runner.ts\r\n+++
b/x-pack/plugins/alerting/server/task_runner/task_runner.ts\r\n@@ -649,6
+649,10 @@ export class TaskRunner<\r\n schedule: taskSchedule,\r\n } =
this.taskInstance;\r\n\r\n+ // throw createTaskRunError(new
Error('foo'), TaskErrorSource.USER);\r\n+ // throw
createTaskRunError(new Error('foo'), TaskErrorSource.FRAMEWORK);\r\n+ //
throw new Error('foo');\r\n+\r\n this.logger = createTaskRunnerLogger({
logger: this.logger, tags: [ruleId, this.ruleType.id] });\r\n\r\n let
stateWithMetrics: Result<RuleTaskStateAndMetrics,
Error>;\r\n```","sha":"544525d497d6c833c9a861061876412d3198c5e9","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Feature:Task
Manager","Team:ResponseOps","v9.0.0","backport:version","v8.17.0"],"title":"Enhance
task failure log to include error source in
tags","number":199406,"url":"https://github.com/elastic/kibana/pull/199406","mergeCommit":{"message":"Enhance
task failure log to include error source in tags (#199406)\n\nResolves
https://github.com/elastic/kibana/issues/199346\r\n\r\nIn this PR I'm
adding `user-error` and `framework-error` tags to the\r\nassociated task
failure logs.\r\n\r\n## To verify\r\n\r\nYou can either use the jest
test to observe the returned flags or set\r\nyour logging to JSON and
use the following code samples to test various\r\ntypes of
errors.\r\n\r\nkibana.yml to set logging to JSON\r\n```\r\nlogging:\r\n
appenders:\r\n json-layout:\r\n type: console\r\n layout:\r\n type:
json\r\n root:\r\n appenders: [json-layout]\r\n```\r\n\r\nCode samples
throwing various types of errors.\r\n```\r\ndiff --git
a/x-pack/plugins/alerting/server/task_runner/task_runner.ts
b/x-pack/plugins/alerting/server/task_runner/task_runner.ts\r\nindex
89432e18220..129b53f71b4 100644\r\n---
a/x-pack/plugins/alerting/server/task_runner/task_runner.ts\r\n+++
b/x-pack/plugins/alerting/server/task_runner/task_runner.ts\r\n@@ -649,6
+649,10 @@ export class TaskRunner<\r\n schedule: taskSchedule,\r\n } =
this.taskInstance;\r\n\r\n+ // throw createTaskRunError(new
Error('foo'), TaskErrorSource.USER);\r\n+ // throw
createTaskRunError(new Error('foo'), TaskErrorSource.FRAMEWORK);\r\n+ //
throw new Error('foo');\r\n+\r\n this.logger = createTaskRunnerLogger({
logger: this.logger, tags: [ruleId, this.ruleType.id] });\r\n\r\n let
stateWithMetrics: Result<RuleTaskStateAndMetrics,
Error>;\r\n```","sha":"544525d497d6c833c9a861061876412d3198c5e9"}},"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/199406","number":199406,"mergeCommit":{"message":"Enhance
task failure log to include error source in tags (#199406)\n\nResolves
https://github.com/elastic/kibana/issues/199346\r\n\r\nIn this PR I'm
adding `user-error` and `framework-error` tags to the\r\nassociated task
failure logs.\r\n\r\n## To verify\r\n\r\nYou can either use the jest
test to observe the returned flags or set\r\nyour logging to JSON and
use the following code samples to test various\r\ntypes of
errors.\r\n\r\nkibana.yml to set logging to JSON\r\n```\r\nlogging:\r\n
appenders:\r\n json-layout:\r\n type: console\r\n layout:\r\n type:
json\r\n root:\r\n appenders: [json-layout]\r\n```\r\n\r\nCode samples
throwing various types of errors.\r\n```\r\ndiff --git
a/x-pack/plugins/alerting/server/task_runner/task_runner.ts
b/x-pack/plugins/alerting/server/task_runner/task_runner.ts\r\nindex
89432e18220..129b53f71b4 100644\r\n---
a/x-pack/plugins/alerting/server/task_runner/task_runner.ts\r\n+++
b/x-pack/plugins/alerting/server/task_runner/task_runner.ts\r\n@@ -649,6
+649,10 @@ export class TaskRunner<\r\n schedule: taskSchedule,\r\n } =
this.taskInstance;\r\n\r\n+ // throw createTaskRunError(new
Error('foo'), TaskErrorSource.USER);\r\n+ // throw
createTaskRunError(new Error('foo'), TaskErrorSource.FRAMEWORK);\r\n+ //
throw new Error('foo');\r\n+\r\n this.logger = createTaskRunnerLogger({
logger: this.logger, tags: [ruleId, this.ruleType.id] });\r\n\r\n let
stateWithMetrics: Result<RuleTaskStateAndMetrics,
Error>;\r\n```","sha":"544525d497d6c833c9a861061876412d3198c5e9"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Mike Côté <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Nov 18, 2024
)

Resolves elastic#199346

In this PR I'm adding `user-error` and `framework-error` tags to the
associated task failure logs.

## To verify

You can either use the jest test to observe the returned flags or set
your logging to JSON and use the following code samples to test various
types of errors.

kibana.yml to set logging to JSON
```
logging:
  appenders:
    json-layout:
      type: console
      layout:
        type: json
  root:
    appenders: [json-layout]
```

Code samples throwing various types of errors.
```
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 89432e18220..129b53f71b4 100644
--- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts
@@ -649,6 +649,10 @@ export class TaskRunner<
       schedule: taskSchedule,
     } = this.taskInstance;

+    // throw createTaskRunError(new Error('foo'), TaskErrorSource.USER);
+    // throw createTaskRunError(new Error('foo'), TaskErrorSource.FRAMEWORK);
+    // throw new Error('foo');
+
     this.logger = createTaskRunnerLogger({ logger: this.logger, tags: [ruleId, this.ruleType.id] });

     let stateWithMetrics: Result<RuleTaskStateAndMetrics, Error>;
```
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Nov 18, 2024
)

Resolves elastic#199346

In this PR I'm adding `user-error` and `framework-error` tags to the
associated task failure logs.

## To verify

You can either use the jest test to observe the returned flags or set
your logging to JSON and use the following code samples to test various
types of errors.

kibana.yml to set logging to JSON
```
logging:
  appenders:
    json-layout:
      type: console
      layout:
        type: json
  root:
    appenders: [json-layout]
```

Code samples throwing various types of errors.
```
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 89432e18220..129b53f71b4 100644
--- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts
@@ -649,6 +649,10 @@ export class TaskRunner<
       schedule: taskSchedule,
     } = this.taskInstance;

+    // throw createTaskRunError(new Error('foo'), TaskErrorSource.USER);
+    // throw createTaskRunError(new Error('foo'), TaskErrorSource.FRAMEWORK);
+    // throw new Error('foo');
+
     this.logger = createTaskRunnerLogger({ logger: this.logger, tags: [ruleId, this.ruleType.id] });

     let stateWithMetrics: Result<RuleTaskStateAndMetrics, Error>;
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels Feature:Task Manager release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add user-error and framework-error tags to task manager run failure logs
4 participants