-
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
[Platform] Run SavedObject Migrations after PluginService#setup #52071
Comments
Pinging @elastic/kibana-platform (Team:Platform) |
If I understand correctly, we will run the migration after plugin's |
Hum, if I'm not misreading the code, the migration is actually performed during
|
Right it looks like we don't run the migrations until start, however we may need to do some refactoring to allow migrations to be added during setup. Right now, it looks like the SO service depends on all the migrations being known before It also appears that if Options:
|
I think that from what I understand, the answer is yes. @rudolf can you confirm? |
Yes, I confused discovering and registering migrations with running them. The issue is exactly what Josh describes here, we need to refactor saved objects to allow for adding migrations during setup.
kibana/src/core/server/saved_objects/saved_objects_service.ts Lines 81 to 127 in 56041f0
To really model the behaviour we would need three lifecycle stages to separate the following API calls:
My initial idea was to put (1) & (2) into If (2) & (3) are placed in |
So after discussing with @rudolf and @joshdover, it seems that the main (and only) reason why we are exposing the i.E security: kibana/x-pack/plugins/security/server/saved_objects/index.ts Lines 27 to 34 in e582277
WDYT about changing the signatures of The previous snippet would become: savedObjects.setClientFactory(repoFactory => ({ request }) => {
const kibanaRequest = getKibanaRequest(request);
return new SavedObjectsClient(
authz.mode.useRbacForRequest(kibanaRequest)
? repoFactory.createInternalRepository()
: repoFactory.createScopedRepository(kibanaRequest)
);
}); That would allow to remove the There would be no more pain point in performing SO migration between plugin's I'm really not an expert in SO apis, so is there any blocker in this approach? |
Another option would be to have the SO repositories being aware of the current lifecycle state and either logs a warning or throws an error when calls are performed before the end of core's |
Looking at Lines 33 to 50 in ebd2c21
there is another need of accessing a SO repository during (this snippet will not be able to be migrated to NP atm, as is currently uses apis from core's both |
I think this is a really elegant way to solve the problem. We would also have to expose an
|
We will need to expose a repository from @rudolf Do you see any other usages for the repositories during |
This comment has been minimized.
This comment has been minimized.
That's not exactly true. the There is another bigger issue though: the migrator is currently created during setup, needs 'final' version of the schema/mapping and migration to be instanciated, and is required to creates a repository. Meaning that if the remove it from There is a big chicken-egg condition here. Even changing the |
So, after looking up the code for a while, it seems that if we want migration to be performed after core's I currently see three options for this:
This seems the cleanest solution, however I'm not really sure of the feasibility without introducing breaking changes to the actual usages of the API we are going to remove. #52071 (comment) address the solution regarding
We could just add our own wrapper around the repositories and clients that would delay all calls before the migration is done (Which means before the end of core setup).It may appear pragmatic, however I'm really scared of the risk of introducing deadlocks by doing that, at least as long as plugin's Simplest example coming to mind would be a plugin awaiting a SO call during setup before returning. This would just deadlock the initialization. As we would not be doing the migration before after the plugin's setup phase however, these deadlocks should be deterministic: a lock condition caused by a plugin awaiting such a call would always occurs, and could/should be detected in development. It we decide to go in this direction, we should therefor probably throw an error if a call is performed during setup, to let the developer fix his code.
I don't like the idea, but a simple solution which would likely less impact the code would be to allow plugins to either defines their migrations in a static way, as they currently do for their config schema, or to introduce a new 'lifecycle' method that would expose a restricted SO api to be able to register migrations, schema and mapping before the setup phase is run. Overall, I'm leaning toward trying 1., as it's probably the best approach and is consistent with what the |
I'm not aware of any other use cases. Using the repository (or the client) in setup is an anti-pattern, so if we come across new use cases we should ideally find a better alternative. So I'm also leaning towards (1).
The downside to static migrations is it limits us to static saved object types. This is a theoretical use case that we might never have to support but I can imagine something like the alerting plugin creating an alert type for every solution that integrates with it e.g. We might never have to support this use case, so it doesn't justify adding a huge amount of complexity, but my gut feeling is that the additional complexity from dynamic migrations are small enough to justify getting the added flexibility. |
I'm currently working on the first proposal, moving the migration to an isolated method on the service to be called at the end of core's |
POC of the 'moving the repository access from setup to start' (first option) here: #55012 After #55012 (comment), I think I will then try rudolf suggestion which is actually an equivalent to option 2 (Let the plugin access/create clients and repositories, but block any call before the migration is actually complete) |
In NP Plugins should be able to register SavedObject types, schemas and migrations during the setup lifecycle. This means we can only run SavedObject migrations at the end of Core's setup lifecycle after PluginService#setup has completed.
Currently in Core, migrations run before PluginService#setup which means all migrations have completed before we expose
createScopedRepository
, andcreateInternalRepository
. Although these repositories aren't meant to be used directly, we need to ensure that if they were used to make SavedObject requests to Elasticsearch, that these requests would only fire once all migrations have completed.The text was updated successfully, but these errors were encountered: