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

Parse duration expressions in accordance with promql #5275

Merged
merged 6 commits into from
Feb 22, 2022

Conversation

SasSwart
Copy link
Contributor

@SasSwart SasSwart commented Jan 30, 2022

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

  • Documentation added
  • Tests updated
  • Add an entry in the CHANGELOG.md about the changes.

@pull-request-size pull-request-size bot added size/S and removed size/L labels Feb 20, 2022
@SasSwart SasSwart marked this pull request as ready for review February 20, 2022 15:43
@SasSwart SasSwart requested a review from a team as a code owner February 20, 2022 15:43
@SasSwart SasSwart changed the title WIP: Parse duration expressions in accordance with promql Parse duration expressions in accordance with promql Feb 20, 2022
pkg/logql/ast_test.go Show resolved Hide resolved
pkg/logql/lex.go Outdated Show resolved Hide resolved
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())
Copy link
Contributor

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

Copy link
Contributor Author

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
@pull-request-size pull-request-size bot added size/M and removed size/S labels Feb 20, 2022
Copy link
Contributor

@sandeepsukhani sandeepsukhani left a 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".
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@dannykopping dannykopping left a 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

Copy link
Contributor

@sandeepsukhani sandeepsukhani left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

d (day) and w (week) argument doesn't work with offset modifier
3 participants