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

[STORY] Add error handling to parseAlphaNumTime #539

Closed
AndrewHess opened this issue Feb 22, 2024 · 6 comments · Fixed by #878
Closed

[STORY] Add error handling to parseAlphaNumTime #539

AndrewHess opened this issue Feb 22, 2024 · 6 comments · Fixed by #878
Assignees
Labels
good first issue Good for newcomers

Comments

@AndrewHess
Copy link
Collaborator

Description

parseAlphaNumTime() is defined in pkg/ast/pipesearch/searchHandler.go. It converts strings like now-1h (meaning one hour before now) to a unix timestamp in milliseconds. However, the code is a little messy and doesn't properly handle invalid cases (e.g., strings like Hello, World!). You should refactor/comment this code to make it more legible and add error handling.

Acceptance Criteria

  • The new version of the function should be easy to understand and return an error if the input values are invalid.
  • Running make pr from the siglens base directory gives no errors
@AndrewHess AndrewHess added the good first issue Good for newcomers label Feb 22, 2024
@abhinavg1997
Copy link

I can pick it up

@nbhavana
Copy link
Collaborator

go ahead

@abhinavg1997
Copy link

abhinavg1997 commented Mar 26, 2024

Hey @AndrewHess , I had a question with respect to checking the length of the input value. While having a check for "less than 6 characters" makes sense, should there be an upper bound check? Based off of the possible values, the highest it can currently go would be 7 characters "now-90d" but that could change in the future.
Moreover I see test cases that are checking for 3 digit values which would fail if we keep a 7 character limit.
Could use your opinion on this

@AndrewHess
Copy link
Collaborator Author

You don't need an upper bound on the length; as long as the string is properly formatted, we should handle it. You could have a check to make sure we don't overflow the return value, but since it's a uint64 and we're returning unix milli time, this shouldn't really ever be an issue unless some of the inputs to the function are very wrong.

Also if you want you can remove/refactor that check for less than 6 characters. That's there because we need at least something like now-1s which has 6 characters, but that's not immediately obvious from just quickly looking at the code, so if there's a cleaner way to handle that check that doesn't have a magic number that could help clean up the code

@gouthamhusky
Copy link
Contributor

Hey @AndrewHess , does this need to be assigned to me to open a PR or can I go ahead?

@nkunal
Copy link
Contributor

nkunal commented May 16, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants