[APM] Fix Synthtrace script (#133620)

This commit is contained in:
Søren Louv-Jansen 2022-06-08 18:24:04 +02:00 committed by GitHub
parent 56f2c1cc9e
commit 702aa29e56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 108 deletions

View file

@ -14,4 +14,4 @@ require('@babel/register')({
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'], presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
}); });
require('../src/scripts/run_synthtrace'); require('../src/scripts/run_synthtrace').runSynthtrace();

View file

@ -3,6 +3,9 @@
"version": "0.1.0", "version": "0.1.0",
"description": "Elastic APM trace data generator", "description": "Elastic APM trace data generator",
"license": "SSPL-1.0 OR Elastic License 2.0", "license": "SSPL-1.0 OR Elastic License 2.0",
"bin": {
"synthtrace": "./bin/synthtrace"
},
"main": "./target_node/index.js", "main": "./target_node/index.js",
"private": true "private": true
} }

View file

@ -6,6 +6,7 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
export { runSynthtrace } from './scripts/run_synthtrace';
export { timerange } from './lib/timerange'; export { timerange } from './lib/timerange';
export { apm } from './lib/apm'; export { apm } from './lib/apm';
export { stackMonitoring } from './lib/stack_monitoring'; export { stackMonitoring } from './lib/stack_monitoring';

View file

@ -124,6 +124,7 @@ function options(y: Argv) {
export type RunCliFlags = ReturnType<typeof options>['argv']; export type RunCliFlags = ReturnType<typeof options>['argv'];
export function runSynthtrace() {
yargs(process.argv.slice(2)) yargs(process.argv.slice(2))
.command( .command(
'*', '*',
@ -238,3 +239,4 @@ yargs(process.argv.slice(2))
} }
) )
.parse(); .parse();
}

View file

@ -20,15 +20,18 @@ function getParsedFile(flags: RunCliFlags) {
throw new Error('Please specify a scenario to run'); throw new Error('Please specify a scenario to run');
} }
const result = [ const filepath = [
path.resolve(parsedFile), path.resolve(parsedFile),
path.resolve(`${parsedFile}.ts`), path.resolve(`${parsedFile}.ts`),
path.resolve(__dirname, '../../scenarios', parsedFile), path.resolve(__dirname, '../../scenarios', parsedFile),
path.resolve(__dirname, '../../scenarios', `${parsedFile}.ts`), path.resolve(__dirname, '../../scenarios', `${parsedFile}.ts`),
].find((filepath) => existsSync(filepath)); path.resolve(__dirname, '../../scenarios', `${parsedFile}.js`),
].find((p) => existsSync(p));
if (result) { if (filepath) {
return result; // eslint-disable-next-line no-console
console.log(`Loading scenario from ${filepath}`);
return filepath;
} }
throw new Error(`Could not find scenario file: "${parsedFile}"`); throw new Error(`Could not find scenario file: "${parsedFile}"`);

View file

@ -6,5 +6,11 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
require('../src/setup_node_env/node_version_validator'); require('../src/setup_node_env');
require('@elastic/apm-synthtrace/bin/synthtrace');
// We have to import directly from package since scenarios and worker.js are imported dynamically,
// If we import the package (require('@elastic/apm-synthtrace')) the program will be executed on the compiled files, and thus we need to
// compile scenarios with `yarn kbn bootstrap` every time scenario changes.
// eslint-disable-next-line @kbn/imports/uniform_imports
require('../packages/elastic-apm-synthtrace/src/index').runSynthtrace();