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

Do not serve legacy JS when serving a Kibana Platform application #61011

Merged
merged 23 commits into from
Apr 22, 2020

Conversation

joshdover
Copy link
Contributor

@joshdover joshdover commented Mar 23, 2020

Summary

Fixes #60580
Fixes #58327

  • Removing all legacy imports for src/core/public
  • Adding a new bundle configuration to @kbn/optimizer
  • Update the bootstrapping code to load only the core bundle when we're not rendering a legacy application
  • Removes the legacy core bundle

To do

  • Add tests for core bundle in @kbn/optimizer

Page load time improvements

Here are some stats on a production build comparing this branch to the latest snapshot from master.

Before - Cold Start After - Cold Start Diff Before - Cached After - Cached Diff
Number of requests 128 100 -22% 128 100 -22%
Data transferred 20mb 15.6mb -22% 528kb 516kb -2%
Total resources 103mb 82.2mb -20% 103mb 82.2mb -20%
Time ~12s ~8.5s -30% ~8s ~7s -12%

Checklist

Delete any items that are not applicable to this PR.

For maintainers

Comment on lines +223 to +225
window.location.assign(
this.http.basePath.prepend('/app/kibana#/error/action.auto_create_index')
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: test this case

Copy link
Contributor

Choose a reason for hiding this comment

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

🙈 on this if (isAutoCreateIndexError(error)) { block, but we need to keep the TODO to at least adapt the redirecting url when the page is migrated from legacy.

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 a test for this?

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 remove the auto create index error handling code and views. Probably out of scope for this PR, so I created #63894

@streamich streamich added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Mar 24, 2020
@elasticmachine
Copy link
Contributor

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

@pgayvallet pgayvallet linked an issue Mar 24, 2020 that may be closed by this pull request
2 tasks
Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

Approach looks good to me. Now, is it working 😄 ?

src/core/public/entry_point.ts Show resolved Hide resolved
src/core/public/legacy/legacy_service.ts Show resolved Hide resolved
Comment on lines +223 to +225
window.location.assign(
this.http.basePath.prepend('/app/kibana#/error/action.auto_create_index')
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🙈 on this if (isAutoCreateIndexError(error)) { block, but we need to keep the TODO to at least adapt the redirecting url when the page is migrated from legacy.

src/legacy/ui/ui_render/bootstrap/template.js.hbs Outdated Show resolved Hide resolved
@joshdover joshdover force-pushed the np/slim-bundle branch 2 times, most recently from 80fe38d to 3f17e0a Compare April 7, 2020 22:43
@pgayvallet
Copy link
Contributor

@joshdover is this ready for review?

@joshdover
Copy link
Contributor Author

@joshdover is this ready for review?

I'm planning to add a more tests for the @kbn/optimizer changes, other than that it should be ready.

The other to do is to create a dedicated core bundle that is separate from the core entry point so that more code sharing can be leveraged with the plugin and legacy bundles. However, this can be done in a future PR.

@joshdover joshdover changed the title [Draft] Serve less JS when serving a new platform application Serve less JS when serving a new platform application Apr 9, 2020
@joshdover joshdover marked this pull request as ready for review April 9, 2020 21:18
@joshdover joshdover requested review from a team as code owners April 9, 2020 21:18
@joshdover joshdover added release_note:skip Skip the PR/issue when compiling release notes v7.8.0 labels Apr 9, 2020
@joshdover joshdover added this to Pending Review in kibana-core [DEPRECATED] via automation Apr 9, 2020
@joshdover joshdover changed the title Serve less JS when serving a new platform application Do not serve legacy JS when serving a Kibana Platform application Apr 9, 2020
@joshdover
Copy link
Contributor Author

@cchaos I actually decided to rollback these SCSS changes. I was originally trying to avoid loading some legacy CSS but it turns out there's more there we need right now and cleaning that up feels out of scope for this PR.

For now we will continue to load most of the legacy CSS (still excluding legacy plugin-specific CSS) so that everything still works. We can focus on this more deliberately in #58369.

@cchaos
Copy link
Contributor

cchaos commented Apr 20, 2020

Got it thanks 👍. It would be great if we could eventually have some guidelines around how SASS/CSS is compiled in some form of documentation like the CONTRIBUTING doc. I think this is the most misunderstood part of writing plugins. We have "How to write SASS", but not how to import it into the file system.

@joshdover
Copy link
Contributor Author

@cchaos Scratch that, it was necessary to move. I addressed all of your comments and pushed again with those CSS changes.

@@ -162,7 +162,7 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {
],
},
{
test: /\.scss$/,
test: /\.(scss|css)$/,
Copy link
Contributor

@spalger spalger Apr 20, 2020

Choose a reason for hiding this comment

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

We shouldn't be passing css to the sass-loader, should we? If the file should be parsed as sass I think we should change the extension to scss and not automatically parse it as scss.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, I added this in my first POC iterations and forgot to remove.

src/core/public/entry_point.ts Show resolved Hide resolved
: `${basePath}/${path.publicPath}`
)
.reverse(),
...(isCore
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.

Since the order of CSS files affects the rendered styles, I decided to preserve the current ordering. I think we want to make sure that DLL styles are loaded first so that all subsequent sheets can override them.

It's just too hard to accidentally break things with CSS so I'm erring on the side caution here.

src/legacy/ui/ui_render/ui_render_mixin.js Outdated Show resolved Hide resolved
'{{regularBundlePath}}/kbn-ui-shared-deps/{{sharedJsFilename}}',
'{{dllBundlePath}}/vendors_runtime.bundle.dll.js',
{{#each dllJsChunks}}
{{#each jsDependencies}}
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ this diff

@@ -23,7 +23,7 @@ import { BundleCache } from './bundle_cache';
import { UnknownVals } from './ts_helpers';
import { includes, ascending, entriesToObject } from './array_helpers';

const VALID_BUNDLE_TYPES = ['plugin' as const];
const VALID_BUNDLE_TYPES = ['plugin' as const, 'entry' as const];
Copy link
Contributor

Choose a reason for hiding this comment

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

The inclusion of plugins in those bundles has caused a number of issues over the years and it seems there needs not be a whole "platform" loaded to render those two pages.

Not sure it's feasible. That would add a limitation that security plugin cannot use other plugins API (licensing, for example) on login / logout pages. Also, it's already working with bootstrapping all the KP plugins.

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

👍 Thanks for making those SASS changes!


// Mixins provide generic code expansion through helpers
@import '@elastic/eui/src/global_styling/mixins/index';
// This file is built by both the legacy and KP build systems so we need to
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 this comment!

implement `includeCoreBundle: boolean` config
Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

Optimizer side of things LGTM

@joshdover
Copy link
Contributor Author

@flash1293 would you mind taking a look at the graph changes? I removed an unused scss import and added a manual import for angular-route that was inadvertently imported by core before.

@joshdover
Copy link
Contributor Author

@elasticmachine merge upstream

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.

Tested Graph changes in Chrome and everything works as expected, LGTM 👍 I will take care of inlining the wrapper styles in a separate PR.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@joshdover joshdover merged commit fc1f4f2 into elastic:master Apr 22, 2020
kibana-core [DEPRECATED] automation moved this from Pending Review to Done (7.8) Apr 22, 2020
@joshdover joshdover deleted the np/slim-bundle branch April 22, 2020 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
Projects
10 participants