-
Notifications
You must be signed in to change notification settings - Fork 8.5k
build immutable bundles for new platform plugins #53976
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
Merged
Merged
Changes from all commits
Commits
Show all changes
134 commits
Select commit
Hold shift + click to select a range
f4db1ad
build immutable bundles for new platform plugins
spalger be16d71
Merge branch 'master' into implement/kbn-optimizer
elasticmachine 53794ef
Merge branch 'master' into implement/kbn-optimizer
elasticmachine 0d99762
Merge branch 'master' into implement/kbn-optimizer
elasticmachine bcf6159
Merge branch 'master' into implement/kbn-optimizer
elasticmachine 24ded26
Merge branch 'master' into implement/kbn-optimizer
elasticmachine da80e54
Merge branch 'master' into implement/kbn-optimizer
elasticmachine ac62e68
only inspect workers if configured to do so
spalger 2112fb1
[navigation] use an index.scss file
spalger 3810326
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 2b3a2a0
add yarn.lock symlink
spalger f624d8e
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 13d700b
set pluginScanDirs in test so fixtures stay consistent
spalger ebcae45
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger edc362a
cleanup helpers a little
spalger 42a2640
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 9089c20
fix type error
spalger 7a85b6d
support KBN_OPTIMIZER_MAX_WORKERS for limiting workers via env
spalger e338773
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 58afee8
test support for KBN_OPTIMIZER_MAX_WORKERS
spalger 39b7a96
expand the available memory for workers when only running one or two
spalger c70177d
add docs about KBN_OPTIMIZER_MAX_WORKERS environment variable
spalger 75fde11
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 71294c6
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 4e851f6
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 3dea8ae
fix README link
spalger a8df88e
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger cf6ef2a
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger d5241bd
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger d96475a
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 7a993b1
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 90bd445
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 3668d76
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 9ad7549
update kbn/pm dist
spalger 784df98
implement bundle caching/reuse
spalger 976d711
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 214ca6a
update kbn/pm dist
spalger de191ca
don't check for cache if --no-cache is passed
spalger 8a06c59
update renovate config
spalger c61bb2f
standardize on index.scss, move console styles over
spalger a1d7d6e
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 785a77c
add support for --no-cache to cli
spalger 3422ac8
include worker config vars in optimizer version
spalger c01562e
ignore concatenated modules
spalger 7f2d330
update integration test
spalger d701fe3
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 5ab0208
add safari to browserslist to avoid user-agent warnings in dev
spalger 23d069d
update docs, clean up optimizer message/misc naming
spalger 78ed6b8
always handle initialized messages, don't ignore states that are atta…
spalger 78ae262
Merge branch 'master' into implement/kbn-optimizer
elasticmachine ee8cd0b
Merge branch 'master' into implement/kbn-optimizer
elasticmachine f4787d8
Merge branch 'master' into implement/kbn-optimizer
elasticmachine 18aa8fc
reword caching docs, add environment var to disable caching
spalger 9e2289f
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger c77c8e1
tweak logging and don't use optimizer.useBundleCache as that's disabl…
spalger a5b12c8
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 7c15bc0
handle change notifications
spalger 58f4d57
batch changes for 1 second
spalger ec00ae2
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger bb7b370
Merge branch 'master' into implement/kbn-optimizer
elasticmachine 7d7df93
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger c20b5f2
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 15d1e42
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 60800b0
rename CompilerState type to CompilerMsg
spalger 442ec85
getChanges() no longer needs to assign changes to dirs
spalger af9c89a
remove unused deps
spalger 37c5c0d
split up run_worker.ts and share cacheKey generation logic
spalger 2395ee1
add a couple docs
spalger 02f95a0
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 4e34191
update tests and remove unused imports
spalger 610f65f
specify files when creating bundle cache key
spalger 943bdcd
remove one more unused import
spalger 2eb2cd4
match existing dev cli output more closely
spalger c855d27
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 793a008
update kbn/pm dist
spalger 1d2b14d
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger eb7c282
set KBN_NP_PLUGINS_BUILT to avoid warning in CI
spalger 4f1217b
avoid extending global window type
spalger 33bdf96
add note to keep pluginScanDirs in sync
spalger 6c034e7
pass browserslistEnv in workerConfig so it is used for cache key
spalger dff0ad2
load commons.bundle.js in parallel too
spalger db4aaf7
emit initialized+success states if all bundles are cached
spalger 0991715
load bootstraps as quickly as possible
spalger de1e2f4
skip flaky suite
spalger 5f70256
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger e372290
bump
spalger 05bd681
update jest snapshots
spalger 7d11025
remove hashing from cache key generation
spalger cea523e
remove unnecessary non-null assertion
spalger 262f4ab
improve docs and break up Optimizer#run()
spalger a3c800b
remove unused import
spalger 9f4cbab
refactor kbn/optimizer to break up observable logic, implement more h…
spalger 6adeb68
fix tests
spalger 85a398a
add initializing phase
spalger 7aabd90
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 9546bf7
avoid rxjs observable constructor
spalger 9636ac0
remove unnecessary rxjs helper, add tests for bundle cache
spalger aea28ad
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 096aac7
update consumers of optimizer
spalger 960c2cd
update readme with new call style
spalger a6ce86a
replace "new platform" with "kibana platform"
spalger cebb017
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 04a4e82
fix a couple more renames
spalger 045c86e
add support for several plain-text file formats
spalger b60c6ad
fix naming of OptimizerMsg => OptimizerUpdate, use "store" naming too
spalger 9ca4328
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 8b689f3
one more OptimizerMsg update
spalger 6e18553
ensure bundles are not cached when cache config is false
spalger e77a70a
test for initializing states and bundle cache events
spalger 2896a6e
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 5e553b8
remove unnecessary timeout change
spalger 7bb00e1
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 9c47ff0
Remove unnecessary helpers
spalger 3159b1c
Add tests for BundleCache class
spalger a145e48
Add tests for Bundle class
spalger 242b854
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 1a08b22
test summarizeEvent$
spalger 8880e0c
missing paths are no longer listed in mtimes map
spalger 0b990af
add tests for optimizer/cache_keys
spalger fdf535c
Add some extra docs
spalger deeaa5c
Remove labeled loop
spalger ec977a4
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 9525eb4
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger c190d78
add integration test for kbn-optimizer watcher components
spalger b037200
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger e9b4ad0
querystring-browser removed
spalger bfc269f
tweak logging a smidge, improve info and final message
spalger 3c86dea
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger 654ad79
remove unused imports
spalger 7ab9f52
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger a802d02
remove duplication of getModuleCount() method
spalger 7986dbe
move type annotation that validates things
spalger a0e2e8c
Merge branch 'master' of github.com:elastic/kibana into implement/kbn…
spalger b6390e7
clear up the build completion message
spalger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| [production] | ||
| last 2 versions | ||
| > 5% | ||
| Safari 7 # for PhantomJS support: https://github.com/elastic/kibana/issues/27136 | ||
|
|
||
| [dev] | ||
| last 1 chrome versions | ||
| last 1 firefox versions | ||
| last 1 safari versions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,6 @@ | |
| "glob-all": "^3.1.0", | ||
| "lru-cache": "^4.1.5", | ||
| "resolve": "^1.7.1", | ||
| "webpack": "^4.41.0" | ||
| "webpack": "^4.41.5" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # @kbn/optimizer | ||
|
|
||
| `@kbn/optimizer` is a package for building Kibana platform UI plugins (and hopefully more soon). | ||
|
|
||
| Kibana Platform plugins with `"ui": true` in their `kibana.json` file will have their `public/index.ts` file (and all of its dependencies) bundled into the `target/public` directory of the plugin. The build output does not need to be updated when other plugins are updated and is included in the distributable without requiring that we ship `@kbn/optimizer` 🎉. | ||
|
|
||
| ## Webpack config | ||
|
|
||
| The [Webpack config][WebpackConfig] is designed to provide the majority of what was available in the legacy optimizer and is the same for all plugins to promote consistency and keep things sane for the operations team. It has support for JS/TS built with babel, url imports of image and font files, and support for importing `scss` and `css` files. SCSS is pre-processed by [postcss][PostCss], built for both light and dark mode and injected automatically into the page when the parent module is loaded (page reloads are still required for switching between light/dark mode). CSS is injected into the DOM as it is written on disk when the parent module is loaded (no postcss support). | ||
|
|
||
| Source maps are enabled except when building the distributable. They show the code actually being executed by the browser to strike a balance between debuggability and performance. They are not configurable at this time but will be configurable once we have a developer configuration solution that doesn't rely on the server (see [#55656](https://github.com/elastic/kibana/issues/55656)). | ||
|
|
||
| ### IE Support | ||
|
|
||
| To make front-end code easier to debug the optimizer uses the `BROWSERSLIST_ENV=dev` environment variable (by default) to build JS and CSS that is compatible with modern browsers. In order to support older browsers like IE in development you will need to specify the `BROWSERSLIST_ENV=production` environment variable or build a distributable for testing. | ||
|
|
||
| ## Running the optimizer | ||
|
|
||
| The `@kbn/optimizer` is automatically executed from the dev cli, the Kibana build scripts, and in CI. If you're running Kibana locally in some other way you might need to build the plugins manually, which you can do by running `node scripts/build_kibana_platform_plugins` (pass `--help` for options). | ||
|
|
||
| ### Worker count | ||
|
|
||
| You can limit the number of workers the optimizer uses by setting the `KBN_OPTIMIZER_MAX_WORKERS` environment variable. You might want to do this if your system struggles to keep up while the optimizer is getting started and building all plugins as fast as possible. Setting `KBN_OPTIMIZER_MAX_WORKERS=1` will cause the optimizer to take the longest amount of time but will have the smallest impact on other components of your system. | ||
|
|
||
| We only limit the number of workers we will start at any given time. If we start more workers later we will limit the number of workers we start at that time by the maximum, but we don't take into account the number of workers already started because it is assumed that those workers are doing very little work. This greatly simplifies the logic as we don't ever have to reallocate workers and provides the best performance in most cases. | ||
|
|
||
| ### Caching | ||
|
|
||
| Bundles built by the the optimizer include a cache file which describes the information needed to determine if the bundle needs to be rebuilt when the optimizer is restarted. Caching is enabled by default and is very aggressive about invalidating the cache output, but if you need to disable caching you can pass `--no-cache` to `node scripts/build_kibana_platform_plugins`, or set the `KBN_OPTIMIZER_NO_CACHE` environment variable to anything (env overrides everything). | ||
|
|
||
| When a bundle is determined to be up-to-date a worker is not started for the bundle. If running the optimizer with the `--dev/--watch` flag, then all the files referenced by cached bundles are watched for changes. Once a change is detected in any of the files referenced by the built bundle a worker is started. If a file is changed that is referenced by several bundles then workers will be started for each bundle, combining workers together to respect the worker limit. | ||
|
|
||
| ## API | ||
|
|
||
| To run the optimizer from code, you can import the [`OptimizerConfig`][OptimizerConfig] class and [`runOptimizer`][Optimizer] function. Create an [`OptimizerConfig`][OptimizerConfig] instance by calling it's static `create()` method with some options, then pass it to the [`runOptimizer`][Optimizer] function. `runOptimizer()` returns an observable of update objects, which are summaries of the optimizer state plus an optional `event` property which describes the internal events occuring and may be of use. You can use the [`logOptimizerState()`][LogOptimizerState] helper to write the relevant bits of state to a tooling log or checkout it's implementation to see how the internal events like [`WorkerStdio`][ObserveWorker] and [`WorkerStarted`][ObserveWorker] are used. | ||
|
|
||
| Example: | ||
| ```ts | ||
| import { runOptimizer, OptimizerConfig, logOptimizerState } from '@kbn/optimizer'; | ||
| import { REPO_ROOT, ToolingLog } from '@kbn/dev-utils'; | ||
|
|
||
| const log = new ToolingLog({ | ||
| level: 'verbose', | ||
| writeTo: process.stdout, | ||
| }) | ||
|
|
||
| const config = OptimizerConfig.create({ | ||
| repoRoot: Path.resolve(__dirname, '../../..'), | ||
| watch: false, | ||
| oss: true, | ||
| dist: true | ||
| }); | ||
|
|
||
| await runOptimizer(config) | ||
| .pipe(logOptimizerState(log, config)) | ||
| .toPromise(); | ||
| ``` | ||
|
|
||
| This is essentially what we're doing in [`script/build_kibana_platform_plugins`][Cli] and the new [build system task][BuildTask]. | ||
|
|
||
| ## Internals | ||
|
|
||
| The optimizer runs webpack instances in worker processes. Each worker is configured via a [`WorkerConfig`][WorkerConfig] object and an array of [`Bundle`][Bundle] objects which are JSON serialized and passed to the worker as it's arguments. | ||
|
|
||
| Plugins/bundles are assigned to workers based on the number of modules historically seen in each bundle in an effort to evenly distribute the load across the worker pool (see [`assignBundlesToWorkers`][AssignBundlesToWorkers]). | ||
|
|
||
| The number of workers that will be started at any time is automatically chosen by dividing the number of cores available by 3 (minimum of 2). | ||
|
|
||
| The [`WorkerConfig`][WorkerConfig] includes the location of the repo (it might be one of many builds, or the main repo), wether we are running in watch mode, wether we are building a distributable, and other global config items. | ||
|
|
||
| The [`Bundle`][Bundle] objects which include the details necessary to create a webpack config for a specific plugin's bundle (created using [`webpack.config.ts`][WebpackConfig]). | ||
|
|
||
| Each worker communicates state back to the main process by sending [`WorkerMsg`][WorkerMsg] and [`CompilerMsg`][CompilerMsg] objects using IPC. | ||
|
|
||
| The Optimizer captures all of these messages and produces a stream of update objects. | ||
|
|
||
| Optimizer phases: | ||
| <dl> | ||
| <dt><code>'initializing'</code></dt> | ||
| <dd>Initial phase, during this state the optimizer is validating caches and determining which builds should be built initially.</dd> | ||
| <dt><code>'initialized'</code></dt> | ||
| <dd>Emitted by the optimizer once it's don't initializing its internal state and determined which bundles are going to be built initially.</dd> | ||
| <dt><code>'running'</code></dt> | ||
| <dd>Emitted when any worker is in a running state. To determine which compilers are running, look for <code>BundleState</code> objects with type <code>'running'</code>.</dd> | ||
| <dt><code>'issue'</code></dt> | ||
| <dd>Emitted when all workers are done running and any compiler completed with a <code>'compiler issue'</code> status. Compiler issues include things like "unable to resolve module" or syntax errors in the source modules and can be fixed by users when running in watch mode.</dd> | ||
| <dt><code>'success'</code></dt> | ||
| <dd>Emitted when all workers are done running and all compilers completed with <code>'compiler success'</code>.</dd> | ||
| <dt><code>'reallocating'</code></dt> | ||
| <dd>Emitted when the files referenced by a cached bundle have changed, before the worker has been started up to update that bundle.</dd> | ||
| </dl> | ||
|
|
||
| Workers have several error message they may emit which indicate unrecoverable errors. When any of those messages are received the stream will error and the workers will be torn down. | ||
|
|
||
| For an example of how to handle these states checkout the [`logOptimizerState()`][LogOptimizerState] helper. | ||
|
|
||
| [PostCss]: https://postcss.org/ | ||
| [Cli]: src/cli.ts | ||
| [Optimizer]: src/optimizer.ts | ||
| [ObserveWorker]: src/observe_worker.ts | ||
| [CompilerMsg]: src/common/compiler_messages.ts | ||
| [WorkerMsg]: src/common/worker_messages.ts | ||
| [Bundle]: src/common/bundle.ts | ||
| [WebpackConfig]: src/worker/webpack.config.ts | ||
| [BundleDefinition]: src/common/bundle_definition.ts | ||
| [WorkerConfig]: src/common/worker_config.ts | ||
| [OptimizerConfig]: src/optimizer_config.ts | ||
| [LogOptimizerState]: src/log_optimizer_state.ts | ||
| [AssignBundlesToWorkers]: src/assign_bundles_to_workers.ts | ||
| [BuildTask]: ../../src/dev/build/tasks/build_kibana_platform_plugins.js | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,4 +17,4 @@ | |
| * under the License. | ||
| */ | ||
|
|
||
| module.exports = require('tinymath/lib/tinymath.es5.js'); | ||
| export * from './src/index'; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.