-
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
Decouple saved object management from SavedObjectLoader #67607
Comments
Pinging @elastic/kibana-platform (Team:Platform) |
So, as @flash1293 already described in the issue, we are mostly using the SO loaders in SOM for two things: We are currently using the SO loaders in SOM for two things: 1. Loading SOs for the legacy importkibana/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts Lines 268 to 274 in 9450248
kibana/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts Lines 35 to 45 in 9450248
I think these usages could be easily replaced by generic APIs provided by the client side 2. Reading the mappings of the types to generate the fields to display in the edition viewkibana/src/plugins/saved_objects_management/public/lib/create_field_list.ts Lines 41 to 43 in 6c62c68
This one is slightly more complicated to remove or adapt, and we have multiple options here: 1. Use a new API for the client-side mappingsAs @flash1293 suggested, we could have something similar to export interface SavedObjectsManagementServiceRegistryEntry {
id: string;
fields: Array<{ name: string; type: 'text' | 'number' | 'boolean' | 'json'; defaultValue?: unknown; }>;
importDocument: (doc: SavedObjectsRawDoc, id: string; migrationVersion: string) => Promise<void>;
title: string;
} Note that we are currently only using the SO loaders provided / exposed by type owners
so doing so would require that this API is already in place when we start addressing this issue As a side-note, I don't think we'll need this 2. Change the current edition view with a plain JSON editorWe could replace the current view with a 'plain' JSON editor. we would just have two fields
This have some notable upsides:
The most notable con is that, even if it was already quite easy to break stuff by editing saved objects from this page, it would be even more, as we wouldn't even be validating the allowed fields in the I still think this would be a good alternative to what we currently have. @timroes @joshdover wdyt? |
I haven't looked at this code in a while but I think the way legacy jsons are structured it does require custom logic to unwrap them and turn them into "real" saved objects. Does someone have legacy JSONs to test? :) Edit: Actually, I found some I think you are right - we can have a generic helper to migrate the structure.
Another IMHO large con I want to bring up is that in a lot of places we are storing serialized JSON as a string field. If this page would become a regular JSON editor, the user would have to deal with JSON like this : What about implementing the service to register editable fields, but just falling back to a full json editor? Seems like this would give us the best of both worlds. |
From a quick look, legacy import/export is just working with raw SOs. I guess accessing the attributes given the type should be doable. kibana/src/plugins/legacy_export/server/lib/export/collect_references_deep.ts Lines 29 to 52 in 36b66a8
Would you mind sharing where?
That's a very valid point we overlooked with @timroes during our sync discussion yesteday
That could be an option. It would also allow us to change SOM without the requirement that all SO loader providers migrate to the new API before or at the same time. As a side note: currently, the dependency between SOM and the loader providers is reversed, as the are registering the SO 'services' from SOM itself:
If we are going to clean SOM from loaders, I feel that now will be a good time to also return to dependency to its correct direction (e.g |
Not sure whether you are asking for the place for this helper to live or the legacy exports.
+1 on reversing this dependency |
Sorry, I read |
So, after taking a quick look, regarding the legacy import, there is actually way more logic than I thought in the underlying calls to the loaders/SavedObject class. The most blocking thing I discovered is the way we handle Took me some time to follow the cascade, but: This is the code that collect the index-pattern conflict errors: kibana/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts Lines 339 to 351 in 9450248
Which calls kibana/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts Lines 136 to 140 in 9450248
Which does a LOT of internal logic, and mostly calls kibana/src/plugins/saved_objects/public/saved_object/helpers/apply_es_resp.ts Lines 70 to 85 in d4b2a51
So in short: getting rid of SO loaders for legacy import would require to recode most of the logic contained in This is more work than anticipated tbh. Overall, I feel like the easiest solution (by a very large margin) would be to just drop the legacy import in The alternative will be to recode / copy / adapt all we need from the |
@pgayvallet So if I understand correctly the issue is the check whether an index pattern actually exists? I think we can work around that in a generic way without relying on |
I don't think it should. I think it only may have that references array. Legacy import is supporting very old versions (6.8? older?) and references were not yet a thing at this time. This is what the logic in |
Good point @pgayvallet , I missed those really old legacy exports :) . We chatted about this offline and IMHO the best option right now is to just leave this code in place until 8.0. It would be possible to implement an intermediary solution now, then remove it in 8.0, but as this code is rarely interacted with I think it's not worth the extra effort; maintaining it for a few more minors is less work. |
Added |
In saved object management the "edit saved object" form as well as the legacy import are still tied by the saved object loader respectively the saved object class from the
saved_objects
plugin.To be able to get rid of legacy structures, the saved object management API should be decoupled to make it possible to incrementally migrate away from the saved object class.
Currently the registry looks like this:
kibana/src/plugins/saved_objects_management/public/services/service_registry.ts
Lines 22 to 26 in 358d139
A decoupled API could look like this
This requires some changes in the legacy import and in the way the fields are put together for the form:
kibana/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts
Line 33 in bf04235
kibana/src/plugins/saved_objects_management/public/lib/resolve_saved_objects.ts
Line 133 in bf04235
kibana/src/plugins/saved_objects_management/public/lib/create_field_list.ts
Line 92 in bf04235
To keep the existing implementations till they can get refactored accordingly, a shim function should be introduced as well to turn a saved object loader into the required format:
The text was updated successfully, but these errors were encountered: