-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Parse duration expressions in accordance with promql #5275
Conversation
pkg/logql/lex.go
Outdated
@@ -240,21 +240,27 @@ func tryScanDuration(number string, l *scanner.Scanner) (time.Duration, bool) { | |||
return 0, false | |||
} | |||
// we've found more characters before a whitespace or the end | |||
d, err := time.ParseDuration(sb.String()) | |||
var duration time.Duration | |||
prometheusDuration, err := model.ParseDuration(sb.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment here explaining why we're doing this would be helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Add a comment to explain why both promql and time's ParseDuration methods are used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I just added a minor nit but other than that, it LGTM!
pkg/logql/lex.go
Outdated
duration = time.Duration(prometheusDuration) | ||
} | ||
|
||
return duration, nil | ||
} | ||
|
||
func isDurationRune(r rune) bool { | ||
// "ns", "us" (or "µs"), "ms", "s", "m", "h". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep this comment in sync with what we have in the switch case. While we are at it, can you please also order it the same manner as the switch case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! Agreed, and done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @SasSwart! LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What this PR does / why we need it:
Add support for promql-like duration units in logql
Which issue(s) this PR fixes:
Fixes #5199
Special notes for your reviewer:
Checklist
CHANGELOG.md
about the changes.