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

[Response Ops][Alerting] Alerting event logger should not throw error when ad hoc task runner cannot load saved object #201637

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

ymao1
Copy link
Contributor

@ymao1 ymao1 commented Nov 25, 2024

Summary

The ad-hoc task runner loads the ad_hoc_run saved object that contains rule information when it first starts running. If the saved object cannot be loaded due to saved object not found (likely because the SO was deleted), the alerting event logger was throwing an error because it didn't have the rule information to populate the execute-backfill event. This PR fixes it so we're not throwing an error and writes the execute-backfill event with whatever information is available.

To Verify

  1. Modify the ad-hoc task runner to load a random saved object
--- a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
@@ -294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask {
         const adHocRunSO: SavedObject<AdHocRunSO> =
           await this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(
             AD_HOC_RUN_SAVED_OBJECT_TYPE,
-            adHocRunParamsId,
+            `abcdefgh`,
+            // adHocRunParamsId,
             { namespace }
  1. Create a detection rule and then schedule backfill run for it. You should see the execution fail with Executing ad hoc run with id \"7401d1f1-73fc-4483-acd5-edf6180028ce\" has resulted in Error: Saved object [ad_hoc_run_params/abcdefgh] not found but you should NOT see any errors from task manager like Task ad_hoc_run-backfill "40fd4c52-411f-462c-b285-87e33520bd5b" failed: Error: AlertingEventLogger not initialized

@ymao1 ymao1 changed the title [Response Ops][Alerting] Alerting event logger should not throw error when ad hoc task runner … [Response Ops][Alerting] Alerting event logger should not throw error when ad hoc task runner cannot load saved object Nov 25, 2024
@ymao1 ymao1 self-assigned this Nov 25, 2024
@ymao1 ymao1 added Feature:Alerting Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v9.0.0 v8.17.0 v8.18.0 release_note:skip Skip the PR/issue when compiling release notes labels Nov 25, 2024
@ymao1 ymao1 marked this pull request as ready for review November 25, 2024 17:50
@ymao1 ymao1 requested a review from a team as a code owner November 25, 2024 17:50
@elasticmachine
Copy link
Contributor

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

@ymao1 ymao1 added the backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) label Nov 25, 2024
@ymao1 ymao1 requested review from pmuellr and adcoelho November 25, 2024 17:51
@ymao1
Copy link
Contributor Author

ymao1 commented Dec 2, 2024

@elasticmachine merge upstream

Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

Changes LGTM! Tested locally and verified it works

@ymao1
Copy link
Contributor Author

ymao1 commented Dec 4, 2024

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @ymao1

@ymao1 ymao1 merged commit 6a4fe4f into elastic:main Dec 4, 2024
8 checks passed
@ymao1 ymao1 deleted the backfill-saved-object-not-found-bug branch December 4, 2024 15:09
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.17, 8.x

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 4, 2024
… when ad hoc task runner cannot load saved object (elastic#201637)

## Summary

The ad-hoc task runner loads the `ad_hoc_run` saved object that contains
rule information when it first starts running. If the saved object
cannot be loaded due to saved object not found (likely because the SO
was deleted), the alerting event logger was throwing an error because it
didn't have the rule information to populate the `execute-backfill`
event. This PR fixes it so we're not throwing an error and writes the
`execute-backfill` event with whatever information is available.

## To Verify

1. Modify the ad-hoc task runner to load a random saved object

```
--- a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
@@ -294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask {
         const adHocRunSO: SavedObject<AdHocRunSO> =
           await this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(
             AD_HOC_RUN_SAVED_OBJECT_TYPE,
-            adHocRunParamsId,
+            `abcdefgh`,
+            // adHocRunParamsId,
             { namespace }
```

2. Create a detection rule and then schedule backfill run for it. You
should see the execution fail with `Executing ad hoc run with id
\"7401d1f1-73fc-4483-acd5-edf6180028ce\" has resulted in Error: Saved
object [ad_hoc_run_params/abcdefgh] not found` but you should NOT see
any errors from task manager like `Task ad_hoc_run-backfill
"40fd4c52-411f-462c-b285-87e33520bd5b" failed: Error:
AlertingEventLogger not initialized`

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 6a4fe4f)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 4, 2024
… when ad hoc task runner cannot load saved object (elastic#201637)

## Summary

The ad-hoc task runner loads the `ad_hoc_run` saved object that contains
rule information when it first starts running. If the saved object
cannot be loaded due to saved object not found (likely because the SO
was deleted), the alerting event logger was throwing an error because it
didn't have the rule information to populate the `execute-backfill`
event. This PR fixes it so we're not throwing an error and writes the
`execute-backfill` event with whatever information is available.

## To Verify

1. Modify the ad-hoc task runner to load a random saved object

```
--- a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
@@ -294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask {
         const adHocRunSO: SavedObject<AdHocRunSO> =
           await this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(
             AD_HOC_RUN_SAVED_OBJECT_TYPE,
-            adHocRunParamsId,
+            `abcdefgh`,
+            // adHocRunParamsId,
             { namespace }
```

2. Create a detection rule and then schedule backfill run for it. You
should see the execution fail with `Executing ad hoc run with id
\"7401d1f1-73fc-4483-acd5-edf6180028ce\" has resulted in Error: Saved
object [ad_hoc_run_params/abcdefgh] not found` but you should NOT see
any errors from task manager like `Task ad_hoc_run-backfill
"40fd4c52-411f-462c-b285-87e33520bd5b" failed: Error:
AlertingEventLogger not initialized`

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 6a4fe4f)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.17
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 Dec 4, 2024
…w error when ad hoc task runner cannot load saved object (#201637) (#202957)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Response Ops][Alerting] Alerting event logger should not throw error
when ad hoc task runner cannot load saved object
(#201637)](#201637)

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

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

<!--BACKPORT [{"author":{"name":"Ying
Mao","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-04T15:09:30Z","message":"[Response
Ops][Alerting] Alerting event logger should not throw error when ad hoc
task runner cannot load saved object (#201637)\n\n## Summary\r\n\r\nThe
ad-hoc task runner loads the `ad_hoc_run` saved object that
contains\r\nrule information when it first starts running. If the saved
object\r\ncannot be loaded due to saved object not found (likely because
the SO\r\nwas deleted), the alerting event logger was throwing an error
because it\r\ndidn't have the rule information to populate the
`execute-backfill`\r\nevent. This PR fixes it so we're not throwing an
error and writes the\r\n`execute-backfill` event with whatever
information is available.\r\n\r\n## To Verify\r\n\r\n1. Modify the
ad-hoc task runner to load a random saved object \r\n\r\n```\r\n---
a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n+++
b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n@@
-294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask
{\r\n const adHocRunSO: SavedObject<AdHocRunSO> =\r\n await
this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(\r\n
AD_HOC_RUN_SAVED_OBJECT_TYPE,\r\n- adHocRunParamsId,\r\n+
`abcdefgh`,\r\n+ // adHocRunParamsId,\r\n { namespace }\r\n```\r\n\r\n2.
Create a detection rule and then schedule backfill run for it.
You\r\nshould see the execution fail with `Executing ad hoc run with
id\r\n\\\"7401d1f1-73fc-4483-acd5-edf6180028ce\\\" has resulted in
Error: Saved\r\nobject [ad_hoc_run_params/abcdefgh] not found` but you
should NOT see\r\nany errors from task manager like `Task
ad_hoc_run-backfill\r\n\"40fd4c52-411f-462c-b285-87e33520bd5b\" failed:
Error:\r\nAlertingEventLogger not initialized`\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"6a4fe4f73dbab778efcd4f329ba9a72a79cf9e3c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Alerting","release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.17.0","v8.18.0"],"title":"[Response
Ops][Alerting] Alerting event logger should not throw error when ad hoc
task runner cannot load saved
object","number":201637,"url":"https://github.com/elastic/kibana/pull/201637","mergeCommit":{"message":"[Response
Ops][Alerting] Alerting event logger should not throw error when ad hoc
task runner cannot load saved object (#201637)\n\n## Summary\r\n\r\nThe
ad-hoc task runner loads the `ad_hoc_run` saved object that
contains\r\nrule information when it first starts running. If the saved
object\r\ncannot be loaded due to saved object not found (likely because
the SO\r\nwas deleted), the alerting event logger was throwing an error
because it\r\ndidn't have the rule information to populate the
`execute-backfill`\r\nevent. This PR fixes it so we're not throwing an
error and writes the\r\n`execute-backfill` event with whatever
information is available.\r\n\r\n## To Verify\r\n\r\n1. Modify the
ad-hoc task runner to load a random saved object \r\n\r\n```\r\n---
a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n+++
b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n@@
-294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask
{\r\n const adHocRunSO: SavedObject<AdHocRunSO> =\r\n await
this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(\r\n
AD_HOC_RUN_SAVED_OBJECT_TYPE,\r\n- adHocRunParamsId,\r\n+
`abcdefgh`,\r\n+ // adHocRunParamsId,\r\n { namespace }\r\n```\r\n\r\n2.
Create a detection rule and then schedule backfill run for it.
You\r\nshould see the execution fail with `Executing ad hoc run with
id\r\n\\\"7401d1f1-73fc-4483-acd5-edf6180028ce\\\" has resulted in
Error: Saved\r\nobject [ad_hoc_run_params/abcdefgh] not found` but you
should NOT see\r\nany errors from task manager like `Task
ad_hoc_run-backfill\r\n\"40fd4c52-411f-462c-b285-87e33520bd5b\" failed:
Error:\r\nAlertingEventLogger not initialized`\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"6a4fe4f73dbab778efcd4f329ba9a72a79cf9e3c"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201637","number":201637,"mergeCommit":{"message":"[Response
Ops][Alerting] Alerting event logger should not throw error when ad hoc
task runner cannot load saved object (#201637)\n\n## Summary\r\n\r\nThe
ad-hoc task runner loads the `ad_hoc_run` saved object that
contains\r\nrule information when it first starts running. If the saved
object\r\ncannot be loaded due to saved object not found (likely because
the SO\r\nwas deleted), the alerting event logger was throwing an error
because it\r\ndidn't have the rule information to populate the
`execute-backfill`\r\nevent. This PR fixes it so we're not throwing an
error and writes the\r\n`execute-backfill` event with whatever
information is available.\r\n\r\n## To Verify\r\n\r\n1. Modify the
ad-hoc task runner to load a random saved object \r\n\r\n```\r\n---
a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n+++
b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n@@
-294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask
{\r\n const adHocRunSO: SavedObject<AdHocRunSO> =\r\n await
this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(\r\n
AD_HOC_RUN_SAVED_OBJECT_TYPE,\r\n- adHocRunParamsId,\r\n+
`abcdefgh`,\r\n+ // adHocRunParamsId,\r\n { namespace }\r\n```\r\n\r\n2.
Create a detection rule and then schedule backfill run for it.
You\r\nshould see the execution fail with `Executing ad hoc run with
id\r\n\\\"7401d1f1-73fc-4483-acd5-edf6180028ce\\\" has resulted in
Error: Saved\r\nobject [ad_hoc_run_params/abcdefgh] not found` but you
should NOT see\r\nany errors from task manager like `Task
ad_hoc_run-backfill\r\n\"40fd4c52-411f-462c-b285-87e33520bd5b\" failed:
Error:\r\nAlertingEventLogger not initialized`\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"6a4fe4f73dbab778efcd4f329ba9a72a79cf9e3c"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Ying Mao <[email protected]>
kibanamachine added a commit that referenced this pull request Dec 4, 2024
… error when ad hoc task runner cannot load saved object (#201637) (#202958)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Response Ops][Alerting] Alerting event logger should not throw error
when ad hoc task runner cannot load saved object
(#201637)](#201637)

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

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

<!--BACKPORT [{"author":{"name":"Ying
Mao","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-04T15:09:30Z","message":"[Response
Ops][Alerting] Alerting event logger should not throw error when ad hoc
task runner cannot load saved object (#201637)\n\n## Summary\r\n\r\nThe
ad-hoc task runner loads the `ad_hoc_run` saved object that
contains\r\nrule information when it first starts running. If the saved
object\r\ncannot be loaded due to saved object not found (likely because
the SO\r\nwas deleted), the alerting event logger was throwing an error
because it\r\ndidn't have the rule information to populate the
`execute-backfill`\r\nevent. This PR fixes it so we're not throwing an
error and writes the\r\n`execute-backfill` event with whatever
information is available.\r\n\r\n## To Verify\r\n\r\n1. Modify the
ad-hoc task runner to load a random saved object \r\n\r\n```\r\n---
a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n+++
b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n@@
-294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask
{\r\n const adHocRunSO: SavedObject<AdHocRunSO> =\r\n await
this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(\r\n
AD_HOC_RUN_SAVED_OBJECT_TYPE,\r\n- adHocRunParamsId,\r\n+
`abcdefgh`,\r\n+ // adHocRunParamsId,\r\n { namespace }\r\n```\r\n\r\n2.
Create a detection rule and then schedule backfill run for it.
You\r\nshould see the execution fail with `Executing ad hoc run with
id\r\n\\\"7401d1f1-73fc-4483-acd5-edf6180028ce\\\" has resulted in
Error: Saved\r\nobject [ad_hoc_run_params/abcdefgh] not found` but you
should NOT see\r\nany errors from task manager like `Task
ad_hoc_run-backfill\r\n\"40fd4c52-411f-462c-b285-87e33520bd5b\" failed:
Error:\r\nAlertingEventLogger not initialized`\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"6a4fe4f73dbab778efcd4f329ba9a72a79cf9e3c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Alerting","release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.17.0","v8.18.0"],"title":"[Response
Ops][Alerting] Alerting event logger should not throw error when ad hoc
task runner cannot load saved
object","number":201637,"url":"https://github.com/elastic/kibana/pull/201637","mergeCommit":{"message":"[Response
Ops][Alerting] Alerting event logger should not throw error when ad hoc
task runner cannot load saved object (#201637)\n\n## Summary\r\n\r\nThe
ad-hoc task runner loads the `ad_hoc_run` saved object that
contains\r\nrule information when it first starts running. If the saved
object\r\ncannot be loaded due to saved object not found (likely because
the SO\r\nwas deleted), the alerting event logger was throwing an error
because it\r\ndidn't have the rule information to populate the
`execute-backfill`\r\nevent. This PR fixes it so we're not throwing an
error and writes the\r\n`execute-backfill` event with whatever
information is available.\r\n\r\n## To Verify\r\n\r\n1. Modify the
ad-hoc task runner to load a random saved object \r\n\r\n```\r\n---
a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n+++
b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n@@
-294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask
{\r\n const adHocRunSO: SavedObject<AdHocRunSO> =\r\n await
this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(\r\n
AD_HOC_RUN_SAVED_OBJECT_TYPE,\r\n- adHocRunParamsId,\r\n+
`abcdefgh`,\r\n+ // adHocRunParamsId,\r\n { namespace }\r\n```\r\n\r\n2.
Create a detection rule and then schedule backfill run for it.
You\r\nshould see the execution fail with `Executing ad hoc run with
id\r\n\\\"7401d1f1-73fc-4483-acd5-edf6180028ce\\\" has resulted in
Error: Saved\r\nobject [ad_hoc_run_params/abcdefgh] not found` but you
should NOT see\r\nany errors from task manager like `Task
ad_hoc_run-backfill\r\n\"40fd4c52-411f-462c-b285-87e33520bd5b\" failed:
Error:\r\nAlertingEventLogger not initialized`\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"6a4fe4f73dbab778efcd4f329ba9a72a79cf9e3c"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201637","number":201637,"mergeCommit":{"message":"[Response
Ops][Alerting] Alerting event logger should not throw error when ad hoc
task runner cannot load saved object (#201637)\n\n## Summary\r\n\r\nThe
ad-hoc task runner loads the `ad_hoc_run` saved object that
contains\r\nrule information when it first starts running. If the saved
object\r\ncannot be loaded due to saved object not found (likely because
the SO\r\nwas deleted), the alerting event logger was throwing an error
because it\r\ndidn't have the rule information to populate the
`execute-backfill`\r\nevent. This PR fixes it so we're not throwing an
error and writes the\r\n`execute-backfill` event with whatever
information is available.\r\n\r\n## To Verify\r\n\r\n1. Modify the
ad-hoc task runner to load a random saved object \r\n\r\n```\r\n---
a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n+++
b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts\r\n@@
-294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask
{\r\n const adHocRunSO: SavedObject<AdHocRunSO> =\r\n await
this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(\r\n
AD_HOC_RUN_SAVED_OBJECT_TYPE,\r\n- adHocRunParamsId,\r\n+
`abcdefgh`,\r\n+ // adHocRunParamsId,\r\n { namespace }\r\n```\r\n\r\n2.
Create a detection rule and then schedule backfill run for it.
You\r\nshould see the execution fail with `Executing ad hoc run with
id\r\n\\\"7401d1f1-73fc-4483-acd5-edf6180028ce\\\" has resulted in
Error: Saved\r\nobject [ad_hoc_run_params/abcdefgh] not found` but you
should NOT see\r\nany errors from task manager like `Task
ad_hoc_run-backfill\r\n\"40fd4c52-411f-462c-b285-87e33520bd5b\" failed:
Error:\r\nAlertingEventLogger not initialized`\r\n\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"6a4fe4f73dbab778efcd4f329ba9a72a79cf9e3c"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Ying Mao <[email protected]>
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
… when ad hoc task runner cannot load saved object (elastic#201637)

## Summary

The ad-hoc task runner loads the `ad_hoc_run` saved object that contains
rule information when it first starts running. If the saved object
cannot be loaded due to saved object not found (likely because the SO
was deleted), the alerting event logger was throwing an error because it
didn't have the rule information to populate the `execute-backfill`
event. This PR fixes it so we're not throwing an error and writes the
`execute-backfill` event with whatever information is available.

## To Verify

1. Modify the ad-hoc task runner to load a random saved object 

```
--- a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
@@ -294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask {
         const adHocRunSO: SavedObject<AdHocRunSO> =
           await this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(
             AD_HOC_RUN_SAVED_OBJECT_TYPE,
-            adHocRunParamsId,
+            `abcdefgh`,
+            // adHocRunParamsId,
             { namespace }
```

2. Create a detection rule and then schedule backfill run for it. You
should see the execution fail with `Executing ad hoc run with id
\"7401d1f1-73fc-4483-acd5-edf6180028ce\" has resulted in Error: Saved
object [ad_hoc_run_params/abcdefgh] not found` but you should NOT see
any errors from task manager like `Task ad_hoc_run-backfill
"40fd4c52-411f-462c-b285-87e33520bd5b" failed: Error:
AlertingEventLogger not initialized`

Co-authored-by: Elastic Machine <[email protected]>
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Dec 9, 2024
… when ad hoc task runner cannot load saved object (elastic#201637)

## Summary

The ad-hoc task runner loads the `ad_hoc_run` saved object that contains
rule information when it first starts running. If the saved object
cannot be loaded due to saved object not found (likely because the SO
was deleted), the alerting event logger was throwing an error because it
didn't have the rule information to populate the `execute-backfill`
event. This PR fixes it so we're not throwing an error and writes the
`execute-backfill` event with whatever information is available.

## To Verify

1. Modify the ad-hoc task runner to load a random saved object 

```
--- a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
@@ -294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask {
         const adHocRunSO: SavedObject<AdHocRunSO> =
           await this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(
             AD_HOC_RUN_SAVED_OBJECT_TYPE,
-            adHocRunParamsId,
+            `abcdefgh`,
+            // adHocRunParamsId,
             { namespace }
```

2. Create a detection rule and then schedule backfill run for it. You
should see the execution fail with `Executing ad hoc run with id
\"7401d1f1-73fc-4483-acd5-edf6180028ce\" has resulted in Error: Saved
object [ad_hoc_run_params/abcdefgh] not found` but you should NOT see
any errors from task manager like `Task ad_hoc_run-backfill
"40fd4c52-411f-462c-b285-87e33520bd5b" failed: Error:
AlertingEventLogger not initialized`

Co-authored-by: Elastic Machine <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 9, 2024
… when ad hoc task runner cannot load saved object (elastic#201637)

## Summary

The ad-hoc task runner loads the `ad_hoc_run` saved object that contains
rule information when it first starts running. If the saved object
cannot be loaded due to saved object not found (likely because the SO
was deleted), the alerting event logger was throwing an error because it
didn't have the rule information to populate the `execute-backfill`
event. This PR fixes it so we're not throwing an error and writes the
`execute-backfill` event with whatever information is available.

## To Verify

1. Modify the ad-hoc task runner to load a random saved object 

```
--- a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
@@ -294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask {
         const adHocRunSO: SavedObject<AdHocRunSO> =
           await this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(
             AD_HOC_RUN_SAVED_OBJECT_TYPE,
-            adHocRunParamsId,
+            `abcdefgh`,
+            // adHocRunParamsId,
             { namespace }
```

2. Create a detection rule and then schedule backfill run for it. You
should see the execution fail with `Executing ad hoc run with id
\"7401d1f1-73fc-4483-acd5-edf6180028ce\" has resulted in Error: Saved
object [ad_hoc_run_params/abcdefgh] not found` but you should NOT see
any errors from task manager like `Task ad_hoc_run-backfill
"40fd4c52-411f-462c-b285-87e33520bd5b" failed: Error:
AlertingEventLogger not initialized`

Co-authored-by: Elastic Machine <[email protected]>
Samiul-TheSoccerFan pushed a commit to Samiul-TheSoccerFan/kibana that referenced this pull request Dec 10, 2024
… when ad hoc task runner cannot load saved object (elastic#201637)

## Summary

The ad-hoc task runner loads the `ad_hoc_run` saved object that contains
rule information when it first starts running. If the saved object
cannot be loaded due to saved object not found (likely because the SO
was deleted), the alerting event logger was throwing an error because it
didn't have the rule information to populate the `execute-backfill`
event. This PR fixes it so we're not throwing an error and writes the
`execute-backfill` event with whatever information is available.

## To Verify

1. Modify the ad-hoc task runner to load a random saved object 

```
--- a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
@@ -294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask {
         const adHocRunSO: SavedObject<AdHocRunSO> =
           await this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(
             AD_HOC_RUN_SAVED_OBJECT_TYPE,
-            adHocRunParamsId,
+            `abcdefgh`,
+            // adHocRunParamsId,
             { namespace }
```

2. Create a detection rule and then schedule backfill run for it. You
should see the execution fail with `Executing ad hoc run with id
\"7401d1f1-73fc-4483-acd5-edf6180028ce\" has resulted in Error: Saved
object [ad_hoc_run_params/abcdefgh] not found` but you should NOT see
any errors from task manager like `Task ad_hoc_run-backfill
"40fd4c52-411f-462c-b285-87e33520bd5b" failed: Error:
AlertingEventLogger not initialized`

Co-authored-by: Elastic Machine <[email protected]>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
… when ad hoc task runner cannot load saved object (elastic#201637)

## Summary

The ad-hoc task runner loads the `ad_hoc_run` saved object that contains
rule information when it first starts running. If the saved object
cannot be loaded due to saved object not found (likely because the SO
was deleted), the alerting event logger was throwing an error because it
didn't have the rule information to populate the `execute-backfill`
event. This PR fixes it so we're not throwing an error and writes the
`execute-backfill` event with whatever information is available.

## To Verify

1. Modify the ad-hoc task runner to load a random saved object 

```
--- a/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
+++ b/x-pack/plugins/alerting/server/task_runner/ad_hoc_task_runner.ts
@@ -294,7 +294,8 @@ export class AdHocTaskRunner implements CancellableTask {
         const adHocRunSO: SavedObject<AdHocRunSO> =
           await this.context.encryptedSavedObjectsClient.getDecryptedAsInternalUser<AdHocRunSO>(
             AD_HOC_RUN_SAVED_OBJECT_TYPE,
-            adHocRunParamsId,
+            `abcdefgh`,
+            // adHocRunParamsId,
             { namespace }
```

2. Create a detection rule and then schedule backfill run for it. You
should see the execution fail with `Executing ad hoc run with id
\"7401d1f1-73fc-4483-acd5-edf6180028ce\" has resulted in Error: Saved
object [ad_hoc_run_params/abcdefgh] not found` but you should NOT see
any errors from task manager like `Task ad_hoc_run-backfill
"40fd4c52-411f-462c-b285-87e33520bd5b" failed: Error:
AlertingEventLogger not initialized`

Co-authored-by: Elastic Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) Feature:Alerting 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 v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants