-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
…cannot load saved object
Pinging @elastic/response-ops (Team:ResponseOps) |
@elasticmachine merge upstream |
There was a problem hiding this 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
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]
History
cc @ymao1 |
Starting backport for target branches: 8.17, 8.x https://github.com/elastic/kibana/actions/runs/12162593088 |
… 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)
… 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)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…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]>
… 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]>
… 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]>
… 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]>
… 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]>
… 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]>
… 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]>
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 theexecute-backfill
event. This PR fixes it so we're not throwing an error and writes theexecute-backfill
event with whatever information is available.To Verify
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 likeTask ad_hoc_run-backfill "40fd4c52-411f-462c-b285-87e33520bd5b" failed: Error: AlertingEventLogger not initialized