Skip to content

Commit f466ebf

Browse files
Spencerspalger
andauthored
[esArchiver] drop support for --dir, use repo-relative paths instead (#101345)
Co-authored-by: spalger <spalger@users.noreply.github.com>
1 parent 686ade7 commit f466ebf

710 files changed

Lines changed: 2459 additions & 1831 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/developer/contributing/development-functional-tests.asciidoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ export default function ({ getService, getPageObject }) {
229229
before(async () => {
230230
await Promise.all([
231231
// start with an empty .kibana index
232-
esArchiver.load('empty_kibana'),
232+
esArchiver.load('test/functional/fixtures/es_archiver/empty_kibana'),
233233
// load some basic log data only if the index doesn't exist
234-
esArchiver.loadIfNeeded('makelogs')
234+
esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/makelogs')
235235
]);
236236
// go to the page described by `apps.visualize` in the config
237237
await PageObjects.common.navigateTo('visualize');
@@ -243,7 +243,7 @@ export default function ({ getService, getPageObject }) {
243243
// we unload the empty_kibana archive but not the makelogs
244244
// archive because we don't make any changes to it, and subsequent
245245
// suites could use it if they call `.loadIfNeeded()`.
246-
await esArchiver.unload('empty_kibana');
246+
await esArchiver.unload('test/functional/fixtures/es_archiver/empty_kibana');
247247
});
248248
249249
// This series of tests illustrate how tests generally verify
@@ -370,9 +370,9 @@ await testSubjects.click(‘containerButton’);
370370
* Source: {blob}test/common/services/es_archiver.ts[test/common/services/es_archiver.ts]
371371
* Load/unload archives created with the `esArchiver`
372372
* Popular methods:
373-
** `esArchiver.load(name)`
374-
** `esArchiver.loadIfNeeded(name)`
375-
** `esArchiver.unload(name)`
373+
** `esArchiver.load(path)`
374+
** `esArchiver.loadIfNeeded(path)`
375+
** `esArchiver.unload(path)`
376376

377377
Full list of services that are used in functional tests can be found here: {blob}test/functional/services[test/functional/services]
378378

docs/developer/plugin/external-plugin-functional-tests.asciidoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ export default async function ({ readConfigFile }) {
5858
}
5959
},
6060
61-
// choose where esArchiver should load archives from
62-
esArchiver: {
63-
directory: resolve(__dirname, './es_archives'),
64-
},
65-
6661
// choose where screenshots should be saved
6762
screenshots: {
6863
directory: resolve(__dirname, './tmp/screenshots'),

packages/kbn-es-archiver/src/actions/edit.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* Side Public License, v 1.
77
*/
88

9-
import { resolve, relative } from 'path';
9+
import { relative } from 'path';
1010
import Fs from 'fs';
11-
import { createGunzip, createGzip, Z_BEST_COMPRESSION } from 'zlib';
11+
import { createGunzip, createGzip, constants } from 'zlib';
1212
import { promisify } from 'util';
1313
import globby from 'globby';
1414
import { ToolingLog } from '@kbn/dev-utils';
@@ -17,24 +17,22 @@ import { createPromiseFromStreams } from '@kbn/utils';
1717
const unlinkAsync = promisify(Fs.unlink);
1818

1919
export async function editAction({
20-
prefix,
21-
dataDir,
20+
path,
2221
log,
2322
handler,
2423
}: {
25-
prefix: string;
26-
dataDir: string;
24+
path: string;
2725
log: ToolingLog;
2826
handler: () => Promise<any>;
2927
}) {
3028
const archives = (
3129
await globby('**/*.gz', {
32-
cwd: prefix ? resolve(dataDir, prefix) : dataDir,
30+
cwd: path,
3331
absolute: true,
3432
})
35-
).map((path) => ({
36-
path,
37-
rawPath: path.slice(0, -3),
33+
).map((found) => ({
34+
path: found,
35+
rawPath: found.slice(0, -3),
3836
}));
3937

4038
await Promise.all(
@@ -61,7 +59,7 @@ export async function editAction({
6159
archives.map(async (archive) => {
6260
await createPromiseFromStreams([
6361
Fs.createReadStream(archive.rawPath),
64-
createGzip({ level: Z_BEST_COMPRESSION }),
62+
createGzip({ level: constants.Z_BEST_COMPRESSION }),
6563
Fs.createWriteStream(archive.path),
6664
]);
6765

packages/kbn-es-archiver/src/actions/load.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* Side Public License, v 1.
77
*/
88

9-
import { resolve } from 'path';
9+
import { resolve, relative } from 'path';
1010
import { createReadStream } from 'fs';
1111
import { Readable } from 'stream';
12-
import { ToolingLog } from '@kbn/dev-utils';
12+
import { ToolingLog, REPO_ROOT } from '@kbn/dev-utils';
1313
import { KbnClient } from '@kbn/test';
1414
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
1515
import { createPromiseFromStreams, concatStreamProviders } from '@kbn/utils';
@@ -37,23 +37,21 @@ const pipeline = (...streams: Readable[]) =>
3737
);
3838

3939
export async function loadAction({
40-
name,
40+
inputDir,
4141
skipExisting,
4242
useCreate,
4343
client,
44-
dataDir,
4544
log,
4645
kbnClient,
4746
}: {
48-
name: string;
47+
inputDir: string;
4948
skipExisting: boolean;
5049
useCreate: boolean;
5150
client: KibanaClient;
52-
dataDir: string;
5351
log: ToolingLog;
5452
kbnClient: KbnClient;
5553
}) {
56-
const inputDir = resolve(dataDir, name);
54+
const name = relative(REPO_ROOT, inputDir);
5755
const stats = createStats(name, log);
5856
const files = prioritizeMappings(await readDirectory(inputDir));
5957
const kibanaPluginIds = await kbnClient.plugins.getEnabledIds();

packages/kbn-es-archiver/src/actions/rebuild_all.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Side Public License, v 1.
77
*/
88

9-
import { resolve, dirname, relative } from 'path';
9+
import { resolve, relative } from 'path';
1010
import { stat, Stats, rename, createReadStream, createWriteStream } from 'fs';
1111
import { Readable, Writable } from 'stream';
1212
import { fromNode } from 'bluebird';
13-
import { ToolingLog } from '@kbn/dev-utils';
13+
import { ToolingLog, REPO_ROOT } from '@kbn/dev-utils';
1414
import { createPromiseFromStreams } from '@kbn/utils';
1515
import {
1616
prioritizeMappings,
@@ -25,15 +25,7 @@ async function isDirectory(path: string): Promise<boolean> {
2525
return stats.isDirectory();
2626
}
2727

28-
export async function rebuildAllAction({
29-
dataDir,
30-
log,
31-
rootDir = dataDir,
32-
}: {
33-
dataDir: string;
34-
log: ToolingLog;
35-
rootDir?: string;
36-
}) {
28+
export async function rebuildAllAction({ dataDir, log }: { dataDir: string; log: ToolingLog }) {
3729
const childNames = prioritizeMappings(await readDirectory(dataDir));
3830
for (const childName of childNames) {
3931
const childPath = resolve(dataDir, childName);
@@ -42,13 +34,12 @@ export async function rebuildAllAction({
4234
await rebuildAllAction({
4335
dataDir: childPath,
4436
log,
45-
rootDir,
4637
});
4738
continue;
4839
}
4940

50-
const archiveName = dirname(relative(rootDir, childPath));
51-
log.info(`${archiveName} Rebuilding ${childName}`);
41+
const archiveName = relative(REPO_ROOT, childPath);
42+
log.info('[%s] Rebuilding %j', archiveName, childName);
5243
const gzip = isGzip(childPath);
5344
const tempFile = childPath + (gzip ? '.rebuilding.gz' : '.rebuilding');
5445

@@ -60,6 +51,6 @@ export async function rebuildAllAction({
6051
] as [Readable, ...Writable[]]);
6152

6253
await fromNode((cb) => rename(tempFile, childPath, cb));
63-
log.info(`${archiveName} Rebuilt ${childName}`);
54+
log.info('[%s] Rebuilt %j', archiveName, childName);
6455
}
6556
}

packages/kbn-es-archiver/src/actions/save.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Side Public License, v 1.
77
*/
88

9-
import { resolve } from 'path';
9+
import { resolve, relative } from 'path';
1010
import { createWriteStream, mkdirSync } from 'fs';
1111
import { Readable, Writable } from 'stream';
1212
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
13-
import { ToolingLog } from '@kbn/dev-utils';
13+
import { ToolingLog, REPO_ROOT } from '@kbn/dev-utils';
1414
import { createListStream, createPromiseFromStreams } from '@kbn/utils';
1515

1616
import {
@@ -22,23 +22,21 @@ import {
2222
} from '../lib';
2323

2424
export async function saveAction({
25-
name,
25+
outputDir,
2626
indices,
2727
client,
28-
dataDir,
2928
log,
3029
raw,
3130
query,
3231
}: {
33-
name: string;
32+
outputDir: string;
3433
indices: string | string[];
3534
client: KibanaClient;
36-
dataDir: string;
3735
log: ToolingLog;
3836
raw: boolean;
3937
query?: Record<string, any>;
4038
}) {
41-
const outputDir = resolve(dataDir, name);
39+
const name = relative(REPO_ROOT, outputDir);
4240
const stats = createStats(name, log);
4341

4442
log.info('[%s] Creating archive of %j', name, indices);

packages/kbn-es-archiver/src/actions/unload.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* Side Public License, v 1.
77
*/
88

9-
import { resolve } from 'path';
9+
import { resolve, relative } from 'path';
1010
import { createReadStream } from 'fs';
1111
import { Readable, Writable } from 'stream';
1212
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
13-
import { ToolingLog } from '@kbn/dev-utils';
13+
import { ToolingLog, REPO_ROOT } from '@kbn/dev-utils';
1414
import { KbnClient } from '@kbn/test';
1515
import { createPromiseFromStreams } from '@kbn/utils';
1616

@@ -25,19 +25,17 @@ import {
2525
} from '../lib';
2626

2727
export async function unloadAction({
28-
name,
28+
inputDir,
2929
client,
30-
dataDir,
3130
log,
3231
kbnClient,
3332
}: {
34-
name: string;
33+
inputDir: string;
3534
client: KibanaClient;
36-
dataDir: string;
3735
log: ToolingLog;
3836
kbnClient: KbnClient;
3937
}) {
40-
const inputDir = resolve(dataDir, name);
38+
const name = relative(REPO_ROOT, inputDir);
4139
const stats = createStats(name, log);
4240
const kibanaPluginIds = await kbnClient.plugins.getEnabledIds();
4341

0 commit comments

Comments
 (0)