Skip to content

build immutable bundles for new platform plugins#53976

Merged
spalger merged 134 commits intoelastic:masterfrom
spalger:implement/kbn-optimizer
Feb 13, 2020
Merged

build immutable bundles for new platform plugins#53976
spalger merged 134 commits intoelastic:masterfrom
spalger:implement/kbn-optimizer

Conversation

@spalger
Copy link
Copy Markdown
Contributor

@spalger spalger commented Jan 4, 2020

Creates a decoupled optimizer that can build new platform plugins so that they can be distributed as static assets, created at build time, loaded independently in the browser, and never rebuilt in the distributable. See the @kbn/optimizer readme for some more details on the new optimizer.

styles

.scss files can now be imported directly from JS/TS module. node-sass is used to build the linked file as if it was built using node-sass directly (using node-sass module resolution, not webpack's). An import for the src/legacy/ui/public/styles/_styling_constants.scss file is automatically injected at the beginning of each .scss file imported by a JS/TS module so that users can access the styling constants without explicitly pulling in the styles (as requested by design). The styles required by a module are a part of the JS bundle (both light and dark mode variants) and are injected into the page when the module is loaded based on the theme selected for the current page. Light/dark mode variants are built the same way they used to be, by replacing eui_colors_light with eui_colors_dark when it's found in any imported path. A page reload is still required to switch themes.

changes made to plugins

  • new platform plugins now import their root scss files rather that defining uiExports.styleSheetPaths (ie src/plugins/expressions/public/index.ts)
  • any legacy plugins that were purely for building styles have been removed

performance

A primary performance goal of the new optimizer is to build everything as quickly as possible, it does this by running webpack compilers in parallel. This can cause the CPU usage to spike for a bit while the initial build completes. Most people I've talked to prefer that to longer build times, but if you prefer not pegging your CPU you can lower the maximum number of workers using the KBN_OPTIMIZER_MAX_WORKERS environment variable. Setting it to 1 will make the new build take a while, but will cause the least amount of load on your system.

caching

When the files in a bundle haven't changed since the last time it was built, the webpack compiler for that bundle will not be started and instead a watcher will be created to watch the files for changes. Checkout the caching section of the readme


Dev Docs

Plugins that have been migrated to the "new platform" are built with a new system into their own target/public directory. To build third-party plugin's with this new system either pass --plugin-path to node scripts/build_new_platform_plugins or use the @kbn/optimizer package in the Kibana repo to build your plugin as described in the readme for that package.

@spalger spalger force-pushed the implement/kbn-optimizer branch 13 times, most recently from 374f3b1 to 0dc7d68 Compare January 9, 2020 19:30
@spalger spalger force-pushed the implement/kbn-optimizer branch 15 times, most recently from dd74deb to 7c5be03 Compare January 16, 2020 19:27
Copy link
Copy Markdown
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for refactoring this for readability.

I haven't reviewed all 12,000 lines 😬 but I don't have any fundamental issues with how it works and I'm able to follow along. This is going to lay a great foundation for even further improvements going forward!

Copy link
Copy Markdown
Member

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

LGTM - looking forward to this shaving more off the production builds as plugins move over to the new platform. As of right now, this is reducing our HTTP assets on load from 134 to 128 (still crazy high).

Development looks good as well.

One thing which needs a follow-up is that the building of 3rd party plugins was removed in #55281 (comment) so could not be tested as part of this PR.

@spalger
Copy link
Copy Markdown
Contributor Author

spalger commented Feb 14, 2020

7.x/7.7: 9f94c39

@kibanamachine
Copy link
Copy Markdown
Contributor

💔 Build Failed


Test Failures

Kibana Pipeline / kibana-intake-agent / Jest Integration Tests.packages/kbn-plugin-generator/integration_tests.running the plugin-generator via 'node scripts/generate_plugin.js plugin-name' with default config then running with es instance 'yarn start' should result in the spec plugin being initialized on kibana's stdout

Link to Jenkins

Standard Out

Failed Tests Reporter:
  - Test has failed 4 times on tracked branches: https://github.com/elastic/kibana/issues/54481


Stack Trace

Error: Command failed with exit code 126: ./bin/elasticsearch-keystore create
    at makeError (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/execa/lib/error.js:56:11)
    at handlePromise (/var/lib/jenkins/workspace/elastic+kibana+pipeline-pull-request/kibana/node_modules/execa/index.js:114:26)
    at process._tickCallback (internal/process/next_tick.js:68:7)

History

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. Team:Operations Kibana-Operations Team v7.7.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.