Skip to content
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

Revert "Custom path for data directory configuration is ignored (#157… #158325

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/kbn-utils/src/path/__fixtures__/kibana.yml

This file was deleted.

52 changes: 1 addition & 51 deletions packages/kbn-utils/src/path/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
* Side Public License, v 1.
*/

import { join } from 'path';
import { accessSync, constants } from 'fs';
import { getConfigPath, getDataPath, getLogsPath, getConfigDirectory, buildDataPaths } from '.';
import { getConfigPath, getDataPath, getLogsPath, getConfigDirectory } from '.';
import { REPO_ROOT } from '@kbn/repo-info';

expect.addSnapshotSerializer(
Expand Down Expand Up @@ -47,52 +46,3 @@ describe('Default path finder', () => {
expect(() => accessSync(configPath, constants.R_OK)).not.toThrow();
});
});

describe('Custom data path finder', () => {
const originalArgv = process.argv;

beforeEach(() => {
process.argv = originalArgv;
});

it('overrides path.data when provided as command line argument', () => {
process.argv = ['--foo', 'bar', '--path.data', '/some/data/path', '--baz', 'xyz'];

/*
* Test buildDataPaths since getDataPath returns the first valid directory and
* custom paths do not exist in environment. Custom directories are built during env init.
*/
expect(buildDataPaths()).toMatchInlineSnapshot(`
Array [
<absolute path>/some/data/path,
<absolute path>/data,
"/var/lib/kibana",
]
`);
});

it('ignores the path.data flag when no value is provided', () => {
process.argv = ['--foo', 'bar', '--path.data', '--baz', 'xyz'];

expect(buildDataPaths()).toMatchInlineSnapshot(`
Array [
<absolute path>/data,
"/var/lib/kibana",
]
`);
});

it('overrides path.when when provided by kibana.yml', () => {
process.env.KBN_PATH_CONF = join(__dirname, '__fixtures__');

expect(buildDataPaths()).toMatchInlineSnapshot(`
Array [
<absolute path>/path/from/yml,
<absolute path>/data,
"/var/lib/kibana",
]
`);

delete process.env.KBN_PATH_CONF;
});
});
38 changes: 9 additions & 29 deletions packages/kbn-utils/src/path/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ import { join } from 'path';
import { accessSync, constants } from 'fs';
import { TypeOf, schema } from '@kbn/config-schema';
import { REPO_ROOT } from '@kbn/repo-info';
import { getConfigFromFiles } from '@kbn/config';
import getopts from 'getopts';

const isString = (v: any): v is string => typeof v === 'string';

const buildConfigPaths = () => {
return [
process.env.KBN_PATH_CONF && join(process.env.KBN_PATH_CONF, 'kibana.yml'),
join(REPO_ROOT, 'config/kibana.yml'),
'/etc/kibana/kibana.yml',
].filter(isString);
};
const CONFIG_PATHS = [
process.env.KBN_PATH_CONF && join(process.env.KBN_PATH_CONF, 'kibana.yml'),
join(REPO_ROOT, 'config/kibana.yml'),
'/etc/kibana/kibana.yml',
].filter(isString);

const CONFIG_DIRECTORIES = [
process.env.KBN_PATH_CONF,
join(REPO_ROOT, 'config'),
'/etc/kibana',
].filter(isString);

const DATA_PATHS = [join(REPO_ROOT, 'data'), '/var/lib/kibana'].filter(isString);

const LOGS_PATHS = [join(REPO_ROOT, 'logs'), '/var/log/kibana'].filter(isString);

function findFile(paths: string[]) {
Expand All @@ -43,29 +41,11 @@ function findFile(paths: string[]) {
return availablePath || paths[0];
}

export const buildDataPaths = (): string[] => {
const configDataPath = getConfigFromFiles([getConfigPath()]).path?.data;
const argv = process.argv.slice(2);
const options = getopts(argv, {
string: ['pathData'],
alias: {
pathData: 'path.data',
},
});

return [
!!options.pathData && join(REPO_ROOT, options.pathData),
configDataPath && join(REPO_ROOT, configDataPath),
join(REPO_ROOT, 'data'),
'/var/lib/kibana',
].filter(isString);
};

/**
* Get the path of kibana.yml
* @internal
*/
export const getConfigPath = () => findFile(buildConfigPaths());
export const getConfigPath = () => findFile(CONFIG_PATHS);

/**
* Get the directory containing configuration files
Expand All @@ -77,7 +57,7 @@ export const getConfigDirectory = () => findFile(CONFIG_DIRECTORIES);
* Get the directory containing runtime data
* @internal
*/
export const getDataPath = () => findFile(buildDataPaths());
export const getDataPath = () => findFile(DATA_PATHS);

/**
* Get the directory containing logs
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"kbn_references": [
"@kbn/config-schema",
"@kbn/repo-info",
"@kbn/config",
],
"exclude": [
"target/**/*",
Expand Down