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

Need a replacement for esArchiver.emptyKibanaIndex(); #136562

Open
bhavyarm opened this issue Jul 18, 2022 · 12 comments
Open

Need a replacement for esArchiver.emptyKibanaIndex(); #136562

bhavyarm opened this issue Jul 18, 2022 · 12 comments
Labels
bug Fixes for quality problems that affect the customer experience Team:Operations Team label for Operations Team

Comments

@bhavyarm
Copy link
Contributor

I am migrating test/api_integration/fixtures/es_archiver/management/saved_objects/scroll_count to kbnArchiver (kibana/test/api_integration/apis/saved_objects_management/scroll_count.ts) And this test is using await esArchiver.emptyKibanaIndex();.

I tried to replace it with await kibanaServer.savedObjects.cleanStandardList(); but the test failed.
This is the test run with kibanaServer.savedObjects.cleanStandardList();

scroll_count with more than 10k objects
         └-> "before all" hook: beforeTestSuite.trigger for "returns the correct count for each included types"
         └-> "before all" hook for "returns the correct count for each included types"
         └-> returns the correct count for each included types
           └-> "before each" hook: global before each for "returns the correct count for each included types"
           └- ✓ pass  (493ms)
         └-> "after all" hook for "returns the correct count for each included types"
           │ debg Cleaning all saved objects { space: undefined }
           │ info deleting batch of 1000 objects
           │ info deleting batch of 1000 objects
           │ info deleting batch of 1000 objects
           │ info deleting batch of 1000 objects
           │ info deleting batch of 1000 objects
           │ info deleting batch of 1000 objects
           │ info deleting batch of 1000 objects
           └- ✖ fail: apis saved objects management apis scroll_count scroll_count with more than 10k objects "after all" hook for "returns the correct count for each included types"
           │      Error: Timeout of 360000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/bhavyarajumandya/Desktop/kibana_dev/kibana/test/api_integration/apis/saved_objects_management/scroll_count.ts)
           │       at listOnTimeout (node:internal/timers:559:17)
           │       at processTimers (node:internal/timers:502:7)
           │ 
           │ 
         └-> "after all" hook: afterTestSuite.trigger in "scroll_count"
       └-> "after all" hook: afterTestSuite.trigger in "saved objects management apis"
     └-> "after all" hook: afterTestSuite.trigger in "apis"
 │
 │5 passing (6.0m)
 │1 failing
 │
 │1)    apis
 │       saved objects management apis
 │         scroll_count
 │           scroll_count with more than 10k objects
 │             "after all" hook for "returns the correct count for each included types":
 │
 │      Error: Timeout of 360000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/Users/bhavyarajumandya/Desktop/kibana_dev/kibana/test/api_integration/apis/saved_objects_management/scroll_count.ts)
 │       at listOnTimeout (node:internal/timers:559:17)
 │       at processTimers (node:internal/timers:502:7)
 │ 
 │ 

And this is the test run with await esArchiver.emptyKibanaIndex();

> "after all" hook for "includes all requested types even when none match the search"
           │ debg unloading docs from archive at /Users/bhavyarajumandya/Desktop/kibana_dev/kibana/test/api_integration/fixtures/kbn_archiver/saved_objects/scroll_count.json
           │ info deleting 6 objects { space: undefined }
           │ succ 6 saved objects deleted
           │ debg Cleaning all saved objects { space: undefined }
           │ info deleting batch of 0 objects
           │ succ deleted 0 objects
         └-> "after all" hook: afterTestSuite.trigger for "includes all requested types even when none match the search"
       └-: scroll_count with more than 10k objects
         └-> "before all" hook: beforeTestSuite.trigger for "returns the correct count for each included types"
         └-> "before all" hook for "returns the correct count for each included types"
         └-> returns the correct count for each included types
           └-> "before each" hook: global before each for "returns the correct count for each included types"
           └- ✓ pass  (550ms)
         └-> "after all" hook for "returns the correct count for each included types"
           │ warn since spaces are enabled, all objects other than the default space were deleted from .kibana rather than deleting the whole index
           │ info [emptyKibanaIndex] Deleted existing index ".kibana"
           │ debg Migrating saved objects
           │ info [emptyKibanaIndex] Created index ".kibana"
         └-> "after all" hook: afterTestSuite.trigger for "returns the correct count for each included types"
       └-> "after all" hook: afterTestSuite.trigger in "scroll_count"
     └-> "after all" hook: afterTestSuite.trigger in "saved objects management apis"
   └-> "after all" hook: afterTestSuite.trigger in "apis"

Creating an issue because we want to get rid of esArchiver.

@bhavyarm bhavyarm added the bug Fixes for quality problems that affect the customer experience label Jul 18, 2022
@botelastic botelastic bot added the needs-team Issues missing a team label label Jul 18, 2022
@bhavyarm bhavyarm added the Team:Operations Team label for Operations Team label Jul 18, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@botelastic botelastic bot removed the needs-team Issues missing a team label label Jul 18, 2022
@spalger
Copy link
Contributor

spalger commented Jul 18, 2022

I'm pretty sure the problem is that there are so many saved objects to delete, and there isn't any bulk delete API. @elastic/kibana-core can we discuss the option of closing #30503 again?

@TinaHeiligers
Copy link
Contributor

can we discuss the option of closing #30503 again

I've added it to our sync.

@pgayvallet
Copy link
Contributor

I'm pretty sure the problem is that there are so many saved objects to delete, and there isn't any bulk delete API.

I tend to agree that this is the issue here. Deleting 10k objects without bulk APIs will likely take quite some time.

can we discuss the option of closing #30503 again?

I can close the issue for sure, but you probably meant to resolve it :trollface: ?

@tylersmalley
Copy link
Contributor

Realize this is from a few weeks ago... but could an alternative solution for this test be to use a space and delete it?

@spalger
Copy link
Contributor

spalger commented Aug 3, 2022

Does deleting a space clean up their saved objects in bulk? That sounds like a reasonable idea to me

@rudolf
Copy link
Contributor

rudolf commented Aug 12, 2022

@tylersmalley @spalger Yes, deleting a space will delete all its documents too.

One edge case is creating an object and then sharing it to another space. In this case, removing the original space won't delete the object. But outside of the spaces test suites I doubt this happens often.

@TinaHeiligers
Copy link
Contributor

FYI folks, #139680 merged in time for 8.5 FF.
A few caveats with the API that are worth mentioning:

  1. hidden objects cannot be deleted using the API, these are filtered out from the permissible SO types we act on
  2. Deleting shared saved objects that exist in more than one space has to be done by force. It's a similar option as to single delete except that the behavior applies to the whole request. If you want to be selective over which objects to force delete, you'll have to delete them one by one (or use the space-delete "hack")
  3. Deleting many shared saved objects in one request might block the event loop because we have to delete legacy url aliases for each object that's deleted. ATM, these are done one at a time and we're using a pMap to minimize the number of concurrent requests. If anyone wants to help out and feels up to modifying the deleteByQuery script, feel free to do so, otherwise, we'll try to get there as priorities allow.

@LeeDr
Copy link

LeeDr commented Oct 12, 2022

While discussing another issue, I think it was @pmuellr that mentioned that we really shouldn't delete alerts saved objects through the saved object API because it orphaned the task manager tasks related to it. So to really "clean" or "tear-down" after a test we should include things outside the .kibana index. Maybe we develop a function or service that takes all these things into account like;

For each space:

  • find any alerts and delete them using the proper API so that it cleans up any tasks related to them
  • for other types of saved objects, use the proper APIs to remove them
  • for any remaining saved objects, use the saved object API to delete them (like the kibanaServer.savedObjects.cleanStandardList() method currently does

@pmuellr
Copy link
Member

pmuellr commented Oct 13, 2022

While discussing another issue, I think it was @pmuellr that mentioned that we really shouldn't delete alerts saved objects through the saved object API because it orphaned the task manager tasks related to it.

correct. We also have a parallel set of APIs for connectors - they can be deleted as plain old SO's today, but that could change in the future, so probably connectors should be looped through and deleted through their APIs as well.

For each space:

  • find any alerts and delete them using the proper API so that it cleans up any tasks related to them
  • for other types of saved objects, use the proper APIs to remove them
  • for any remaining saved objects, use the saved object API to delete them (like the kibanaServer.savedObjects.cleanStandardList() method currently does

Or, for each space, for each saved object, if it's a "special" type call it's special delete, otherwise call the SO delete. I believe we have or will have bulk delete for rules (maybe not connectors), and plain old SO's as well, so probably want to batch those up instead of deleting one at a time.

@TinaHeiligers
Copy link
Contributor

TinaHeiligers commented Oct 13, 2022

we have or will have bulk delete

@pmuellr there is a bulkDelete saved objects API in main: #139680.
I also added docs for that: #141164

@watson
Copy link
Contributor

watson commented Oct 3, 2023

This bug report hasn't received any updates for a year. Can someone please verify if this is still relevant?

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 Team:Operations Team label for Operations Team
Projects
None yet
Development

No branches or pull requests

10 participants