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

Conversation

KhudaDad414
Copy link
Member

@KhudaDad414 KhudaDad414 commented Mar 27, 2024

Description

  • collect the asyncapi file birth timestamp.
  • It will help us track each file for each user over time.

fixes #1225, fixes #1161, fixes partialy #1300

EDIT:
fixes #1300

cc: @Amzani @smoya @peter-rr

@KhudaDad414 KhudaDad414 changed the title feat: add asyncapi file creation timestamp in metrics collection. feat: add asyncapi file birth timestamp in metrics collection. Mar 27, 2024
@KhudaDad414 KhudaDad414 marked this pull request as ready for review March 27, 2024 22:08
src/models/SpecificationFile.ts Outdated Show resolved Hide resolved
@KhudaDad414 KhudaDad414 requested a review from fmvilas April 2, 2024 20:09
@KhudaDad414
Copy link
Member Author

Copy link
Member

@peter-rr peter-rr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

src/base.ts Outdated Show resolved Hide resolved
src/base.ts Outdated
@@ -3,7 +3,7 @@ import { MetadataFromDocument, MetricMetadata, NewRelicSink, Recorder, Sink, Std
import { Parser } from '@asyncapi/parser';
import { Specification } from 'models/SpecificationFile';
import { join, resolve } from 'path';
import { existsSync } from 'fs-extra';
import { existsSync, statSync } from 'fs-extra';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the asynchronous versions of these functions? 🤔 You can easily make setSource an async function and then it would be easy to call await stat() instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working fine with: const stats = await fPromises.stat(specFilePath);
Don't know if there is any better alternative to make setSource an async function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peter-rr I don't think there is any. we either have to use promises and await it. or use Sync functions. which I guess the first option is a lot better.

Copy link
Member

@peter-rr peter-rr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Souvikns
Souvikns previously approved these changes Apr 12, 2024
@Souvikns
Copy link
Member

@fmvilas need your approval to merge this.

src/base.ts Outdated
const stats = await stat(specFilePath);
this.metricsMetadata['file_creation_timestamp'] = stats.birthtimeMs;
} catch (e: any) {
// do nothing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the possible errors we could find here? File doesn't exist maybe? We don't have permission to access the file?

I have the feeling we should control (and report to New Relic) failures here.

Copy link
Member Author

@KhudaDad414 KhudaDad414 Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is ultimately being called from the finally method of the command with a file path, If there is any error with the file, We expect that the current call is actually reporting the error.
(strange sentence, hope it makes sense. 😆 )

clarified the comment in the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question on this topic: if there is an error with the file, is it handled at the catch method as well, apart from the finally method? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peter-rr if by "handled" you mean reporting to New Relic, then it is only being done in finally since it will run regardless of errors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KhudaDad414 @peter-rr It's generally considered best practice to handle errors as close to their source as possible. This helps maintain clear code structure and makes it easier to understand and reason about error handling logic, in this case having some exception type checks under the catch would help.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Amzani this is how I understand the CLI would work when an error happens:

  1. A CLI command is run against an invalid file path, or a file that the user doesn't have read permission etc...
  2. Error is thrown.
  3. catch method will log the error.
  4. finally method will report it to New Relic.

setSouce is being called from the finally method. so the same error that caused the finally method to run will occur again. If the error is already logged and is being reported to New Relic, I am failing to understand why it should be handled and not be ignored here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would need some clarification here: are we all talking about the catch method from the class, or the catch block inside the setSource method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am saying that if there is an error with the file, we expect the command to throw an error, catch method inside the class will log the error, and finally method will report it.

Since The setSource is called from the finally method, it is unnecessary to do anything inside of it's catch block.

If we log it, we have logged it twice, if we initiate a report we have reported it twice.

One time by command trying to access the file and throwing the error and one time by us trying to access it here.

Hope it is clear now.

@Amzani
Copy link
Collaborator

Amzani commented Apr 22, 2024

@KhudaDad414 can you elaborate more on how this will partially solve #1300 thanks

@KhudaDad414
Copy link
Member Author

KhudaDad414 commented Apr 22, 2024

@Amzani the Track Time to First API design in the CLI scope of the issue will be resolved. we already have the Add Time to First API design to Metric dashboard in the dashboard.

so after merging this PR we can close the issue.

Copy link
Collaborator

@Amzani Amzani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@KhudaDad414
Copy link
Member Author

@fmvilas waiting for your review. 🙇‍♂️

Copy link
Collaborator

@Amzani Amzani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Amzani
Copy link
Collaborator

Amzani commented May 14, 2024

/rtm

@asyncapi-bot
Copy link
Contributor

Hello, @Amzani! 👋🏼
This PR is not up to date with the base branch and can't be merged.
Please update your branch manually with the latest version of the base branch.
PRO-TIP: To request an update from the upstream branch, simply comment /u or /update and our bot will handle the update operation promptly.

       The only requirement for this to work is to enable [Allow edits from maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) option in your PR. Also the update will not work if your fork is located in an organization, not under your personal profile.
       Thanks 😄

@asyncapi-bot asyncapi-bot merged commit 254c721 into asyncapi:master May 14, 2024
Copy link

sonarcloud bot commented May 14, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 1.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link
Collaborator

Amzani commented May 14, 2024

/update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
6 participants