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

Introduce start lifecycle event to client #35269

Merged
merged 7 commits into from
Apr 23, 2019
Merged

Conversation

joshdover
Copy link
Contributor

@joshdover joshdover commented Apr 17, 2019

Summary

In preparation for the ApplicationService, we need a point in time where we know all applications are registered in order to perform privilege checks and other setup. To support this, I'm re-introducing the start lifecycle hook to core services and plugins.

This comes with a couple caveats when it comes to integrating with legacy browser code:

Some core services are not going to be available at legacy files import time

CoreSetup will be available when legacy files are imported, but CoreStart will not be available until just before angular is bootstrapped.

For instance, CapabilitiesService will not be able to provide any data until the start lifecycle event. Any legacy code that needs services that are not available until start will need to execute within an Angular context, at which point these services are guaranteed to be available.

Setup contracts can still be used in legacy code after setup is finished

We don't have a mechanism in place that allows us to prevent usage of setup contracts after setup is complete and we are in the "start" part of the lifecycle.

Many of the things in setup may need to moved to start or exposed in start as well as setup. I've done some of that in this PR, but I plan to flesh this out more (specifically, the ChromeService) as the ApplicationService is built out since there are dependencies here.


If the platform team feels comfortable moving forward, I expect this to land around the same time as #35297 which introduces the start event on the server as well. At that time, we should also make sure to update the Migration Guide.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@joshdover joshdover changed the title [wip] Move capabilities to 'start' lifecycle event [wip] Introduce start lifecycle event to client Apr 18, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@joshdover joshdover changed the title [wip] Introduce start lifecycle event to client Introduce start lifecycle event to client Apr 18, 2019
@joshdover joshdover added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.2.0 v8.0.0 labels Apr 18, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform

@joshdover joshdover added Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes labels Apr 18, 2019
@joshdover joshdover marked this pull request as ready for review April 18, 2019 21:55
@joshdover joshdover requested review from a team as code owners April 18, 2019 21:55
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@eliperelman eliperelman left a comment

Choose a reason for hiding this comment

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

Great start, have a few notes.

src/core/public/core_system.ts Show resolved Hide resolved

return { fatalErrors };
await this.plugins.start(core);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any harm in doing these in parallel?

await Promise.all([
  this.plugins.start(core),
  this.legacyPlatform.start({ core, targetDomElement: legacyPlatformTargetDomElement }),
]);

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, though we don't do this yet, I believe we will expose new platform plugin contracts to the legacy platform. We'll need those contracts to be available before we even kick off the legacy code.

src/core/public/i18n/i18n_service.mock.ts Outdated Show resolved Hide resolved
constructor(private readonly params: LegacyPlatformParams) {}

public setup(core: CoreSetup) {
public async setup({ core }: SetupDeps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that instead of passing core as an argument to setup it is now passed as a property to this object. Can you explain why this was necessary?

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 did this for consistency, since all the other services accept an option bag. Now that I'm reading this again, I think I'll put it back since CoreSetup is already a bag of services.

uiSettings,
chrome,
} = core;
// Inject parts of the new platform into parts of the legacy platform
// so that legacy APIs/modules can mimic their new platform counterparts
require('ui/new_platform').__newPlatformInit__(core);
require('ui/new_platform').__newPlatformInitSetup__(core);
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like Init was the identifier being used to denote faking setup. Thoughts on renaming these identifiers to __newPlatformSetup__ and exposing __newPlatformStart__?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess there are 3 now. Can you explain why we need all of __newPlatformInit__, __newPlatformInitSetup__, and __newPlatformInitStart__ ?

Copy link
Contributor Author

@joshdover joshdover Apr 22, 2019

Choose a reason for hiding this comment

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

I think your first suggestion makes sense: __newPlatformSetup__ and __newPlatformStart__. I don't think we currently expose anything to the legacy code when the LegacyService is constructed, so no init should be needed.

src/core/public/plugins/plugin.test.ts Show resolved Hide resolved
throw new Error(`Plugin "${this.name}" can't be started since it isn't set up.`);
}

return await this.instance.start(startContext, plugins);
Copy link
Contributor

Choose a reason for hiding this comment

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

return await is typically redundant outside of try/catch blocks, can you explain the reasoning for awaiting 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.

It's a little redundant, I agree. I think it's a bit matter of opinion here, but I've started to prefer using await on promise return values so that if someone does add try/catch later, they don't forget that what is being called won't throw without an await.

Copy link
Contributor

@kobelb kobelb left a comment

Choose a reason for hiding this comment

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

LGTM from the security perspective, I'll defer to others on the new platform details

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@eliperelman eliperelman left a comment

Choose a reason for hiding this comment

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

PR revision LGTM!

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.2.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants