Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add asyncapi file birth timestamp in metrics collection. #1304

Merged
merged 25 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ spec-examples.zip
# Coverage for testing

coverage
.asyncapi-analytics

# Analytics

Expand Down
13 changes: 12 additions & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { promises as fPromises } from 'fs';
import { v4 as uuidv4 } from 'uuid';
import { homedir } from 'os';

const { readFile, writeFile } = fPromises;
const { readFile, writeFile, stat } = fPromises;

class DiscardSink implements Sink {
async send() {
Expand Down Expand Up @@ -70,6 +70,7 @@ export default abstract class extends Command {

async recordActionMetric(recordFunc: (recorder: Recorder) => Promise<void>) {
try {
await this.setSource();
await recordFunc(await this.recorder);
await (await this.recorder).flush();
} catch (e: any) {
Expand All @@ -79,6 +80,16 @@ export default abstract class extends Command {
}
}

async setSource() {
const specFilePath = this.specFile?.getFilePath();
if (!specFilePath) { return; }
try {
const stats = await stat(specFilePath);
this.metricsMetadata['file_creation_timestamp'] = stats.birthtimeMs;
} catch (e: any) {
// If there's an error with the file, we don't handle it here because it's expected to be handled and reported in the 'finally' method of the command.
}
}
async finally(error: Error | undefined): Promise<any> {
await super.finally(error);
this.metricsMetadata['success'] = error === undefined;
Expand Down
Loading