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 section to NP #61700

Merged

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Mar 27, 2020

Summary

Fix #50308

Last part of the #50308 'epic'. This moves the SO management section from the legacy kibana plugin in src/legacy/core_plugins/kibana/public/management/sections to a new savedObjectsManagement platform plugin.

I tried to reduce this PR's size with the preliminary PRs I did last weeks, however this one is still quite big. I can't really split that any more, so this last part will have to be reviewed in a single shot unfortunately.

Most UI components were migrated in the simplest way, by converting them to TS and using NP APIs instead of legacy imports. Code cleanup, refactoring and type fixing should be considered as outside of the scope of this PR (as much as possible), as they should be addressed in the #62048 follow-up instead.

Plugin bundle size:

  • before optimization: 4mb.
  • after async require for the management section and removing static import from discover plugin: 50kb.

Notes for reviewers

security

I think only owned files impacting changes are on copy_saved_objects_to_space_service.ts, and are trivial.

app-arch

All src/legacy/core_plugins/kibana/public/management/sections/objects files got moved to the new SOM plugin. This changes their ownership from your team to ours, however a 'full' review is still very welcome.

platform

See self-review

Checklist

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

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

Comment on lines +67 to +73
savedSearches: {
/**
* Create a {@link SavedObjectLoader | loader} to handle the saved searches type.
* @param services
*/
createLoader(services: SavedObjectKibanaServices): SavedObjectLoader;
};
Copy link
Contributor Author

@pgayvallet pgayvallet Apr 6, 2020

Choose a reason for hiding this comment

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

While trying to reduce the initial bundle size, I saw that the async import of the management section mount I added was only reducing the SOM bundle size from 4mb to 3.7mb. After a few checks, the cause appeared to be the createSavedSearchesLoader static import I'm using in the SOM plugin, that caused the full discover plugin + deps to be bundled into the SOM plugin.

After exposing this method from the contract instead, the SOM plugin is no longer using non-type imports from any plugin, and the initial bundle size went from 3.8mb to 51kb.

cc @elastic/kibana-app (btw it seems the discover NP plugin is not present in CODEOWNERS)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for pinging about the codeowners, I will set up a PR for this.

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Changes in discover plugin LGTM, code review only.

@flash1293
Copy link
Contributor

@pgayvallet There is already a plugin saved_objects providing some functionality around saved objects - should this be merged with saved_objects_management?

@rayafratkina rayafratkina added v7.8.0 and removed v7.8 labels Apr 6, 2020
@pgayvallet
Copy link
Contributor Author

@flash1293 This was an option, but after some discussion, we decided (at least for now) to create a distinct plugin.

Main reasons would be better isolation/ per plugin responsibilities, and the fact that atm, the SOM plugin is depending on plugins exposing their SO loaders, and that we didn't want to propagate these dependencies to the SO plugin, as that would cause cyclic dependencies (namely in the dashboard plugin that requires the savedObject plugin)

We have a follow-up issue (#62048) to get rid of the loaders usages in the SOM plugin that would technically allow to merge SO and SOM at some point though.

Happy to discuss it further if you have an opinion on the subject.

@pgayvallet pgayvallet requested a review from a team April 8, 2020 08:46
@pgayvallet
Copy link
Contributor Author

@flash1293 just merged master, the new discover plugin added to CODEOWNER triggered a review from kibana-app (TIL as your initial approval was done before the CODEOWNER update landed in the PR, it's not taken into account), however there are no additional changes.

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Still LGTM :) Not even code review

@mshustov
Copy link
Contributor

mshustov commented Apr 8, 2020

ack: reviewing...

@@ -22,10 +22,15 @@ import { SavedObjectsManagementPlugin } from './plugin';

export { SavedObjectsManagementPluginSetup, SavedObjectsManagementPluginStart } from './plugin';
export {
ISavedObjectsManagementActionRegistry,
SavedObjectsManagementActionService,
Copy link
Contributor

Choose a reason for hiding this comment

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

don't see any usages outside of the plugin

Comment on lines +95 to +96
// depends on `getStartServices`, should not be awaited
registerServices(this.serviceRegistry, core.getStartServices);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a result of the poor implementation ? as per https://github.com/elastic/kibana/pull/61700/files#r401190691

return {
actionRegistry: this.actionRegistry,
actions: actionSetup,
serviceRegistry: this.serviceRegistry,
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to remove unused API

@@ -65,12 +86,27 @@ export class SavedObjectsManagementPlugin
category: FeatureCatalogueCategory.ADMIN,
});

const actionSetup = this.actionService.setup();

registerManagementSection({
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: why not to keep this logic in the plugin? it would make it possible to assess dependencies from the first glance.

}: MountParams) => {
const [coreStart, { data }, pluginStart] = await core.getStartServices();
const { element, basePath, setBreadcrumbs } = mountParams;
const allowedTypes = await getAllowedTypes(coreStart.http);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it okay to fetch types on every mount?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Low impact, but obviously unnecessary, as these will never change during the app lifecycle. Will fix to only perform the http call on initial mount.

}

export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedObjectsTableState> {
private _isMounted = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙈 on that one. This is there because debouncedFetch is performing debounced http calls followed by setState calls (which will raise an error when called after unmount). Removing that would require to be able to interrupt the http requests on unmount, which is indeed better and technically possible with NP apis but way more complicated than this ugly manual mount stats property (which is indeed an anti-pattern)...

@@ -124,21 +158,20 @@ export class ObjectsTable extends Component {
}

fetchCounts = async () => {
const { allowedTypes } = this.props;
const { queryText, visibleTypes } = parseQuery(this.state.activeQuery);
Copy link
Contributor

Choose a reason for hiding this comment

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

can be typed now when we have usage examples? or you'd prefer to do it in a follow-up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added proper typing to parseQuery param & return type

Comment on lines +34 to 37
return http.post<any>('/api/saved_objects/_resolve_import_errors', {
headers: {
// Important to be undefined, it forces proper headers to be set for FormData
'Content-Type': undefined,
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 say it shouldn't be necessary, but I can see

'Content-Type': 'application/json',

@@ -27,13 +27,11 @@ interface RetryObject {
replaceReferences?: any[];
}

async function callResolveImportErrorsApi(file: File, retries: any) {
async function callResolveImportErrorsApi(http: HttpStart, file: File, retries: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish we split the logic in this file...

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. Honestly the whole src/plugins/saved_objects_management/public/lib utilities are a mess, with honourable mentions for this file and resolve_saved_objects. I want to avoid as must as possible to modify them until I got a clearer vision on what needs to be done to get rid of the SavedObjectLoader usages (in #62048), as this will impact a lot of the lib files.

import { findTestSubject } from '@elastic/eui/lib/test';
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

this API is not meant to be used as public ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though I did try to import from @elastic/eui, but apparently not, as keyCodes is actually exported from the root package.

changed to import { keyCodes } from '@elastic/eui';

findTestSubject however is declared as also available from '@elastic/eui'; in the definition file, but is actually not exported... If I try to import { findTestSubject } from '@elastic/eui';, TS compiler does not complain, however at runtime I get:

TypeError: (0 , _eui.findTestSubject) is not a function

So I still need the ts-ignore on import { findTestSubject } from '@elastic/eui/lib/test';

Ping @elastic/kibana-design ^

@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 358d139 into elastic:master Apr 13, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Apr 13, 2020
* move libs to new plugin

* adapt libs to use NP apis

* add required plugins

* add get_allowed_types route

* move object_view components

* add service registry

* migrate table header component

* migrate table component

* migrate saved_objects_table component

* remove migrated legacy files

* fix re-export from legacy management + section label

* migrate services registration

* adapt management section mock

* fix imports

* migrate flyout component

* migrate relationships component

* migrate saved_objects_table tests

* migrate breadcrumb

* add redirect if unauthorized check

* migrate translations to new savedObjectsManagement prefix

* remove obsolete translations

* convert action registry to service pattern

* wire extra actions

* remove importAndExportableTypes from injected vars

* handle newIndexPatternUrl

* remove duplicate dashboard dependency

* remove old TODO

* remove old TODO

* properly mock lodash in tests

* add async management section loading

* expose createSavedSearchesLoader from discover plugin contract

* address most review comments

* fix merge conflicts
pgayvallet added a commit that referenced this pull request Apr 13, 2020
* Migrate SO management section to NP (#61700)

* move libs to new plugin

* adapt libs to use NP apis

* add required plugins

* add get_allowed_types route

* move object_view components

* add service registry

* migrate table header component

* migrate table component

* migrate saved_objects_table component

* remove migrated legacy files

* fix re-export from legacy management + section label

* migrate services registration

* adapt management section mock

* fix imports

* migrate flyout component

* migrate relationships component

* migrate saved_objects_table tests

* migrate breadcrumb

* add redirect if unauthorized check

* migrate translations to new savedObjectsManagement prefix

* remove obsolete translations

* convert action registry to service pattern

* wire extra actions

* remove importAndExportableTypes from injected vars

* handle newIndexPatternUrl

* remove duplicate dashboard dependency

* remove old TODO

* remove old TODO

* properly mock lodash in tests

* add async management section loading

* expose createSavedSearchesLoader from discover plugin contract

* address most review comments

* fix merge conflicts

* fix types for 7.x
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.

[Platform] SavedObject Management
9 participants