Skip to content
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
5 changes: 4 additions & 1 deletion packages/kbn-dev-utils/src/tooling_log/tooling_log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export class ToolingLog {
* @param delta the number of spaces to increase/decrease the indentation
* @param block a function to run and reset any indentation changes after
*/
public indent<T>(delta = 0, block?: () => Promise<T>) {
public indent(delta: number): undefined;
public indent<T>(delta: number, block: () => Promise<T>): Promise<T>;
public indent<T>(delta: number, block: () => T): T;
public indent<T>(delta = 0, block?: () => T | Promise<T>) {
const originalWidth = this.indentWidth$.getValue();
this.indentWidth$.next(Math.max(originalWidth + delta, 0));
if (!block) {
Expand Down
47 changes: 23 additions & 24 deletions packages/kbn-es/src/cli_commands/build_snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,31 @@ exports.run = async (defaults = {}) => {
for (const license of ['oss', 'trial']) {
for (const platform of ['darwin', 'win32', 'linux']) {
log.info('Building', platform, license === 'trial' ? 'default' : 'oss', 'snapshot');
log.indent(4);
await log.indent(4, async () => {
const snapshotPath = await buildSnapshot({
license,
sourcePath: options.sourcePath,
log,
platform,
});

const snapshotPath = await buildSnapshot({
license,
sourcePath: options.sourcePath,
log,
platform,
});

const filename = basename(snapshotPath);
const outputPath = resolve(outputDir, filename);
const hash = createHash('sha512');
await pipelineAsync(
Fs.createReadStream(snapshotPath),
new Transform({
transform(chunk, _, cb) {
hash.update(chunk);
cb(undefined, chunk);
},
}),
Fs.createWriteStream(outputPath)
);
const filename = basename(snapshotPath);
const outputPath = resolve(outputDir, filename);
const hash = createHash('sha512');
await pipelineAsync(
Fs.createReadStream(snapshotPath),
new Transform({
transform(chunk, _, cb) {
hash.update(chunk);
cb(undefined, chunk);
},
}),
Fs.createWriteStream(outputPath)
);

Fs.writeFileSync(`${outputPath}.sha512`, `${hash.digest('hex')} ${filename}`);
log.success('snapshot and shasum written to', outputPath);
log.indent(-4);
Fs.writeFileSync(`${outputPath}.sha512`, `${hash.digest('hex')} ${filename}`);
log.success('snapshot and shasum written to', outputPath);
});
}
}
};
135 changes: 65 additions & 70 deletions packages/kbn-es/src/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ exports.Cluster = class Cluster {
*/
async installSource(options = {}) {
this._log.info(chalk.bold('Installing from source'));
this._log.indent(4);

const { installPath } = await installSource({ log: this._log, ...options });

this._log.indent(-4);

return { installPath };
return await this._log.indent(4, async () => {
const { installPath } = await installSource({ log: this._log, ...options });
return { installPath };
});
}

/**
Expand All @@ -78,16 +75,14 @@ exports.Cluster = class Cluster {
*/
async downloadSnapshot(options = {}) {
this._log.info(chalk.bold('Downloading snapshot'));
this._log.indent(4);
return await this._log.indent(4, async () => {
const { installPath } = await downloadSnapshot({
log: this._log,
...options,
});

const { installPath } = await downloadSnapshot({
log: this._log,
...options,
return { installPath };
});

this._log.indent(-4);

return { installPath };
}

/**
Expand All @@ -100,16 +95,14 @@ exports.Cluster = class Cluster {
*/
async installSnapshot(options = {}) {
this._log.info(chalk.bold('Installing from snapshot'));
this._log.indent(4);
return await this._log.indent(4, async () => {
const { installPath } = await installSnapshot({
log: this._log,
...options,
});

const { installPath } = await installSnapshot({
log: this._log,
...options,
return { installPath };
});

this._log.indent(-4);

return { installPath };
}

/**
Expand All @@ -122,16 +115,14 @@ exports.Cluster = class Cluster {
*/
async installArchive(path, options = {}) {
this._log.info(chalk.bold('Installing from an archive'));
this._log.indent(4);
return await this._log.indent(4, async () => {
const { installPath } = await installArchive(path, {
log: this._log,
...options,
});

const { installPath } = await installArchive(path, {
log: this._log,
...options,
return { installPath };
});

this._log.indent(-4);

return { installPath };
}

/**
Expand All @@ -144,21 +135,19 @@ exports.Cluster = class Cluster {
*/
async extractDataDirectory(installPath, archivePath, extractDirName = 'data') {
this._log.info(chalk.bold(`Extracting data directory`));
this._log.indent(4);

// stripComponents=1 excludes the root directory as that is how our archives are
// structured. This works in our favor as we can explicitly extract into the data dir
const extractPath = path.resolve(installPath, extractDirName);
this._log.info(`Data archive: ${archivePath}`);
this._log.info(`Extract path: ${extractPath}`);

await extract({
archivePath,
targetDir: extractPath,
stripComponents: 1,
await this._log.indent(4, async () => {
// stripComponents=1 excludes the root directory as that is how our archives are
// structured. This works in our favor as we can explicitly extract into the data dir
const extractPath = path.resolve(installPath, extractDirName);
this._log.info(`Data archive: ${archivePath}`);
this._log.info(`Extract path: ${extractPath}`);

await extract({
archivePath,
targetDir: extractPath,
stripComponents: 1,
});
});

this._log.indent(-4);
}

/**
Expand All @@ -169,24 +158,27 @@ exports.Cluster = class Cluster {
* @returns {Promise<void>}
*/
async start(installPath, options = {}) {
this._exec(installPath, options);

await Promise.race([
// wait for native realm to be setup and es to be started
Promise.all([
first(this._process.stdout, (data) => {
if (/started/.test(data)) {
return true;
}
}),
this._setupPromise,
]),
// _exec indents and we wait for our own end condition, so reset the indent level to it's current state after we're done waiting
await this._log.indent(0, async () => {
this._exec(installPath, options);

await Promise.race([
// wait for native realm to be setup and es to be started
Promise.all([
first(this._process.stdout, (data) => {
if (/started/.test(data)) {
return true;
}
}),
this._setupPromise,
]),

// await the outcome of the process in case it exits before starting
this._outcome.then(() => {
throw createCliError('ES exited without starting');
}),
]);
// await the outcome of the process in case it exits before starting
this._outcome.then(() => {
throw createCliError('ES exited without starting');
}),
]);
});
}

/**
Expand All @@ -197,16 +189,19 @@ exports.Cluster = class Cluster {
* @returns {Promise<void>}
*/
async run(installPath, options = {}) {
this._exec(installPath, options);
// _exec indents and we wait for our own end condition, so reset the indent level to it's current state after we're done waiting
await this._log.indent(0, async () => {
this._exec(installPath, options);

// log native realm setup errors so they aren't uncaught
this._setupPromise.catch((error) => {
this._log.error(error);
this.stop();
});

// log native realm setup errors so they aren't uncaught
this._setupPromise.catch((error) => {
this._log.error(error);
this.stop();
// await the final outcome of the process
await this._outcome;
});

// await the final outcome of the process
await this._outcome;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions packages/kbn-optimizer/src/log_optimizer_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ export function logOptimizerState(log: ToolingLog, config: OptimizerConfig) {

if (state.phase === 'issue') {
log.error(`webpack compile errors`);
log.indent(4);
for (const b of state.compilerStates) {
if (b.type === 'compiler issue') {
log.error(`[${b.bundleId}] build`);
log.indent(4);
log.error(b.failure);
log.indent(-4);
log.indent(4, () => {
for (const b of state.compilerStates) {
if (b.type === 'compiler issue') {
log.error(`[${b.bundleId}] build`);
log.indent(4, () => {
log.error(b.failure);
});
}
}
}
log.indent(-4);
});
return;
}

Expand Down
41 changes: 20 additions & 21 deletions packages/kbn-plugin-helpers/src/tasks/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@ export async function optimize({ log, plugin, sourceDir, buildDir }: BuildContex
}

log.info('running @kbn/optimizer');
log.indent(2);

// build bundles into target
const config = OptimizerConfig.create({
repoRoot: REPO_ROOT,
pluginPaths: [sourceDir],
cache: false,
dist: true,
filter: [plugin.manifest.id],
await log.indent(2, async () => {
// build bundles into target
const config = OptimizerConfig.create({
repoRoot: REPO_ROOT,
pluginPaths: [sourceDir],
cache: false,
dist: true,
filter: [plugin.manifest.id],
});

const target = Path.resolve(sourceDir, 'target');

await runOptimizer(config).pipe(logOptimizerState(log, config)).toPromise();

// clean up unnecessary files
Fs.unlinkSync(Path.resolve(target, 'public/metrics.json'));
Fs.unlinkSync(Path.resolve(target, 'public/.kbn-optimizer-cache'));

// move target into buildDir
await asyncRename(target, Path.resolve(buildDir, 'target'));
});

const target = Path.resolve(sourceDir, 'target');

await runOptimizer(config).pipe(logOptimizerState(log, config)).toPromise();

// clean up unnecessary files
Fs.unlinkSync(Path.resolve(target, 'public/metrics.json'));
Fs.unlinkSync(Path.resolve(target, 'public/.kbn-optimizer-cache'));

// move target into buildDir
await asyncRename(target, Path.resolve(buildDir, 'target'));
log.indent(-2);
}
6 changes: 0 additions & 6 deletions src/core/test_helpers/kbn_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,13 @@ export function createTestServers({
writeTo: process.stdout,
});

log.indent(6);
log.info('starting elasticsearch');
log.indent(4);

const es = createTestEsCluster(
defaultsDeep({}, settings.es ?? {}, {
log,
license,
})
);

log.indent(-4);

// Add time for KBN and adding users
adjustTimeout(es.getStartTimeout() + 100000);

Expand Down
Loading