Skip to content

Commit

Permalink
[kbn/es] capture es debug files (#132355) (#132381)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 63fd2dd)

# Conflicts:
#	packages/kbn-test/src/es/test_es_cluster.ts
  • Loading branch information
Spencer authored May 18, 2022
1 parent 10dbee1 commit 7ab925b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions .buildkite/scripts/lifecycle/post_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if [[ "$IS_TEST_EXECUTION_STEP" == "true" ]]; then
buildkite-agent artifact upload 'x-pack/test/functional/apps/reporting/reports/session/*.pdf'
buildkite-agent artifact upload 'x-pack/test/functional/failure_debug/html/*.html'
buildkite-agent artifact upload '.es/**/*.hprof'
buildkite-agent artifact upload 'data/es_debug_*.tar.gz'

echo "--- Run Failed Test Reporter"
node scripts/report_failed_tests --build-url="${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}" 'target/junit/**/*.xml'
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ TYPES_DEPS = [
"@npm//form-data",
"@npm//get-port",
"@npm//getopts",
"@npm//globby",
"@npm//jest",
"@npm//jest-cli",
"@npm//jest-snapshot",
"@npm//redux",
"@npm//rxjs",
"@npm//xmlbuilder",
"@npm//@types/archiver",
"@npm//@types/chance",
"@npm//@types/dedent",
"@npm//@types/enzyme",
Expand All @@ -117,6 +119,7 @@ TYPES_DEPS = [
"@npm//@types/react-redux",
"@npm//@types/react-router-dom",
"@npm//@types/semver",
"@npm//@types/uuid",
"@npm//@types/xml2js",
]

Expand Down
50 changes: 50 additions & 0 deletions packages/kbn-test/src/es/test_es_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import Path from 'path';
import { format } from 'url';
import del from 'del';
import Uuid from 'uuid';
import globby from 'globby';
import createArchiver from 'archiver';
import Fs from 'fs';
import { pipeline } from 'stream/promises';
// @ts-expect-error in js
import { Cluster } from '@kbn/es';
import { Client, HttpConnection } from '@elastic/elasticsearch';
Expand Down Expand Up @@ -285,6 +290,51 @@ export function createTestEsCluster<
await Promise.all(nodeStopPromises.map(async (stop) => await stop()));

log.info('[es] stopped');

await this.captureDebugFiles();
}

async captureDebugFiles() {
const debugFiles = await globby([`**/hs_err_pid*.log`, `**/replay_pid*.log`, `**/*.hprof`], {
cwd: config.installPath,
absolute: true,
});

if (!debugFiles.length) {
log.info('[es] no debug files found, assuming es did not write any');
return;
}

const uuid = Uuid.v4();
const debugPath = Path.resolve(KIBANA_ROOT, `data/es_debug_${uuid}.tar.gz`);
log.error(`[es] debug files found, archiving install to ${debugPath}`);
const archiver = createArchiver('tar', { gzip: true });
const promise = pipeline(archiver, Fs.createWriteStream(debugPath));

const archiveDirname = `es_debug_${uuid}`;
for (const name of Fs.readdirSync(config.installPath)) {
if (name === 'modules' || name === 'jdk') {
// drop these large and unnecessary directories
continue;
}

const src = Path.resolve(config.installPath, name);
const dest = Path.join(archiveDirname, name);
const stat = Fs.statSync(src);
if (stat.isDirectory()) {
archiver.directory(src, dest);
} else {
archiver.file(src, { name: dest });
}
}

archiver.finalize();
await promise;

// cleanup the captured debug files
for (const path of debugFiles) {
Fs.rmSync(path, { force: true });
}
}

async cleanup() {
Expand Down

0 comments on commit 7ab925b

Please sign in to comment.