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 Oct 23, 2023
1 parent 1ed8940 commit a3909e4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
23 changes: 16 additions & 7 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
"@asyncapi/modelina": "^1.9.1",
"@asyncapi/openapi-schema-parser": "^3.0.5",
"@asyncapi/optimizer": "^0.2.1",
"@asyncapi/parser": "^3.0.0-next-major-spec.2",
"@asyncapi/parser": "^3.0.0-next-major-spec.3",
"@asyncapi/protobuf-schema-parser": "3.0.0",
"@asyncapi/raml-dt-schema-parser": "^4.0.3",
"@asyncapi/studio": "^0.17.3",
"@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 a3909e4

Please sign in to comment.