Skip to content

Commit

Permalink
Add new method to unify logic so metrics are collected when any comma…
Browse files Browse the repository at this point in the history
…nd is invoked
  • Loading branch information
peter-rr committed Nov 28, 2023
1 parent 2fd9762 commit b905366
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { Command } from '@oclif/core';
import { MetadataFromDocument, MetricMetadata, NewRelicSink, Recorder, Sink, StdOutSink } from '@smoya/asyncapi-adoption-metrics';
import { Parser } from '@asyncapi/parser';

/* export type Flags<T extends typeof Command> = Interfaces.InferredFlags<typeof BaseCommand['baseFlags'] & T['flags']>
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>
export interface CommandInterface extends Command.Class {
configurationVariablesSection?: HelpSection;
envVariablesSection?: HelpSection;
errorCodes?: HelpSection;
}
*/

class DiscardSink implements Sink {
async send() {
// noop
Expand Down Expand Up @@ -62,6 +72,11 @@ export default abstract class extends Command {
}
}
}

public async init(): Promise<void> {
await super.init();
await this.recordActionInvoked(Command.id);
}
}

function recorderFromEnv(prefix: string): Recorder {
Expand All @@ -77,7 +92,7 @@ function recorderFromEnv(prefix: string): Recorder {
break;
case 'production':
// NODE_ENV set to `production` in bin/run_bin, which is specified in 'bin' package.json section
sink = new NewRelicSink('eu01xx73a8521047150dd9414f6aedd2FFFFNRAL');
sink = new NewRelicSink('eu01xxcdd37dabf88558212c92c3199aFFFFNRAL');
break;
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { validate, validationFlags } from '../parser';
import { load } from '../models/SpecificationFile';
import { specWatcher } from '../globals';
import { watchFlag } from '../flags';
import { stringify } from 'querystring';

export default class Validate extends Command {
static description = 'validate asyncapi file';
Expand All @@ -20,9 +21,6 @@ export default class Validate extends Command {
];

async run() {
// Metrics recording when command is invoked
await this.recordActionInvoked('validate');

const { args, flags } = await this.parse(Validate); //NOSONAR
const filePath = args['spec-file'];
const watchMode = flags.watch;
Expand Down

0 comments on commit b905366

Please sign in to comment.