From 6f44a4fa6de81e041a4c1b67e15a89971d143b21 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 30 Sep 2020 14:07:50 -0700 Subject: [PATCH 1/4] [dev/server] default the max-old-space-size to 4gb --- src/cli/cluster/worker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/cluster/worker.ts b/src/cli/cluster/worker.ts index c8a8a067d30bf..7dc44c08e0868 100644 --- a/src/cli/cluster/worker.ts +++ b/src/cli/cluster/worker.ts @@ -86,7 +86,7 @@ export class Worker extends EventEmitter { this.processBinder = new BinderFor(process); this.env = { - NODE_OPTIONS: process.env.NODE_OPTIONS || '', + NODE_OPTIONS: process.env.NODE_OPTIONS || '--max-old-space-size=4000', kbnWorkerType: this.type, kbnWorkerArgv: JSON.stringify([...(opts.baseArgv || baseArgv), ...(opts.argv || [])]), }; From b8e7ac28ca406104fc1f38f230c98c0b9c2b92da Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 30 Sep 2020 16:16:15 -0700 Subject: [PATCH 2/4] disable babel cache in parent process of dev cli --- scripts/kibana.js | 5 +- scripts/precommit_hook.js | 2 +- src/setup_node_env/babel_register/index.js | 6 +- src/setup_node_env/babel_register/register.js | 117 ++++++++++-------- src/setup_node_env/index.js | 2 +- 5 files changed, 77 insertions(+), 55 deletions(-) diff --git a/scripts/kibana.js b/scripts/kibana.js index f5a63e6c07dd6..cdd9d88ac7406 100644 --- a/scripts/kibana.js +++ b/scripts/kibana.js @@ -18,5 +18,8 @@ */ require('../src/apm')(process.env.ELASTIC_APM_PROXY_SERVICE_NAME || 'kibana-proxy'); -require('../src/setup_node_env'); +require('../src/setup_node_env/prebuilt_dev_only_entry'); +require('../src/setup_node_env/babel_register')({ + cache: false, +}); require('../src/cli/cli'); diff --git a/scripts/precommit_hook.js b/scripts/precommit_hook.js index 7b9647cb7a911..d66f5aaaadd6e 100644 --- a/scripts/precommit_hook.js +++ b/scripts/precommit_hook.js @@ -17,5 +17,5 @@ * under the License. */ -require('../src/setup_node_env/babel_register'); +require('../src/setup_node_env/babel_register')(); require('../src/dev/run_precommit_hook'); diff --git a/src/setup_node_env/babel_register/index.js b/src/setup_node_env/babel_register/index.js index 1574be8937a29..f0e66bd97ee71 100644 --- a/src/setup_node_env/babel_register/index.js +++ b/src/setup_node_env/babel_register/index.js @@ -20,5 +20,7 @@ // register and polyfill need to happen in this // order and in separate files. Checkout each file // for a much more detailed explanation -require('./register'); -require('./polyfill'); +module.exports = function (options) { + require('./register')(options); + require('./polyfill'); +}; diff --git a/src/setup_node_env/babel_register/register.js b/src/setup_node_env/babel_register/register.js index 6d573d8922244..59f686bf26604 100644 --- a/src/setup_node_env/babel_register/register.js +++ b/src/setup_node_env/babel_register/register.js @@ -19,59 +19,76 @@ var resolve = require('path').resolve; -// this must happen before `require('@babel/register')` and can't be changed -// once the module has been loaded -if (!process.env.BABEL_CACHE_PATH) { - process.env.BABEL_CACHE_PATH = resolve( - __dirname, - '../../../data/optimize/.babel_register_cache.json' - ); -} +module.exports = function (options) { + options = options || {}; -// paths that @babel/register should ignore -var ignore = [ - /[\/\\]bower_components[\/\\]/, - /[\/\\]kbn-pm[\/\\]dist[\/\\]/, + // this must happen before `require('@babel/register')` and can't be changed + // once the module has been loaded + if (!process.env.BABEL_CACHE_PATH) { + process.env.BABEL_CACHE_PATH = resolve( + __dirname, + '../../../data/optimize/.babel_register_cache.json' + ); + } - // TODO: remove this and just transpile plugins at build time, but - // has tricky edge cases that will probably require better eslint - // restrictions to make sure that code destined for the server/browser - // follows respects the limitations of each environment. - // - // https://github.com/elastic/kibana/issues/14800#issuecomment-366130268 + // paths that @babel/register should ignore + var ignore = [ + /[\/\\]bower_components[\/\\]/, + /[\/\\]kbn-pm[\/\\]dist[\/\\]/, - // ignore paths matching `/node_modules/{a}/{b}`, unless `a` - // is `x-pack` and `b` is not `node_modules` - /[\/\\]node_modules[\/\\](?!x-pack[\/\\](?!node_modules)([^\/\\]+))([^\/\\]+[\/\\][^\/\\]+)/, + // TODO: remove this and just transpile plugins at build time, but + // has tricky edge cases that will probably require better eslint + // restrictions to make sure that code destined for the server/browser + // follows respects the limitations of each environment. + // + // https://github.com/elastic/kibana/issues/14800#issuecomment-366130268 - // ignore paths matching `/canvas/canvas_plugin/` - /[\/\\]canvas[\/\\]canvas_plugin[\/\\]/, -]; + // ignore paths matching `/node_modules/{a}/{b}`, unless `a` + // is `x-pack` and `b` is not `node_modules` + /[\/\\]node_modules[\/\\](?!x-pack[\/\\](?!node_modules)([^\/\\]+))([^\/\\]+[\/\\][^\/\\]+)/, -if (global.__BUILT_WITH_BABEL__) { - // when building the Kibana source we replace the statement - // `global.__BUILT_WITH_BABEL__` with the value `true` so that - // when @babel/register is required for the first time by users - // it will exclude kibana's `src` directory. - // - // We still need @babel/register for plugins though, we've been - // building their server code at require-time since version 4.2 - // TODO: the plugin install process could transpile plugin server code... - ignore.push(resolve(__dirname, '../../../src')); -} else { - ignore.push( - // ignore any path in the packages, unless it is in the package's - // root `src` directory, in any test or __tests__ directory, or it - // ends with .test.js, .test.ts, or .test.tsx - /[\/\\]packages[\/\\](eslint-|kbn-)[^\/\\]+[\/\\](?!src[\/\\].*|(.+[\/\\])?(test|__tests__)[\/\\].+|.+\.test\.(js|ts|tsx)$)(.+$)/ - ); -} + // ignore paths matching `/canvas/canvas_plugin/` + /[\/\\]canvas[\/\\]canvas_plugin[\/\\]/, + ]; -// modifies all future calls to require() to automatically -// compile the required source with babel -require('@babel/register')({ - ignore, - babelrc: false, - presets: [require.resolve('@kbn/babel-preset/node_preset')], - extensions: ['.js', '.ts', '.tsx'], -}); + if (global.__BUILT_WITH_BABEL__) { + // when building the Kibana source we replace the statement + // `global.__BUILT_WITH_BABEL__` with the value `true` so that + // when @babel/register is required for the first time by users + // it will exclude kibana's `src` directory. + // + // We still need @babel/register for plugins though, we've been + // building their server code at require-time since version 4.2 + // TODO: the plugin install process could transpile plugin server code... + ignore.push(resolve(__dirname, '../../../src')); + } else { + ignore.push( + // ignore any path in the packages, unless it is in the package's + // root `src` directory, in any test or __tests__ directory, or it + // ends with .test.js, .test.ts, or .test.tsx + /[\/\\]packages[\/\\](eslint-|kbn-)[^\/\\]+[\/\\](?!src[\/\\].*|(.+[\/\\])?(test|__tests__)[\/\\].+|.+\.test\.(js|ts|tsx)$)(.+$)/ + ); + } + + // prevent @babel/register from loading cache on require by setting env var + var clearBabelCacheEnvVar = false; + if (options.cache === false) { + clearBabelCacheEnvVar = true; + process.env.BABEL_DISABLE_CACHE = 'true'; + } + + // modifies all future calls to require() to automatically + // compile the required source with babel + require('@babel/register')({ + ignore, + cache: options.cache !== false, + babelrc: false, + presets: [require.resolve('@kbn/babel-preset/node_preset')], + extensions: ['.js', '.ts', '.tsx'], + }); + + // clear the disable cache env var if we set it to prevent cache loading + if (clearBabelCacheEnvVar) { + delete process.env.BABEL_DISABLE_CACHE; + } +}; diff --git a/src/setup_node_env/index.js b/src/setup_node_env/index.js index d84249df7fd8f..f650a67ed1497 100644 --- a/src/setup_node_env/index.js +++ b/src/setup_node_env/index.js @@ -18,4 +18,4 @@ */ require('./prebuilt_dev_only_entry'); -require('./babel_register'); +require('./babel_register')(); From 5766350a31ff68694f8b403c723fcbb8aa71c447 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 30 Sep 2020 16:16:39 -0700 Subject: [PATCH 3/4] disable plugin discovery in parent process of dev cli --- src/core/server/plugins/plugins_service.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core/server/plugins/plugins_service.ts b/src/core/server/plugins/plugins_service.ts index e8fe42ee491ca..a1062bde7765f 100644 --- a/src/core/server/plugins/plugins_service.ts +++ b/src/core/server/plugins/plugins_service.ts @@ -18,7 +18,7 @@ */ import Path from 'path'; -import { Observable } from 'rxjs'; +import { Observable, EMPTY } from 'rxjs'; import { filter, first, map, mergeMap, tap, toArray } from 'rxjs/operators'; import { pick } from '@kbn/std'; @@ -86,9 +86,11 @@ export class PluginsService implements CoreService; private readonly pluginConfigDescriptors = new Map(); private readonly uiPluginInternalInfo = new Map(); + private readonly discoveryDisabled: boolean; constructor(private readonly coreContext: CoreContext) { this.log = coreContext.logger.get('plugins-service'); + this.discoveryDisabled = coreContext.env.isDevClusterMaster; this.pluginsSystem = new PluginsSystem(coreContext); this.configService = coreContext.configService; this.config$ = coreContext.configService @@ -97,13 +99,17 @@ export class PluginsService implements CoreService Date: Wed, 30 Sep 2020 16:19:16 -0700 Subject: [PATCH 4/4] be exact about 4gb --- src/cli/cluster/worker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/cluster/worker.ts b/src/cli/cluster/worker.ts index 7dc44c08e0868..ebcf8f3fe5e3d 100644 --- a/src/cli/cluster/worker.ts +++ b/src/cli/cluster/worker.ts @@ -86,7 +86,7 @@ export class Worker extends EventEmitter { this.processBinder = new BinderFor(process); this.env = { - NODE_OPTIONS: process.env.NODE_OPTIONS || '--max-old-space-size=4000', + NODE_OPTIONS: process.env.NODE_OPTIONS || '--max-old-space-size=4096', kbnWorkerType: this.type, kbnWorkerArgv: JSON.stringify([...(opts.baseArgv || baseArgv), ...(opts.argv || [])]), };