[kbn/es] capture es debug files (#132355)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Spencer 2022-05-17 15:23:13 -07:00 committed by GitHub
parent 95a6966e90
commit 63fd2dd552
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 0 deletions

View file

@ -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'

View file

@ -96,12 +96,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",
@ -119,6 +121,7 @@ TYPES_DEPS = [
"@npm//@types/react-redux",
"@npm//@types/react-router-dom",
"@npm//@types/semver",
"@npm//@types/uuid",
"@npm//@types/xml2js",
]

View file

@ -9,6 +9,12 @@
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';
import type { ChildProcess } from 'child_process';
// @ts-expect-error in js
import { Cluster } from '@kbn/es';
import { Client, HttpConnection } from '@elastic/elasticsearch';
@ -42,6 +48,7 @@ interface Node {
start: (installPath: string, opts: Record<string, unknown>) => Promise<void>;
stop: () => Promise<void>;
kill: () => Promise<void>;
_process?: ChildProcess;
}
export interface ICluster {
@ -284,6 +291,51 @@ export function createTestEsCluster<
);
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() {
@ -296,6 +348,7 @@ export function createTestEsCluster<
})
);
await this.captureDebugFiles();
await del(config.installPath, { force: true });
log.info('[es] cleanup complete');
}