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

[data views] Content management api implementation #155803

Merged

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented Apr 25, 2023

Summary

Data views implements the content management api and associated minor changes. The bulk of the changes are in (common|public|server)/content_management)

Closes #157069

mattkime and others added 30 commits March 26, 2023 23:02
…om:mattkime/kibana into content_management_api_so_type_abstraction
@mattkime mattkime self-assigned this May 17, 2023
@mattkime mattkime added Feature:Data Views Data Views code and UI - index patterns before 8.0 Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) v8.9.0 labels May 17, 2023
@elasticmachine
Copy link
Contributor

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

@mattkime mattkime added the release_note:skip Skip the PR/issue when compiling release notes label May 17, 2023
@mattkime mattkime requested a review from a team as a code owner May 18, 2023 16:37
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
code review only

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

Looks good, code review.

Copy link
Member

@lukasolson lukasolson left a comment

Choose a reason for hiding this comment

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

Mostly looking good! I've added mostly questions rather than feedback.

const dataViewAttributesSchema = schema.object(
{
title: schema.string(),
type: schema.maybe(schema.string()),
Copy link
Member

Choose a reason for hiding this comment

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

Is this the type of the saved object (e.g. "index-pattern")?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its rollup or empty. I guess I should express that in the schema.

// We need it for BWC support between different versions of the content
export const serviceDefinition: ServicesDefinition = {
get: {
out: {
Copy link
Member

Choose a reason for hiding this comment

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

Do we not need in here, or does it have a default of just the id or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no reason since the in portion is just the id of the doc we're getting. That said, if we needed it we could add it later, although I admit it would be nice to have more clarity and agreement around what it would take to introduce new transforms.

Comment on lines +112 to +118
mSearch: {
out: {
result: {
schema: dataViewSavedObjectSchema,
},
},
},
Copy link
Member

Choose a reason for hiding this comment

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

Is this section necessary? I'm not seeing any usage of mSearch in the plugin.

Copy link
Member

Choose a reason for hiding this comment

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

Saw the enableMSearch code below... Is this something that external APIs will make use of?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its for multi type search - src/plugins/content_management/docs/content_onboarding.md:686

src/plugins/data_views/public/plugin.ts Outdated Show resolved Hide resolved
@@ -63,7 +74,10 @@ export class DataViewsPublicPlugin
return new DataViewsServicePublic({
hasData: this.hasData.start(core),
uiSettings: new UiSettingsPublicToCommon(uiSettings),
savedObjectsClient: new SavedObjectsClientPublicToCommon(savedObjects.client),
savedObjectsClient: new SavedObjectsClientPublicToCommon(
Copy link
Member

Choose a reason for hiding this comment

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

Nit: When first going through this code I was a little confused by the name savedObjectsClient. Since this client is no longer just a wrapper around the saved objects client, could we rename it something like dataViewsClient to improve readability? savedObjectsClient seems to be a bit of a misnomer.

Copy link
Contributor Author

@mattkime mattkime May 20, 2023

Choose a reason for hiding this comment

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

I'd prefer to factor out all the SavedObjectsClientPublicToCommon entirely in a follow up. #158191

async get<T = unknown>(type: string, id: string) {
const response = await this.savedObjectClient.resolve<T>(type, id);
async getSavedSearch(id: string) {
const response = await this.savedObjectClient.resolve('search', id);
Copy link
Member

Choose a reason for hiding this comment

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

Once saved search moves to the content management APIs, can the usage of savedObjectClient here be removed entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thats exactly the idea.

options,
});

return response.item as SavedObject<DataViewAttributes>;
Copy link
Member

Choose a reason for hiding this comment

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

I'm slightly concerned by the need to cast here: Is it necessary?

Copy link
Contributor Author

@mattkime mattkime May 20, 2023

Choose a reason for hiding this comment

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

Added comment that addresses this - update may return a partial SO or a full SO. In this case its returning a full SO and thats why I'm casting it as such.

}

delete(type: string, id: string) {
return this.savedObjectClient.delete(type, id, { force: true });
Copy link
Member

Choose a reason for hiding this comment

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

Is there anything necessary to add to the new APIs that is analogous to force: true?

Copy link
Member

Choose a reason for hiding this comment

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

Just played around with this: It looks like this change (not including force: true) prevents us from deleting a data view that is multiple spaces. This might be something we need from the content management folks.
image

Copy link
Contributor Author

@mattkime mattkime May 20, 2023

Choose a reason for hiding this comment

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

Nice catch! ...addressed

*/
export const LATEST_VERSION = 1;

export const DataViewSOType = 'index-pattern';
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Is there any reason you couldn't just re-export from ../../constants instead of redefining this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call

import { DataViewSOType } from '../../common/content_management';
import { cmServicesDefinition } from '../../common/content_management/cm_services';

export class DataViewsStorage extends SOContentStorage<DataViewCrudTypes> {
Copy link
Member

Choose a reason for hiding this comment

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

Is this what takes care of up/down transforms for you since you're extending SOContentStorage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, its the service definition. The service definition is passed in to SOContentStorage so it can be applied in a consistent manner for different SO types. Since we only have v1, there's nothing to code for yet but there's an example here - src/plugins/content_management/docs/content_onboarding.md:587

@kertal
Copy link
Member

kertal commented May 23, 2023

this resolves #157069, right?

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
dataViews 47 50 +3

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 112 115 +3
data 2579 2577 -2
dataViews 245 258 +13
total +14

Async chunks

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

id before after diff
dataViewManagement 118.6KB 118.6KB +15.0B

Page load bundle

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

id before after diff
data 404.1KB 404.1KB +2.0B
dataViews 43.9KB 44.5KB +658.0B
total +660.0B
Unknown metric groups

API count

id before after diff
@kbn/content-management-utils 177 180 +3
data 3273 3301 +28
dataViews 1029 1048 +19
total +50

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
securitySolution 399 403 +4
total +6

References to deprecated APIs

id before after diff
@kbn/core 38 32 -6
@kbn/core-saved-objects-api-browser 64 25 -39
@kbn/core-saved-objects-api-server 17 5 -12
@kbn/core-saved-objects-api-server-internal 10 13 +3
@kbn/core-saved-objects-browser-internal 255 171 -84
@kbn/core-saved-objects-browser-mocks 35 29 -6
@kbn/core-saved-objects-common 9 6 -3
@kbn/core-saved-objects-import-export-server-internal 58 19 -39
@kbn/core-saved-objects-server-internal 7 10 +3
@kbn/core-ui-settings-server-internal 12 3 -9
alerting 86 101 +15
canvas 152 134 -18
data 114 86 -28
dataViews 148 50 -98
fleet 57 63 +6
graph 88 97 +9
home 54 75 +21
lists 95 83 -12
osquery 42 18 -24
savedObjects 106 100 -6
savedObjectsManagement 35 23 -12
savedObjectsTagging 76 37 -39
savedObjectsTaggingOss 29 20 -9
securitySolution 552 606 +54
synthetics 110 50 -60
upgradeAssistant 20 14 -6
total -399

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
securitySolution 479 483 +4
total +6

History

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

cc @mattkime

Copy link
Member

@lukasolson lukasolson left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -21,7 +21,7 @@ import { serializedFieldFormatSchema, fieldSpecSchema } from '../../schemas';
const dataViewAttributesSchema = schema.object(
{
title: schema.string(),
type: schema.maybe(schema.string()),
type: schema.maybe(schema.literal('rollup')),
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to replace this with a constant (outside the scope of this PR), created a new issue here: #158410

@mattkime mattkime merged commit 5fa2226 into elastic:main May 24, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 24, 2023
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:Data Views Data Views code and UI - index patterns before 8.0 release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover App Team (Document Explorer, Saved Search, Surrounding documents, Graph) v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Onboard data-views on content-management
8 participants