Skip to content

Commit e07a65e

Browse files
Spencerkibanamachine
andauthored
[serverless] add support for loading serverless specific config locally (#149878)
This adds the `--serverless` CLI arg (only available in dev mode, you can also use `yarn start-serverless`), which will load the new `config/kibana.serverless.yml` file. For now, this file is not included in the build artifact, though we might include a `--serverless` flag which replaces the `kibana.yml` file with `kibana.serverless.yml`. @jbudz will follow up after this PR with the build related changes to get this working with PR cloud deploys, which will be enough changes for us to start iterating on UI specific changes based on running in a serverless environment. Additionally, support for the undocumented `KBN_CONFIG_PATHS` env var is added, which should contain a comma-separated list of paths to kibana config files. These files are loaded, in the specified order, before any of the config files listed in the CLI but after the kibana.yml config file. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
1 parent 214eb97 commit e07a65e

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ disabledPlugins
5050
webpackstats.json
5151
/config/*
5252
!/config/kibana.yml
53+
!/config/kibana.serverless.yml
5354
!/config/node.options
5455
coverage
5556
selenium

config/kibana.serverless.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# as work on serverless picks up we will add config values to this file that
2+
# define how Kibana will run in "serverless" mode. To start Kibana locally with
3+
# this configuration, pass `--serverless` or run `yarn start-serverless`
4+
5+
# configuration is applied in the following order, later values override
6+
# 1. kibana.yml
7+
# 2. kibana.serverless.yml (when --serverless is passed)
8+
# 3. kibana.dev.yml
9+
# 4. kibana.serverless.dev.yml (when --serverless is passed)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"makelogs": "node scripts/makelogs",
5757
"spec_to_console": "node scripts/spec_to_console",
5858
"start": "node scripts/kibana --dev",
59+
"start-serverless": "node scripts/kibana --dev --serverless",
5960
"storybook": "node scripts/storybook",
6061
"test:ftr": "node scripts/functional_tests",
6162
"test:ftr:runner": "node scripts/functional_test_runner",

src/cli/serve/serve.js

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { statSync } from 'fs';
1212
import { resolve } from 'path';
1313
import url from 'url';
1414

15-
import { getConfigPath } from '@kbn/utils';
16-
import { fromRoot, isKibanaDistributable } from '@kbn/repo-info';
15+
import { getConfigPath, getConfigDirectory } from '@kbn/utils';
16+
import { isKibanaDistributable } from '@kbn/repo-info';
1717
import { readKeystore } from '../keystore/read_keystore';
1818

1919
function canRequire(path) {
@@ -55,6 +55,40 @@ const pathCollector = function () {
5555
const configPathCollector = pathCollector();
5656
const pluginPathCollector = pathCollector();
5757

58+
/**
59+
* @param {string} name
60+
* @param {string[]} configs
61+
* @param {'push' | 'unshift'} method
62+
*/
63+
function maybeAddConfig(name, configs, method) {
64+
const path = resolve(getConfigDirectory(), name);
65+
try {
66+
if (statSync(path).isFile()) {
67+
configs[method](path);
68+
}
69+
} catch (err) {
70+
if (err.code === 'ENOENT') {
71+
return;
72+
}
73+
74+
throw err;
75+
}
76+
}
77+
78+
/**
79+
* @returns {string[]}
80+
*/
81+
function getEnvConfigs() {
82+
const val = process.env.KBN_CONFIG_PATHS;
83+
if (typeof val === 'string') {
84+
return val
85+
.split(',')
86+
.filter((v) => !!v)
87+
.map((p) => resolve(p.trim()));
88+
}
89+
return [];
90+
}
91+
5892
function applyConfigOverrides(rawConfig, opts, extraCliOptions) {
5993
const set = _.partial(lodashSet, rawConfig);
6094
const get = _.partial(_.get, rawConfig);
@@ -152,7 +186,7 @@ export default function (program) {
152186
'-c, --config <path>',
153187
'Path to the config file, use multiple --config args to include multiple config files',
154188
configPathCollector,
155-
[getConfigPath()]
189+
[]
156190
)
157191
.option('-p, --port <port>', 'The port to bind to', parseInt)
158192
.option('-Q, --silent', 'Set the root logger level to off')
@@ -177,7 +211,8 @@ export default function (program) {
177211
.option(
178212
'--run-examples',
179213
'Adds plugin paths for all the Kibana example plugins and runs with no base path'
180-
);
214+
)
215+
.option('--serverless', 'Start Kibana with serverless configuration overrides');
181216
}
182217

183218
if (DEV_MODE_SUPPORTED) {
@@ -200,19 +235,22 @@ export default function (program) {
200235
}
201236

202237
command.action(async function (opts) {
238+
const unknownOptions = this.getUnknownOptions();
239+
const configs = [getConfigPath(), ...getEnvConfigs(), ...(opts.config || [])];
240+
241+
// we "unshift" .serverless. config so that it only overrides defaults
242+
if (opts.serverless) {
243+
maybeAddConfig('kibana.serverless.yml', configs, 'unshift');
244+
}
245+
246+
// .dev. configs are "pushed" so that they override all other config files
203247
if (opts.dev && opts.devConfig !== false) {
204-
try {
205-
const kbnDevConfig = fromRoot('config/kibana.dev.yml');
206-
if (statSync(kbnDevConfig).isFile()) {
207-
opts.config.push(kbnDevConfig);
208-
}
209-
} catch (err) {
210-
// ignore, kibana.dev.yml does not exist
248+
maybeAddConfig('kibana.dev.yml', configs, 'push');
249+
if (opts.serverless) {
250+
maybeAddConfig('kibana.serverless.dev.yml', configs, 'push');
211251
}
212252
}
213253

214-
const unknownOptions = this.getUnknownOptions();
215-
const configs = [].concat(opts.config || []);
216254
const cliArgs = {
217255
dev: !!opts.dev,
218256
envName: unknownOptions.env ? unknownOptions.env.name : undefined,
@@ -231,6 +269,7 @@ export default function (program) {
231269
oss: !!opts.oss,
232270
cache: !!opts.cache,
233271
dist: !!opts.dist,
272+
serverless: !!opts.serverless,
234273
};
235274

236275
// In development mode, the main process uses the @kbn/dev-cli-mode

0 commit comments

Comments
 (0)