[Synthetics] Perform clean up delete in batches#245775
[Synthetics] Perform clean up delete in batches#245775shahzad31 merged 4 commits intoelastic:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the duplicate package policy cleanup logic to delete policies in batches of 100 instead of attempting to delete all at once, preventing potential issues with oversized payloads.
Key changes:
- Extracted deletion logic into a new
deleteDuplicatePackagePoliciesfunction that processes deletions in batches of 100 - Added comprehensive unit tests covering empty arrays, small single-batch deletions, and large multi-batch scenarios
- Enhanced logging to show batch progress during deletion
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| x-pack/solutions/observability/plugins/synthetics/server/tasks/clean_up_duplicate_policies.ts | Refactored deletion logic into a new exported function with batching logic; added ElasticsearchClient type import |
| x-pack/solutions/observability/plugins/synthetics/server/tasks/clean_up_duplicate_policies.test.ts | Added new test file with three test cases covering empty array, single batch, and multi-batch deletion scenarios |
x-pack/solutions/observability/plugins/synthetics/server/tasks/clean_up_duplicate_policies.ts
Show resolved
Hide resolved
x-pack/solutions/observability/plugins/synthetics/server/tasks/clean_up_duplicate_policies.ts
Outdated
Show resolved
Hide resolved
x-pack/solutions/observability/plugins/synthetics/server/tasks/clean_up_duplicate_policies.ts
Show resolved
Hide resolved
.../solutions/observability/plugins/synthetics/server/tasks/clean_up_duplicate_policies.test.ts
Show resolved
Hide resolved
.../solutions/observability/plugins/synthetics/server/tasks/clean_up_duplicate_policies.test.ts
Show resolved
Hide resolved
|
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
|
Starting backport for target branches: 8.19, 9.2 https://github.com/elastic/kibana/actions/runs/20109525028 |
💚 Build Succeeded
Metrics [docs]
History
|
## Summary
Refactor code to Perform clean up delete in batches, unit tests have
been added for the changes.
Instead of calling on all found package policies to delete, do a for
loop in batches
```
await fleet.packagePolicyService.delete(soClient, esClient, batch, {
force: true,
spaceIds: ['*'],
});
```
(cherry picked from commit 287b929)
💔 Some backports could not be created
Note: Successful backport PRs will be merged automatically after passing CI. Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
) # Backport This will backport the following commits from `main` to `9.2`: - [[Synthetics] Perform clean up delete in batches (#245775)](#245775) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2025-12-10T18:40:46Z","message":"[Synthetics] Perform clean up delete in batches (#245775)\n\n## Summary\n\nRefactor code to Perform clean up delete in batches, unit tests have\nbeen added for the changes.\n\nInstead of calling on all found package policies to delete, do a for\nloop in batches\n```\n await fleet.packagePolicyService.delete(soClient, esClient, batch, {\n force: true,\n spaceIds: ['*'],\n });\n```","sha":"287b929c42199a35c23fece3300d1eddc89bb913","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.3.0","author:actionable-obs","Team:obs-ux-management","v9.2.3","v8.19.9"],"title":"[Synthetics] Perform clean up delete in batches","number":245775,"url":"https://github.com/elastic/kibana/pull/245775","mergeCommit":{"message":"[Synthetics] Perform clean up delete in batches (#245775)\n\n## Summary\n\nRefactor code to Perform clean up delete in batches, unit tests have\nbeen added for the changes.\n\nInstead of calling on all found package policies to delete, do a for\nloop in batches\n```\n await fleet.packagePolicyService.delete(soClient, esClient, batch, {\n force: true,\n spaceIds: ['*'],\n });\n```","sha":"287b929c42199a35c23fece3300d1eddc89bb913"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/245775","number":245775,"mergeCommit":{"message":"[Synthetics] Perform clean up delete in batches (#245775)\n\n## Summary\n\nRefactor code to Perform clean up delete in batches, unit tests have\nbeen added for the changes.\n\nInstead of calling on all found package policies to delete, do a for\nloop in batches\n```\n await fleet.packagePolicyService.delete(soClient, esClient, batch, {\n force: true,\n spaceIds: ['*'],\n });\n```","sha":"287b929c42199a35c23fece3300d1eddc89bb913"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Shahzad <shahzad31comp@gmail.com>
## Summary
Refactor code to Perform clean up delete in batches, unit tests have
been added for the changes.
Instead of calling on all found package policies to delete, do a for
loop in batches
```
await fleet.packagePolicyService.delete(soClient, esClient, batch, {
force: true,
spaceIds: ['*'],
});
```
(cherry picked from commit 287b929)
# Conflicts:
# x-pack/solutions/observability/plugins/synthetics/server/tasks/clean_up_duplicate_policies.ts
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…5926) # Backport This will backport the following commits from `main` to `8.19`: - [[Synthetics] Perform clean up delete in batches (#245775)](#245775) <!--- Backport version: 10.2.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2025-12-10T18:40:46Z","message":"[Synthetics] Perform clean up delete in batches (#245775)\n\n## Summary\n\nRefactor code to Perform clean up delete in batches, unit tests have\nbeen added for the changes.\n\nInstead of calling on all found package policies to delete, do a for\nloop in batches\n```\n await fleet.packagePolicyService.delete(soClient, esClient, batch, {\n force: true,\n spaceIds: ['*'],\n });\n```","sha":"287b929c42199a35c23fece3300d1eddc89bb913","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.3.0","author:actionable-obs","Team:obs-ux-management","v9.2.3","v8.19.9"],"title":"[Synthetics] Perform clean up delete in batches","number":245775,"url":"https://github.com/elastic/kibana/pull/245775","mergeCommit":{"message":"[Synthetics] Perform clean up delete in batches (#245775)\n\n## Summary\n\nRefactor code to Perform clean up delete in batches, unit tests have\nbeen added for the changes.\n\nInstead of calling on all found package policies to delete, do a for\nloop in batches\n```\n await fleet.packagePolicyService.delete(soClient, esClient, batch, {\n force: true,\n spaceIds: ['*'],\n });\n```","sha":"287b929c42199a35c23fece3300d1eddc89bb913"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/245775","number":245775,"mergeCommit":{"message":"[Synthetics] Perform clean up delete in batches (#245775)\n\n## Summary\n\nRefactor code to Perform clean up delete in batches, unit tests have\nbeen added for the changes.\n\nInstead of calling on all found package policies to delete, do a for\nloop in batches\n```\n await fleet.packagePolicyService.delete(soClient, esClient, batch, {\n force: true,\n spaceIds: ['*'],\n });\n```","sha":"287b929c42199a35c23fece3300d1eddc89bb913"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/245904","number":245904,"state":"MERGED","mergeCommit":{"sha":"03c026c2876802f5fe175db71bd791b4fe589abe","message":"[9.2] [Synthetics] Perform clean up delete in batches (#245775) (#245904)\n\n# Backport\n\nThis will backport the following commits from `main` to `9.2`:\n- [[Synthetics] Perform clean up delete in batches\n(#245775)](https://github.com/elastic/kibana/pull/245775)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by: Shahzad <shahzad31comp@gmail.com>"}},{"branch":"8.19","label":"v8.19.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
## Summary
Refactor code to Perform clean up delete in batches, unit tests have
been added for the changes.
Instead of calling on all found package policies to delete, do a for
loop in batches
```
await fleet.packagePolicyService.delete(soClient, esClient, batch, {
force: true,
spaceIds: ['*'],
});
```
## Summary
Refactor code to Perform clean up delete in batches, unit tests have
been added for the changes.
Instead of calling on all found package policies to delete, do a for
loop in batches
```
await fleet.packagePolicyService.delete(soClient, esClient, batch, {
force: true,
spaceIds: ['*'],
});
```
(cherry picked from commit 287b929)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
) # Backport This will backport the following commits from `main` to `9.1`: - [[Synthetics] Perform clean up delete in batches (#245775)](#245775) <!--- Backport version: 10.2.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2025-12-10T18:40:46Z","message":"[Synthetics] Perform clean up delete in batches (#245775)\n\n## Summary\n\nRefactor code to Perform clean up delete in batches, unit tests have\nbeen added for the changes.\n\nInstead of calling on all found package policies to delete, do a for\nloop in batches\n```\n await fleet.packagePolicyService.delete(soClient, esClient, batch, {\n force: true,\n spaceIds: ['*'],\n });\n```","sha":"287b929c42199a35c23fece3300d1eddc89bb913","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.3.0","author:actionable-obs","Team:obs-ux-management","v9.2.3","v8.19.9","v9.1.10"],"title":"[Synthetics] Perform clean up delete in batches","number":245775,"url":"https://github.com/elastic/kibana/pull/245775","mergeCommit":{"message":"[Synthetics] Perform clean up delete in batches (#245775)\n\n## Summary\n\nRefactor code to Perform clean up delete in batches, unit tests have\nbeen added for the changes.\n\nInstead of calling on all found package policies to delete, do a for\nloop in batches\n```\n await fleet.packagePolicyService.delete(soClient, esClient, batch, {\n force: true,\n spaceIds: ['*'],\n });\n```","sha":"287b929c42199a35c23fece3300d1eddc89bb913"}},"sourceBranch":"main","suggestedTargetBranches":["9.1"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/245775","number":245775,"mergeCommit":{"message":"[Synthetics] Perform clean up delete in batches (#245775)\n\n## Summary\n\nRefactor code to Perform clean up delete in batches, unit tests have\nbeen added for the changes.\n\nInstead of calling on all found package policies to delete, do a for\nloop in batches\n```\n await fleet.packagePolicyService.delete(soClient, esClient, batch, {\n force: true,\n spaceIds: ['*'],\n });\n```","sha":"287b929c42199a35c23fece3300d1eddc89bb913"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/245904","number":245904,"state":"MERGED","mergeCommit":{"sha":"03c026c2876802f5fe175db71bd791b4fe589abe","message":"[9.2] [Synthetics] Perform clean up delete in batches (#245775) (#245904)\n\n# Backport\n\nThis will backport the following commits from `main` to `9.2`:\n- [[Synthetics] Perform clean up delete in batches\n(#245775)](https://github.com/elastic/kibana/pull/245775)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by: Shahzad <shahzad31comp@gmail.com>"}},{"branch":"8.19","label":"v8.19.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/245926","number":245926,"state":"MERGED","mergeCommit":{"sha":"e8062fff81c26b6be11c5ba2cdb27169821fee78","message":"[8.19] [Synthetics] Perform clean up delete in batches (#245775) (#245926)\n\n# Backport\n\nThis will backport the following commits from `main` to `8.19`:\n- [[Synthetics] Perform clean up delete in batches\n(#245775)](https://github.com/elastic/kibana/pull/245775)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n"}},{"branch":"9.1","label":"v9.1.10","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
Summary
Refactor code to Perform clean up delete in batches, unit tests have been added for the changes.
Instead of calling on all found package policies to delete, do a for loop in batches