Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[kbnArchiver] convert archive names to root-relative paths (elastic#1…
Browse files Browse the repository at this point in the history
…01839)

* [kbnArchiver] convert archive names to root-relative paths

* ensure that newly multiline hooks are explicitly async

* missed a newly multiline hook

* fix exists check

* avoid extra lines by wrapping arrow body in {}

* one block more

* fix errant `name` variable

Co-authored-by: spalger <spalger@users.noreply.github.com>
# Conflicts:
#	test/api_integration/apis/kql_telemetry/kql_telemetry.ts
#	test/api_integration/apis/saved_objects/bulk_create.ts
#	test/api_integration/apis/saved_objects/bulk_get.ts
#	test/api_integration/apis/saved_objects/bulk_update.ts
#	test/api_integration/apis/saved_objects/create.ts
#	test/api_integration/apis/saved_objects/delete.ts
#	test/api_integration/apis/saved_objects/export.ts
#	test/api_integration/apis/saved_objects/find.ts
#	test/api_integration/apis/saved_objects/get.ts
#	test/api_integration/apis/saved_objects/import.ts
#	test/api_integration/apis/saved_objects/resolve.ts
#	test/api_integration/apis/saved_objects/resolve_import_errors.ts
#	test/api_integration/apis/saved_objects/update.ts
#	test/api_integration/apis/saved_objects_management/find.ts
#	test/api_integration/apis/saved_objects_management/get.ts
#	test/api_integration/apis/saved_objects_management/relationships.ts
#	test/api_integration/apis/shorten/index.js
#	test/api_integration/apis/stats/stats.js
#	test/api_integration/apis/suggestions/suggestions.js
#	test/functional/apps/discover/_discover.ts
  • Loading branch information
Spencer authored and spalger committed Jun 10, 2021
1 parent 15fe0f9 commit a23a072
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 53 deletions.
23 changes: 2 additions & 21 deletions packages/kbn-test/src/kbn_archiver_cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ export function runKbnArchiverCli() {
new RunWithCommands({
description: 'Import/export saved objects from archives, for testing',
globalFlags: {
string: ['config', 'space', 'kibana-url', 'dir'],
string: ['config', 'space', 'kibana-url'],
help: `
--space space id to operate on, defaults to the default space
--config optional path to an FTR config file that will be parsed and used for defaults
--kibana-url set the url that kibana can be reached at, uses the "servers.kibana" setting from --config by default
--dir directory that contains exports to be imported, or where exports will be saved, uses the "kbnArchiver.directory"
setting from --config by default
`,
},
async extendContext({ log, flags }) {
Expand Down Expand Up @@ -79,23 +77,6 @@ export function runKbnArchiverCli() {
);
}

let importExportDir;
if (flags.dir) {
if (typeof flags.dir !== 'string') {
throw createFlagError('expected --dir to be a string');
}

importExportDir = flags.dir;
} else if (config) {
importExportDir = config.get('kbnArchiver.directory');
}

if (!importExportDir) {
throw createFlagError(
'--config does not include a kbnArchiver.directory, specify it or include --dir flag'
);
}

const space = flags.space;
if (!(space === undefined || typeof space === 'string')) {
throw createFlagError('--space must be a string');
Expand All @@ -106,7 +87,7 @@ export function runKbnArchiverCli() {
kbnClient: new KbnClient({
log,
url: kibanaUrl,
importExportDir,
importExportBaseDir: process.cwd(),
}),
};
},
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-test/src/kbn_client/kbn_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface KbnClientOptions {
certificateAuthorities?: Buffer[];
log: ToolingLog;
uiSettingDefaults?: UiSettingValues;
importExportDir?: string;
importExportBaseDir?: string;
}

export class KbnClient {
Expand Down Expand Up @@ -64,7 +64,7 @@ export class KbnClient {
this.log,
this.requester,
this.savedObjects,
options.importExportDir
options.importExportBaseDir
);
}

Expand Down
26 changes: 14 additions & 12 deletions packages/kbn-test/src/kbn_client/kbn_client_import_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import { inspect } from 'util';
import Fs from 'fs/promises';
import { existsSync } from 'fs';
import Path from 'path';

import FormData from 'form-data';
import { ToolingLog, isAxiosResponseError, createFailError } from '@kbn/dev-utils';
import { ToolingLog, isAxiosResponseError, createFailError, REPO_ROOT } from '@kbn/dev-utils';

import { KbnClientRequester, uriencode, ReqOptions } from './kbn_client_requester';
import { KbnClientSavedObjects } from './kbn_client_saved_objects';
Expand Down Expand Up @@ -39,26 +40,27 @@ export class KbnClientImportExport {
public readonly log: ToolingLog,
public readonly requester: KbnClientRequester,
public readonly savedObjects: KbnClientSavedObjects,
public readonly dir?: string
public readonly baseDir: string = REPO_ROOT
) {}

private resolvePath(path: string) {
if (!Path.extname(path)) {
path = `${path}.json`;
}

if (!this.dir && !Path.isAbsolute(path)) {
const absolutePath = Path.resolve(this.baseDir, path);
if (!existsSync(absolutePath)) {
throw new Error(
'unable to resolve relative path to import/export without a configured dir, either path absolute path or specify --dir'
`unable to resolve path [${path}] to import/export, resolved relative to [${this.baseDir}]`
);
}

return this.dir ? Path.resolve(this.dir, path) : path;
return absolutePath;
}

async load(name: string, options?: { space?: string }) {
const src = this.resolvePath(name);
this.log.debug('resolved import for', name, 'to', src);
async load(path: string, options?: { space?: string }) {
const src = this.resolvePath(path);
this.log.debug('resolved import for', path, 'to', src);

const objects = await parseArchive(src);
this.log.info('importing', objects.length, 'saved objects', { space: options?.space });
Expand Down Expand Up @@ -91,8 +93,8 @@ export class KbnClientImportExport {
}
}

async unload(name: string, options?: { space?: string }) {
const src = this.resolvePath(name);
async unload(path: string, options?: { space?: string }) {
const src = this.resolvePath(path);
this.log.debug('unloading docs from archive at', src);

const objects = await parseArchive(src);
Expand All @@ -110,8 +112,8 @@ export class KbnClientImportExport {
this.log.success(deleted, 'saved objects deleted');
}

async save(name: string, options: { types: string[]; space?: string }) {
const dest = this.resolvePath(name);
async save(path: string, options: { types: string[]; space?: string }) {
const dest = this.resolvePath(path);
this.log.debug('saving export to', dest);

const resp = await this.req(options.space, {
Expand Down
1 change: 0 additions & 1 deletion test/common/services/kibana_server/kibana_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export function KibanaServerProvider({ getService }: FtrProviderContext): KbnCli
url,
certificateAuthorities: config.get('servers.kibana.certificateAuthorities'),
uiSettingDefaults: defaults,
importExportDir: config.get('kbnArchiver.directory'),
});

if (defaults) {
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_data_grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function ({

before(async function () {
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.uiSettings.replace(defaultSettings);
await PageObjects.common.navigateToApp('discover');
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_data_grid_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('discover data grid context tests', () => {
before(async () => {
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
await kibanaServer.uiSettings.update(defaultSettings);
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_data_grid_doc_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async function () {
log.debug('load kibana index with default index pattern');
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.uiSettings.replace(defaultSettings);
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_data_grid_field_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
this.tags('includeFirefox');
before(async function () {
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
await kibanaServer.uiSettings.update(defaultSettings);
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async function () {
log.debug('load kibana index with default index pattern');

await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
log.info(
`\n### SAVED OBJECT TYPES IN index: [.kibana]: \n\t${await savedObjectInfo.types()}`
);
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_discover_fields_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async function () {
log.debug('load kibana index with default index pattern');
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.uiSettings.replace(defaultSettings);
log.debug('discover');
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_doc_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async function () {
log.debug('load kibana index with default index pattern');
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');

// and load a set of makelogs data
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_field_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
this.tags('includeFirefox');
before(async function () {
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.uiSettings.replace({
defaultIndex: 'logstash-*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
this.tags('includeFirefox');
before(async function () {
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.uiSettings.replace({
defaultIndex: 'logstash-*',
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_filter_editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async function () {
log.debug('load kibana index with default index pattern');
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');

// and load a set of makelogs data
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async () => {
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });

await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
// delete .kibana index and update configDoc
await kibanaServer.uiSettings.replace({
Expand Down
4 changes: 3 additions & 1 deletion test/functional/apps/discover/_large_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async function () {
await security.testUser.setRoles(['kibana_admin', 'kibana_large_strings']);

await kibanaServer.importExport.load('testlargestring');
await kibanaServer.importExport.load(
'test/functional/fixtures/kbn_archiver/testlargestring.json'
);
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/hamlet');
await kibanaServer.uiSettings.replace({
defaultIndex: 'testlargestring',
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_saved_queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async function () {
log.debug('load kibana index with default index pattern');
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');

// and load a set of makelogs data
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/_shared_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

log.debug('load kibana index with default index pattern');
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
await kibanaServer.importExport.load('discover');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');

await kibanaServer.uiSettings.replace({
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function ({ getPageObjects, getService, loadTestFile }: FtrProvid
await browser.setWindowSize(1280, 800);
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/long_window_logstash');
await kibanaServer.importExport.load('visualize');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/visualize.json');
await kibanaServer.uiSettings.replace({
defaultIndex: 'logstash-*',
[UI_SETTINGS.FORMAT_BYTES_DEFAULT_PATTERN]: '0,0.[000]b',
Expand Down
4 changes: 3 additions & 1 deletion test/functional/page_objects/visualize_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class VisualizePageObject extends FtrService {

public async initTests(isNewLibrary = false) {
await this.kibanaServer.savedObjects.clean({ types: ['visualization'] });
await this.kibanaServer.importExport.load('visualize');
await this.kibanaServer.importExport.load(
'test/functional/fixtures/kbn_archiver/visualize.json'
);

await this.kibanaServer.uiSettings.replace({
defaultIndex: 'logstash-*',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ export default ({ getService, getPageObjects }) => {
url: process.env.TEST_KIBANA_URLDATA,
certificateAuthorities: config.get('servers.kibana.certificateAuthorities'),
uiSettingDefaults: kibanaServer.uiSettings,
importExportDir: config.get('kbnArchiver.directory'),
});

const esArchiver = new EsArchiver({
Expand Down

0 comments on commit a23a072

Please sign in to comment.