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

[content management / maps] Create abstract types for saved object usage with content management api #154985

Merged

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented Apr 15, 2023

Summary

Abstract types for using Saved Objects with the content management api. This should significantly reduce the amount of code to use additional saved object types.

@mattkime mattkime changed the title abstract types [content management / maps] Create abstract types for saved object usage with content management api Apr 15, 2023
@mattkime mattkime marked this pull request as ready for review April 15, 2023 16:04
@mattkime mattkime requested a review from a team as a code owner April 15, 2023 16:04
@mattkime mattkime requested a review from sebelga April 15, 2023 16:05
@mattkime mattkime added Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. Feature:Maps labels Apr 15, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@mattkime mattkime added Feature:Content Management User generated content (saved objects) management release_note:skip Skip the PR/issue when compiling release notes labels Apr 15, 2023
name: string;
}

export interface CreateOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is a good idea to lock the same Options interface for all content type. The idea was to allow each content to pass different options to the storage layer and type those interface + add a schema for them.

Maybe you are right that all call to create/update/delete/search will have the exact same options object but from where I am standing I can't make such a call. WDYT?

Copy link
Contributor Author

@mattkime mattkime Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specifically aimed at Content Management items backed by Saved Objects. I'm familiar with the Saved Objects api and I don't see a benefit to creating specific Option types for CRUD operations. As best I can tell, only the plugin owner of a particular type should be using the CM api, the plugin can provide whatever API it wants.

This intends to be more of a starting point for consolidating Options rather than what should definitely work for everything. Perhaps we'll find a need to extend the Options and can do so at that time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see if I understand correctly.

I only added the references prop to create because that's the only SavedObjectCreateOptions that map uses. They are more fields in that interface but "map" does not use them so I limited the interface.

Here you are making this decision generic for all SO CM types..

Now if "lens" needs another option to be passed we will allow all other types to provide that other option, even though it is not related to they need and it does not do anything.

It seems to me that we are back in tying different content together and it might be hard to make evolve interfaces with time and version them separately.

  • How will we know if we need to up/down transform an option object?
  • How will you provide a different validation schema if "lens" need to pass this options object: { myLensOptionField: true, references: ['123'] }. Will now all CM types have to up/down transform this specific myLensOptionField, what will be the code line documentation for that "specific to lens" option?

Copy link
Contributor Author

@mattkime mattkime Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are making this decision generic for all SO CM types..

If you'd like, we could provide functionality to extend the Option types.


How will we know if we need to up/down transform an option object?

I've ignored that since we don't yet know how the Saved Object versioning will work, but perhaps it can be considered separately.

Should we consider Options versioning a necessary part of the current content management api? If so, I can revise this PR.

Copy link
Contributor

@vadimkibana vadimkibana Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not have any well defined "options" across all CM types. If there is some field that would be useful for all CM types, it should not be an option, but built into the CM CRUD API directly.

Options should ideally never be used, they are an escape hatch, that can be utilised when some type has some extra behavior that does not fill well into the starndartized CM CURD API.

Having said that, I don't think any database related concern should be standartized in the CM layer. For example, references are a database concern (some database have them, some don't, some content types use them, some don't), the CM system should not know anything about the Saved Object references.

Also, with regards to TypeScript types: in CM plugin and packages there should be no types that deal with SavedObjects, i.e. all names that contain *SO*, savedObject*, etc.. do not belong to CM code. Those should be handled on the content provider level.

For example, if AX group thinks it is useful for their content types to standartize some "options" or SO functionality, you are free to do that, but that code should live outside of CM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want it to be unique to each content.

I understand what you're saying, but as someone considering how I'd apply the Content Management API to a number of saved objects, it doesn't make sense.

Why don't we want to reuse code in this circumstance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applying what I learned from the Maps implementation to the Data Views implementation was a big copy and paste project.

What I'm saying if you feel like you want to standartize "options" across your types, that is all good. But that standartized code should not live in CM, it could be some "AX storage helpers" code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vadimkibana

This is in a new content-management-utils package - is that good?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in a new content-management-utils package - is that good?

Yes, if that package is not expected to be owned by SharedUx.

Copy link
Contributor Author

@mattkime mattkime Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should clarify, I'm fine defaulting options to an empty object although I'd still want to provide something more detailed that a dev could easily grab.


@vadimkibana @sebelga

I think we should find some time to talk. Its unclear why some decisions have been made regarding the CM api and I'd like clarity before I continue work on this.

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. I just have some concerns about having a single Option interface for all the CM types and how BWC will be handle for those.
Maybe I am being overly cautious, I'd like to hear other people thoughts on this. 👍

references?: Reference[];
}

export type GetResultSO<Item extends object> = GetResult<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the same generic name and default? It makes it easier to follow IMO

export type GetResultSO<T extends unknown> = GetResult<T, ...>

@mattkime
Copy link
Contributor Author

mattkime commented Apr 19, 2023

@vadimkibana @sebelga

I moved the option types outside of the main interface as to make them easier to modify. I've taken a guess at which options are most likely to be used. We can encourage devs to only use the option attrs they need.

I think it might make more sense if the arguments for a given method call were treated as a single item for upgrade / downgrade purposes. Treating them separately means being unable to alter one based on the content of the other. While its possible that we may never come across a case where its necessary, it would be better to have the option.

Its clear that CM needs to be able to do versioning transforms even if the SO api does some of the work. After all, other persistence layers might not take responsibility for this.

Next I'd like to put together a PR that focuses on code rather than types, providing necessary separation of concerns and BWCA logic.

Hopefully we're better aligned based on the recent changes in this PR and my statements above.

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Having the possibility to make the options evolve independently from one SO type to another looks much better. thanks 👍

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kibana-gis changes LGTM

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/content-management-utils - 15 +15

Any counts in public APIs

Total count of every any typed public API. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats any for more detailed information.

id before after diff
@kbn/content-management-utils - 1 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
maps 2.8MB 2.8MB +7.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
maps 45.0KB 45.1KB +131.0B
Unknown metric groups

API count

id before after diff
@kbn/content-management-utils - 64 +64

ESLint disabled line counts

id before after diff
enterpriseSearch 17 19 +2
securitySolution 395 398 +3
total +5

Total ESLint disabled count

id before after diff
enterpriseSearch 18 20 +2
securitySolution 475 478 +3
total +5

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @mattkime

@mattkime mattkime merged commit 273eec0 into elastic:main Apr 25, 2023
@kibanamachine kibanamachine added v8.8.0 backport:skip This commit does not require backporting labels Apr 25, 2023
mattkime added a commit that referenced this pull request Apr 27, 2023
…abstraction (#155342)

## Summary

Abstract schema definitions for using Saved Objects with the content
management api. For most schema types, this will reduce creation to only
the attributes specific to a saved object. For Option types (create
options, update options, search options) the saved object api is more
complex and its likely that most SO types will only need to use a
portion of it. In these cases we recommend using the provided schema
definitions as a pattern for creating simpler schemas.

Follow up to - #154985 - expresses
types in schema form

---------

Co-authored-by: kibanamachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Content Management User generated content (saved objects) management Feature:Maps release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants