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

fix/142865/path.data config unused #158426

Merged
merged 54 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6bfc174
Handle path.data in config file and CLI option
Ikuni17 May 11, 2023
a036de6
Extract into data path builder func
Ikuni17 May 12, 2023
316331b
Add tests for argv
Ikuni17 May 12, 2023
22e75f0
Add kibana.yml data path test
Ikuni17 May 13, 2023
048ac28
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine May 13, 2023
a09c3b2
Merge branch 'main' into fix/142865/path.data-config-unused
kibanamachine May 15, 2023
072e1d1
Merge branch 'elastic:main' into fix/142865/path.data-config-unused
Ikuni17 May 24, 2023
0b7a814
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 May 24, 2023
4841d25
Use path.resolve. Add tests for relative and absolute paths
Ikuni17 May 24, 2023
33cc643
Update docs
Ikuni17 May 24, 2023
fce8251
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 May 24, 2023
33ea1aa
Better test descriptions
Ikuni17 May 24, 2023
725acd0
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Sep 1, 2023
9b018cd
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Sep 5, 2023
f2391c2
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 5, 2023
bf4579c
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Sep 5, 2023
d7c2696
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Sep 5, 2023
77b4c37
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Sep 5, 2023
4d0c4fc
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Sep 5, 2023
9d8163c
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Sep 5, 2023
db4ad39
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Sep 5, 2023
bb4cc5c
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Sep 5, 2023
b00e1de
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Sep 6, 2023
6b35b11
Merge remote-tracking branch 'upstream/main' into fix/142865/path.dat…
Ikuni17 Sep 8, 2023
8d1aaa7
Merge remote-tracking branch 'upstream/main' into fix/142865/path.dat…
Ikuni17 Sep 21, 2023
f50fb73
Merge remote-tracking branch 'upstream/main' into fix/142865/path.dat…
Ikuni17 Oct 4, 2023
7cb9c95
Merge remote-tracking branch 'upstream/main' into fix/142865/path.dat…
Ikuni17 Oct 5, 2023
289bdaa
Merge remote-tracking branch 'upstream/main' into fix/142865/path.dat…
Ikuni17 Oct 6, 2023
120b1ad
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 14, 2023
0175750
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 15, 2023
02877b1
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 15, 2023
7adb4ed
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 15, 2023
44f7e4c
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Nov 17, 2023
96d7909
Merge branch 'fix/142865/path.data-config-unused' of github.com:Ikuni…
Ikuni17 Nov 20, 2023
6985c98
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 20, 2023
f12f51f
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 21, 2023
ef00174
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Nov 22, 2023
73b8049
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Nov 23, 2023
aee011a
Merge branch 'main' into fix/142865/path.data-config-unused
kibanamachine Nov 23, 2023
5fe66ca
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Nov 23, 2023
c78fb79
Merge branch 'fix/142865/path.data-config-unused' of github.com:Ikuni…
Ikuni17 Nov 27, 2023
95ff53e
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Nov 28, 2023
4d7806d
Use resolve for config path
Ikuni17 Nov 28, 2023
e72afb9
Merge branch 'fix/142865/path.data-config-unused' of github.com:Ikuni…
Ikuni17 Nov 28, 2023
92a2ed1
Add missing test case
Ikuni17 Nov 28, 2023
d9c1703
Merge branch 'main' into fix/142865/path.data-config-unused
kibanamachine Nov 28, 2023
7155f95
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 28, 2023
22cc151
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 28, 2023
a27a061
Merge branch 'main' into fix/142865/path.data-config-unused
mistic Nov 28, 2023
fa2b9cb
Debug project build
Ikuni17 Nov 28, 2023
5af270e
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 28, 2023
b1a77c8
Revert "Debug project build"
Ikuni17 Nov 28, 2023
dc0e9e8
Merge branch 'fix/142865/path.data-config-unused' of github.com:Ikuni…
Ikuni17 Nov 28, 2023
fccf78e
Merge branch 'main' into fix/142865/path.data-config-unused
Ikuni17 Nov 28, 2023
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
5 changes: 3 additions & 2 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ or `*` to select all roles. *Default: `*`*
Choose the default email connector for user notifications. As of `8.6.0`, {kib} is shipping with a new notification mechanism that will send email notifications for various user actions, e.g. assigning a _Case_ to a user. To enable notifications, an email connector must be <<pre-configured-connectors,preconfigured>> in the system via `kibana.yml`, and the notifications plugin must be configured to point to the ID of that connector.

[[path-data]] `path.data`::
The path where {kib} stores persistent data
not saved in {es}. *Default: `data`*
The path where {kib} stores persistent data not saved in {es}.
Can be a relative or absolute path.
Relative paths are resolved starting from the installation directory. *Default: `data`*

`pid.file`::
Specifies the path where {kib} creates the process ID file.
Expand Down
98 changes: 97 additions & 1 deletion packages/kbn-utils/src/path/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
* Side Public License, v 1.
*/

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

expect.addSnapshotSerializer(
Expand Down Expand Up @@ -46,3 +48,97 @@ 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('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",
]
`);
});

describe('overrides path.data when provided as command line argument', () => {
it('with absolute path', () => {
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 [
"/some/data/path",
<absolute path>/data,
"/var/lib/kibana",
]
`);
});

it('with relative path', () => {
process.argv = ['--foo', 'bar', '--path.data', 'data2', '--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>/data2,
<absolute path>/data,
"/var/lib/kibana",
]
`);
});
});

describe('overrides path.data when provided by kibana.yml', () => {
let tempDir: string;
let tempConfigFile: string;

beforeAll(async () => {
tempDir = await mkdtemp('config-test');
tempConfigFile = join(tempDir, 'kibana.yml');
});

afterAll(async () => {
await rm(tempDir, { recursive: true });
delete process.env.KBN_PATH_CONF;
});

it('with absolute path', async () => {
process.env.KBN_PATH_CONF = tempDir;
await writeFile(tempConfigFile, `path.data: /path/from/yml`);

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

it('with relative path', async () => {
process.env.KBN_PATH_CONF = tempDir;
await writeFile(tempConfigFile, `path.data: data2`);

expect(buildDataPaths()).toMatchInlineSnapshot(`
Array [
<absolute path>/data2,
<absolute path>/data,
"/var/lib/kibana",
]
`);
});
});
});
40 changes: 30 additions & 10 deletions packages/kbn-utils/src/path/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@
* Side Public License, v 1.
*/

import { join } from 'path';
import { join, resolve } 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 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 buildConfigPaths = () => {
return [
process.env.KBN_PATH_CONF && resolve(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 @@ -41,11 +43,29 @@ 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 && resolve(REPO_ROOT, options.pathData),
configDataPath && resolve(REPO_ROOT, configDataPath),
join(REPO_ROOT, 'data'),
'/var/lib/kibana',
].filter(isString);
};

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

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

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