Skip to content

Commit

Permalink
add config value override via cli args
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Sep 22, 2020
1 parent 9436580 commit d64436e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/kbn-apm-config-loader/src/config_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { getConfigurationFilePaths, getConfigFromFiles } from './utils';
import { getConfigurationFilePaths, getConfigFromFiles, applyConfigOverrides } from './utils';

import { ApmConfiguration } from './config';

Expand All @@ -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);
};
38 changes: 38 additions & 0 deletions packages/kbn-apm-config-loader/src/utils/apply_config_overrides.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>, 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);
}
};
1 change: 1 addition & 0 deletions packages/kbn-apm-config-loader/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@

export { getConfigFromFiles } from './read_config';
export { getConfigurationFilePaths } from './get_config_file_paths';
export { applyConfigOverrides } from './apply_config_overrides';
4 changes: 2 additions & 2 deletions packages/kbn-apm-config-loader/src/utils/read_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ function merge(target: Record<string, any>, value: any, key?: string) {
}

/** @internal */
export const getConfigFromFiles = (configFiles: readonly string[]) => {
let mergedYaml = {};
export const getConfigFromFiles = (configFiles: readonly string[]): Record<string, any> => {
let mergedYaml: Record<string, any> = {};

for (const configFile of configFiles) {
const yaml = readYaml(configFile);
Expand Down

0 comments on commit d64436e

Please sign in to comment.