SavedObject migrations are synchronous functions making it impossible to write migrations that require looking up some state from the old .kibana index being migrated.
I want to convert graph saved objects to use index pattern ids instead of names but realized there isn't a method to lookup existing index patterns and the document migration can only be executed synchronously.
Once completed, this will unblock #34989. cc @flash1293
Allow migrations to provide an asynchronous pre-migration state collection function. The result of this function will be passed as an argument to each of the synchronous migration functions.
Pinging @elastic/kibana-operations
We should be really careful in enabling something like this. The problem with asynchronous migrations is that Kibana is completely unavailable while migrations run, so if even one plugin performs a slow asynchronous migration that doesn't scale, it could cause significant downtime for Kibana. This could also make it pretty trivial to clobber the underlying ES cluster by slamming it with queries.
_If_ we support something like this, which I'm not convinced we should even bother, then we might want to introduce some sort of pre-flight async migration hook that would execute once per plugin per version and then result would be passed to all of the synchronous migration functions, and then something like graph could query for its workspaces in bulk and then return a map of names to ids that its own migrations could then rely on.
I absolutely agree with an async setup or preflight request to capture the data to be used by the migrations instead of providing async migrations.
That is a good idea, it will solve the scenario and be more efficient at running. 馃憤
Updated the description based on the discussion.
Discussed the idea with @rudolf and there are a few things to consider.
Because we don't currently have any migrations for the config object, can it safely be loaded before migrations are run? This could unblock our work on https://github.com/elastic/kibana/pull/53972
Discussed this with @pgayvallet and @wylieconlon and we came up with three potential solutions to #53972:
The Platform team favours (1) since it will improve the overall architecture of Kibana and has the lowest risk. This also buys us time to improve the saved object migration framework to be more resilient https://github.com/elastic/kibana/issues/52202 which we're targeting for 8.0.0
Pinging @elastic/kibana-platform (Team:Platform)
I'm closing this as I'm not aware of any plugins requiring this functionality. Let me know if we should re-open it.
@flash1293 I believe we've decided that the best way to implement the graph migration is to do that in the graph plugin itself during the start lifecycle (that is outside of saved object migrations).
@wylieconlon I'm not sure if we still want to implement #53972 but as far as I'm aware there's nothing preventing us from adopting the proposed solution to "Centralize all index-pattern loading to the data plugin and transform any index-pattern when it's loaded."
Most helpful comment
We should be really careful in enabling something like this. The problem with asynchronous migrations is that Kibana is completely unavailable while migrations run, so if even one plugin performs a slow asynchronous migration that doesn't scale, it could cause significant downtime for Kibana. This could also make it pretty trivial to clobber the underlying ES cluster by slamming it with queries.
_If_ we support something like this, which I'm not convinced we should even bother, then we might want to introduce some sort of pre-flight async migration hook that would execute once per plugin per version and then result would be passed to all of the synchronous migration functions, and then something like graph could query for its workspaces in bulk and then return a map of names to ids that its own migrations could then rely on.