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

Migrate SO management routes to new plugin #59734

Merged

Conversation

pgayvallet
Copy link
Contributor

Summary

Part of #50308

Migrate the savedObject management routes to a new savedObjectsManagement plugin

Checklist

@rudolf rudolf mentioned this pull request Mar 10, 2020
5 tasks
@pgayvallet pgayvallet added Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.7.0 v8.0.0 labels Mar 10, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@pgayvallet
Copy link
Contributor Author

retest

@pgayvallet pgayvallet marked this pull request as ready for review March 16, 2020 08:59
@pgayvallet pgayvallet requested a review from a team as a code owner March 16, 2020 08:59
Comment on lines 24 to 33
export const registerScrollForExportRoute = (router: IRouter) => {
router.post(
{
path: '/api/kibana/management/saved_objects/scroll/export',
validate: {
body: schema.object({
typesToInclude: schema.arrayOf(schema.string()),
}),
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, this route seems unused. At least I didn't find any usage in our code. Was not sure if I should remove it though.

Copy link
Contributor

Choose a reason for hiding this comment

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

another good candidate for the platform telemetry project🤔

Comment on lines 51 to 53
return {
management: managementService,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm exposing that from the start contract even if currently no plugin uses it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather keep it private until requested to keep the API surface smaller.

Comment on lines 22 to 29
export const findAll = async (
client: SavedObjectsClientContract,
findOptions: SavedObjectsFindOptions
): Promise<SavedObject[]> => {
return recursiveFind(client, findOptions, 1, []);
};

const recursiveFind = async (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added test for them, but appart from that the so_management/server/lib utilities were almost migrated to TS without any changes

Comment on lines 1 to 5
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the plugin name is savedObjectsManagement. Should I rename the plugin folder from so_management to saved_objects_management ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer saved_objects_management despite verbosity as more descriptive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, that's probably the right call, as the folder should probably match the plugin name. Gonna rename

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

Tested and overall works great!
Plugin structure looks good too.

Noticed that changing the types drop down, causes a double fetch of Request URL: http://localhost:5620/api/kibana/management/saved_objects/scroll/counts (one of them seems to fetch only the selected counts, and I don't see why you need to)

@@ -21,11 +21,7 @@ export function injectVars(server) {
const serverConfig = server.config();

// Get types that are import and exportable, by default yes unless isImportableAndExportable is set to false
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not (and it was wrong, as the default value is actually false...). removed. The whole importAndExportableTypes injection is going to be removed in next stage anyway

path: '/api/kibana/management/saved_objects/_find',
validate: {
query: schema.object({
perPage: schema.number({ min: 0, defaultValue: 20 }),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be coming from savedObjects:perPage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The savedObjects:perPage value is actually accessed and sent by the client.

perPageConfig={config.get('savedObjects:perPage')}

The route's joi schema was not, and I did a rather straight forward migration to config-schema. As this is an internal API and to avoid adding another dependency to the route definition, I'm leaning to keep it that way, unless you want me to perform the change?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can do it later when moving savedObjects:perPage registration to saved_objects_management plugin.

@pgayvallet
Copy link
Contributor Author

@lizozom

Noticed that changing the types drop down, causes a double fetch of Request URL: http://localhost:5620/api/kibana/management/saved_objects/scroll/counts (one of them seems to fetch only the selected counts, and I don't see why you need to)

Thanks. will take a look when migration the client-side code in the follow-up PR.

@mshustov
Copy link
Contributor

ack: will review tomorrow

Copy link
Contributor

@mshustov mshustov left a comment

Choose a reason for hiding this comment

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

some nits, LGTM :shipit:

Comment on lines 1 to 5
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer saved_objects_management despite verbosity as more descriptive.

.map(so => injectMetaAttributes(so, managementService))
.map(obj => {
const result = { ...obj, attributes: {} as Record<string, any> };
for (const field of includedFields || []) {
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary || []? you have [] as default value

dashboard: 1,
visualization: 1,
'index-pattern': 0,
search: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add an explicit test that it sets0 for all the types listed in typesToInclude?

Comment on lines 24 to 33
export const registerScrollForExportRoute = (router: IRouter) => {
router.post(
{
path: '/api/kibana/management/saved_objects/scroll/export',
validate: {
body: schema.object({
typesToInclude: schema.arrayOf(schema.string()),
}),
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

another good candidate for the platform telemetry project🤔

path: '/api/kibana/management/saved_objects/_find',
validate: {
query: schema.object({
perPage: schema.number({ min: 0, defaultValue: 20 }),
Copy link
Contributor

Choose a reason for hiding this comment

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

We can do it later when moving savedObjects:perPage registration to saved_objects_management plugin.

Comment on lines 51 to 53
return {
management: managementService,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather keep it private until requested to keep the API surface smaller.

@pgayvallet pgayvallet requested a review from lizozom March 19, 2020 10:45
@pgayvallet
Copy link
Contributor Author

@elastic/kibana-app-arch @lizozom Could we get another look on this one?

@pgayvallet pgayvallet added v7.8 and removed v7.7.0 labels Mar 26, 2020
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@pgayvallet pgayvallet merged commit a7508b8 into elastic:master Mar 26, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Mar 26, 2020
* unexpose SavedObjectsManagement from legacy server

* migrate saved object management routes to new plugin

* fix endpoint methods

* adapt code due to rebase

* extract types

* improve findAll params

* adapt existing api integration tests and migrate to TS

* update generated doc

* add API integration tests for /scroll/count

* add unit tests for plugin and routes

* add injectMetaAttributes tests

* extract relation type

* add find_relationships tests

* add find_all tests

* do not complete migrator$ to avoid unhandled promise rejection

* fix data for search endpoint integration tests

* remove falsy comment

* rename plugin folder to match plugin id

* address review comments

* update CODEOWNERS
pgayvallet added a commit that referenced this pull request Mar 26, 2020
* unexpose SavedObjectsManagement from legacy server

* migrate saved object management routes to new plugin

* fix endpoint methods

* adapt code due to rebase

* extract types

* improve findAll params

* adapt existing api integration tests and migrate to TS

* update generated doc

* add API integration tests for /scroll/count

* add unit tests for plugin and routes

* add injectMetaAttributes tests

* extract relation type

* add find_relationships tests

* add find_all tests

* do not complete migrator$ to avoid unhandled promise rejection

* fix data for search endpoint integration tests

* remove falsy comment

* rename plugin folder to match plugin id

* address review comments

* update CODEOWNERS
@rayafratkina rayafratkina added v7.8.0 and removed v7.8 labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.8.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants