From ce62fc028d563cb909718eaf89a5e0f4311a12e0 Mon Sep 17 00:00:00 2001 From: marshallmain <55718608+marshallmain@users.noreply.github.com> Date: Thu, 19 Mar 2020 17:01:39 -0400 Subject: [PATCH] [Endpoint] Log random seed for sample data CLI to console (#60646) * log random seed to console * fix off by 1 error with children --- x-pack/plugins/endpoint/common/generate_data.ts | 2 +- x-pack/plugins/endpoint/scripts/resolver_generator.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/endpoint/common/generate_data.ts b/x-pack/plugins/endpoint/common/generate_data.ts index f5ed6da197273..75351bb3bf07d 100644 --- a/x-pack/plugins/endpoint/common/generate_data.ts +++ b/x-pack/plugins/endpoint/common/generate_data.ts @@ -325,7 +325,7 @@ export class EndpointDocGenerator { for (let i = 0; i < generations; i++) { const newParents: EndpointEvent[] = []; parents.forEach(element => { - const numChildren = this.randomN(maxChildrenPerNode); + const numChildren = this.randomN(maxChildrenPerNode + 1); for (let j = 0; j < numChildren; j++) { timestamp = timestamp + 1000; const child = this.generateEvent({ diff --git a/x-pack/plugins/endpoint/scripts/resolver_generator.ts b/x-pack/plugins/endpoint/scripts/resolver_generator.ts index 503999daec587..3d11ccaad005d 100644 --- a/x-pack/plugins/endpoint/scripts/resolver_generator.ts +++ b/x-pack/plugins/endpoint/scripts/resolver_generator.ts @@ -131,8 +131,13 @@ async function main() { process.exit(1); } } - - const generator = new EndpointDocGenerator(argv.seed); + let seed = argv.seed; + if (!seed) { + seed = Math.random().toString(); + // eslint-disable-next-line no-console + console.log('No seed supplied, using random seed: ' + seed); + } + const generator = new EndpointDocGenerator(seed); for (let i = 0; i < argv.numHosts; i++) { await client.index({ index: argv.metadataIndex,