Skip to content

Commit

Permalink
Add new metric recording for action invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-rr committed Nov 22, 2023
1 parent c9027b5 commit b0b445e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 11 additions & 1 deletion src/commands/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate/fromTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 11 additions & 1 deletion src/commands/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 11 additions & 1 deletion src/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit b0b445e

Please sign in to comment.