Skip to content

Commit

Permalink
feat: add POC for measuring adoption
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya committed Nov 22, 2023
1 parent 5ba5946 commit 9952df2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
21 changes: 15 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@oclif/core": "^1.26.2",
"@oclif/errors": "^1.3.6",
"@oclif/plugin-not-found": "^2.3.22",
"@smoya/asyncapi-adoption-metrics": "^1.1.1",
"@smoya/multi-parser": "^4.0.0",
"@stoplight/spectral-cli": "6.9.0",
"ajv": "^8.12.0",
Expand Down
3 changes: 3 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Command } from '@oclif/core';
import { Recorder, StdOutSink } from '@smoya/asyncapi-adoption-metrics';

export default abstract class extends Command {
recorder = new Recorder('asyncapi-adoption', new StdOutSink());

async catch(err: Error & { exitCode?: number; }): Promise<any> {
try {
return await super.catch(err);
Expand Down
22 changes: 21 additions & 1 deletion src/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { validate, validationFlags } from '../parser';
import { load } from '../models/SpecificationFile';
import { specWatcher } from '../globals';
import { watchFlag } from '../flags';
import { MetadataFromDocument } from '@smoya/asyncapi-adoption-metrics';
import { Parser } from '@asyncapi/parser';

export default class Validate extends Command {
static description = 'validate asyncapi file';
Expand All @@ -19,6 +21,8 @@ export default class Validate extends Command {
{ name: 'spec-file', description: 'spec path, url, or context-name', required: false },
];

parser = new Parser();

async run() {
const { args, flags } = await this.parse(Validate); //NOSONAR
const filePath = args['spec-file'];
Expand All @@ -29,6 +33,22 @@ export default class Validate extends Command {
specWatcher({ spec: specFile, handler: this, handlerName: 'validate' });
}

await validate(this, specFile, flags);
const result = await validate(this, specFile, flags);

try {
// Metrics recording.
const {document} = await this.parser.parse(specFile.text());
if (document !== undefined) {
const metadata = MetadataFromDocument(document);
metadata['success'] = true;
metadata['validation_result'] = result;
await this.recorder.recordActionExecution('validate', metadata);
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}`);
}
}
}
}

0 comments on commit 9952df2

Please sign in to comment.