From d64436eb9c5e67f62c340be6a8df2f578280d9cc Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Tue, 22 Sep 2020 12:17:13 +0200 Subject: [PATCH] add config value override via cli args --- .../src/config_loader.ts | 3 +- .../src/utils/apply_config_overrides.ts | 38 +++++++++++++++++++ .../kbn-apm-config-loader/src/utils/index.ts | 1 + .../src/utils/read_config.ts | 4 +- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 packages/kbn-apm-config-loader/src/utils/apply_config_overrides.ts diff --git a/packages/kbn-apm-config-loader/src/config_loader.ts b/packages/kbn-apm-config-loader/src/config_loader.ts index 94bbd98df930b..492ed38c85aef 100644 --- a/packages/kbn-apm-config-loader/src/config_loader.ts +++ b/packages/kbn-apm-config-loader/src/config_loader.ts @@ -17,7 +17,7 @@ * under the License. */ -import { getConfigurationFilePaths, getConfigFromFiles } from './utils'; +import { getConfigurationFilePaths, getConfigFromFiles, applyConfigOverrides } from './utils'; import { ApmConfiguration } from './config'; @@ -30,5 +30,6 @@ import { ApmConfiguration } from './config'; export const loadConfiguration = (argv: string[], rootDir: string): ApmConfiguration => { const configPaths = getConfigurationFilePaths(argv); const rawConfiguration = getConfigFromFiles(configPaths); + applyConfigOverrides(rawConfiguration, argv); return new ApmConfiguration(rootDir, rawConfiguration); }; diff --git a/packages/kbn-apm-config-loader/src/utils/apply_config_overrides.ts b/packages/kbn-apm-config-loader/src/utils/apply_config_overrides.ts new file mode 100644 index 0000000000000..acbdbf9c0829d --- /dev/null +++ b/packages/kbn-apm-config-loader/src/utils/apply_config_overrides.ts @@ -0,0 +1,38 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { set } from '@elastic/safer-lodash-set'; +import { getFlagValue } from './read_argv'; + +/** + * Manually applies the specific configuration overrides we need to load the APM config. + * Currently, only these are needed: + * - server.uuid + * - path.data + */ +export const applyConfigOverrides = (config: Record, argv: string[]) => { + const serverUuid = getFlagValue(argv, '--server.uuid'); + if (serverUuid) { + set(config, 'server.uuid', serverUuid); + } + const dataPath = getFlagValue(argv, '--path.data'); + if (dataPath) { + set(config, 'path.data', dataPath); + } +}; diff --git a/packages/kbn-apm-config-loader/src/utils/index.ts b/packages/kbn-apm-config-loader/src/utils/index.ts index 278042e986fb6..03a44e31a44d5 100644 --- a/packages/kbn-apm-config-loader/src/utils/index.ts +++ b/packages/kbn-apm-config-loader/src/utils/index.ts @@ -19,3 +19,4 @@ export { getConfigFromFiles } from './read_config'; export { getConfigurationFilePaths } from './get_config_file_paths'; +export { applyConfigOverrides } from './apply_config_overrides'; diff --git a/packages/kbn-apm-config-loader/src/utils/read_config.ts b/packages/kbn-apm-config-loader/src/utils/read_config.ts index 806366dc3e062..825bfd60181bf 100644 --- a/packages/kbn-apm-config-loader/src/utils/read_config.ts +++ b/packages/kbn-apm-config-loader/src/utils/read_config.ts @@ -50,8 +50,8 @@ function merge(target: Record, value: any, key?: string) { } /** @internal */ -export const getConfigFromFiles = (configFiles: readonly string[]) => { - let mergedYaml = {}; +export const getConfigFromFiles = (configFiles: readonly string[]): Record => { + let mergedYaml: Record = {}; for (const configFile of configFiles) { const yaml = readYaml(configFile);