From b0b445e2af2767abe6e3c998d90d4bb5837f2a1f Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Wed, 22 Nov 2023 14:32:11 +0100 Subject: [PATCH] Add new metric recording for action invocation --- src/commands/bundle.ts | 12 +++++++++++- src/commands/convert.ts | 12 +++++++++++- src/commands/generate/fromTemplate.ts | 2 +- src/commands/optimize.ts | 12 +++++++++++- src/commands/validate.ts | 12 +++++++++++- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/commands/bundle.ts b/src/commands/bundle.ts index 98d81c464c1..d73c7f9ca47 100644 --- a/src/commands/bundle.ts +++ b/src/commands/bundle.ts @@ -31,6 +31,16 @@ export default class Bundle extends Command { parser = new Parser(); async run() { + try { + // Metrics recording when command is invoked + await this.recorder.recordActionInvoked('bundle'); + await this.recorder.flush(); + } catch (e: any) { + if (e instanceof Error) { + this.log(`Skipping submitting anonymous metrics due to the following error: ${e.name}: ${e.message}`); + } + } + const { argv, flags } = await this.parse(Bundle); const output = flags.output; let baseFile; @@ -87,7 +97,7 @@ export default class Bundle extends Command { const metadata = MetadataFromDocument(document); metadata['success'] = true; metadata['files'] = AsyncAPIFiles.length; - await this.recorder.recordActionExecution('bundle', metadata); + await this.recorder.recordActionExecuted('bundle', metadata); await this.recorder.flush(); } } catch (e: any) { diff --git a/src/commands/convert.ts b/src/commands/convert.ts index d6031844ed1..41a96fb397c 100644 --- a/src/commands/convert.ts +++ b/src/commands/convert.ts @@ -32,6 +32,16 @@ export default class Convert extends Command { parser = new Parser(); async run() { + try { + // Metrics recording when command is invoked + await this.recorder.recordActionInvoked('convert'); + await this.recorder.flush(); + } catch (e: any) { + if (e instanceof Error) { + this.log(`Skipping submitting anonymous metrics due to the following error: ${e.name}: ${e.message}`); + } + } + const { args, flags } = await this.parse(Convert); const filePath = args['spec-file']; let specFile; @@ -83,7 +93,7 @@ export default class Convert extends Command { metadata['from_version'] = document.version(); metadata['to_version'] = flags['target-version']; console.log(metadata); - await this.recorder.recordActionExecution('convert', metadata); + await this.recorder.recordActionExecuted('convert', metadata); await this.recorder.flush(); } } catch (e: any) { diff --git a/src/commands/generate/fromTemplate.ts b/src/commands/generate/fromTemplate.ts index 70a2bf2f0dc..08dcd70d806 100644 --- a/src/commands/generate/fromTemplate.ts +++ b/src/commands/generate/fromTemplate.ts @@ -154,7 +154,7 @@ export default class Template extends Command { const metadata = MetadataFromDocument(document); metadata['success'] = true; metadata['template'] = template; - await this.recorder.recordActionExecution('generate_fromTemplate', metadata); + await this.recorder.recordActionExecuted('generate_fromTemplate', metadata); await this.recorder.flush(); } } catch (e: any) { diff --git a/src/commands/optimize.ts b/src/commands/optimize.ts index 60283f29302..b4c15ce459c 100644 --- a/src/commands/optimize.ts +++ b/src/commands/optimize.ts @@ -50,6 +50,16 @@ export default class Optimize extends Command { parser = new Parser(); async run() { + try { + // Metrics recording when command is invoked + await this.recorder.recordActionInvoked('optimize'); + await this.recorder.flush(); + } catch (e: any) { + if (e instanceof Error) { + this.log(`Skipping submitting anonymous metrics due to the following error: ${e.name}: ${e.message}`); + } + } + const { args, flags } = await this.parse(Optimize); //NOSONAR const filePath = args['spec-file']; let specFile: Specification; @@ -137,7 +147,7 @@ export default class Optimize extends Command { const metadata = MetadataFromDocument(document); metadata['success'] = true; metadata['optimizations'] = this.optimizations; - await this.recorder.recordActionExecution('optimize', metadata); + await this.recorder.recordActionExecuted('optimize', metadata); await this.recorder.flush(); } } catch (e: any) { diff --git a/src/commands/validate.ts b/src/commands/validate.ts index d889671d9b5..737ea2929a0 100644 --- a/src/commands/validate.ts +++ b/src/commands/validate.ts @@ -24,6 +24,16 @@ export default class Validate extends Command { parser = new Parser(); async run() { + try { + // Metrics recording when command is invoked + await this.recorder.recordActionInvoked('validate'); + await this.recorder.flush(); + } catch (e: any) { + if (e instanceof Error) { + this.log(`Skipping submitting anonymous metrics due to the following error: ${e.name}: ${e.message}`); + } + } + const { args, flags } = await this.parse(Validate); //NOSONAR const filePath = args['spec-file']; const watchMode = flags.watch; @@ -42,7 +52,7 @@ export default class Validate extends Command { const metadata = MetadataFromDocument(document); metadata['success'] = true; metadata['validation_result'] = result; - await this.recorder.recordActionExecution('validate', metadata); + await this.recorder.recordActionExecuted('validate', metadata); await this.recorder.flush(); } } catch (e: any) {