Skip to content

Commit

Permalink
[synthtrace] Add usage examples and available options (#172833)
Browse files Browse the repository at this point in the history
## Summary

Minor DX improvements to `synthtrace` CLI:
- Added list of available scenarios
- Added list of available log levels
- Added usage examples

## Screenshot

<img width="993" alt="Screenshot 2023-12-07 at 14 46 31"
src="https://github.com/elastic/kibana/assets/190132/c0d3623f-0b0f-420d-9f6f-5d013494658f">
  • Loading branch information
thomheymann authored Dec 12, 2023
1 parent 6b6008b commit 508762e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/kbn-apm-synthtrace/src/cli/run_synthtrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@
import datemath from '@kbn/datemath';
import { Argv } from 'yargs';
import yargs from 'yargs/yargs';
import { readdirSync } from 'fs';
import path from 'path';
import { intervalToMs } from './utils/interval_to_ms';
import { parseRunCliFlags } from './utils/parse_run_cli_flags';
import { startHistoricalDataUpload } from './utils/start_historical_data_upload';
import { startLiveDataUpload } from './utils/start_live_data_upload';

function getBuiltinScenarios() {
return readdirSync(path.resolve(__dirname, '../scenarios')).map((s) => s.replace(/\.ts$/, ''));
}

function options(y: Argv) {
return y
.usage('$0 <file>')
.positional('file', {
describe: 'File that contains the trace scenario',
describe: 'Name of scenario',
demandOption: true,
string: true,
choices: getBuiltinScenarios(),
})
.option('target', {
describe: 'Elasticsearch target',
Expand Down Expand Up @@ -54,6 +62,7 @@ function options(y: Argv) {
})
.option('logLevel', {
describe: 'Log level',
choices: ['trace', 'debug', 'info', 'error'],
default: 'info',
})
.option('scenarioOpts', {
Expand All @@ -66,7 +75,14 @@ function options(y: Argv) {
describe: 'Assumes passed package version to avoid calling Fleet API to install',
string: true,
})
.showHelpOnFail(false);
.example(
'$0 simple_logs --target=http://admin:changeme@localhost:9200',
'Ingest data to specific Elasticsearch cluster'
)
.example('$0 simple_logs --live', 'Continuously ingest data to local development cluster')
.example('$0 simple_logs --from=now-24h --to=now', 'Ingest data for a fixed time window')
.showHelpOnFail(false)
.wrap(null);
}

async function run(argv: RunCliFlags) {
Expand Down

0 comments on commit 508762e

Please sign in to comment.