-
Notifications
You must be signed in to change notification settings - Fork 21
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: vector selector yacc rule #7
Conversation
6c121dc
to
56741ff
Compare
56741ff
to
e2d9913
Compare
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.
Splendid! I look roughly at the .y
part, which generally looks good to me. And left a few comments in other parts.
c51db71
to
5c66a88
Compare
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 👍
src/util/duration.rs
Outdated
"1", "1y1m1d", "-1w", "1.5d", "d", | ||
"", | ||
// these are invalid in PromQL Go Version | ||
// "294y", "200y10400w", "107675d", "2584200h", |
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.
We can un-comment this in another test, and assert they are valid in our version I suspose
src/util/duration.rs
Outdated
let v = cap.as_str().parse::<u64>().unwrap(); | ||
result = result + Duration::from_millis(v * millis); |
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.
If want to be corrected with any input, I suggest to use checked_add
for result + Duration
and checked_mul
for v * millis
. Because if it will overflow, it overflows here. So I'm afraid the check below (if result > Duration::MAX
) is logically unreachable.
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.
Yes, It's idiomatic Rust way
MatchType::MatchNotEqual => self.value.ne(s), | ||
MatchType::MatchRegexp => todo!(), | ||
MatchType::MatchNotRegexp => todo!(), | ||
pub fn new_matcher(token: Token, name: String, value: String) -> Result<Matcher, 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.
We may need to define an Error type for the parser instead of using 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.
We can file a todo issue for this. I think we can leave them as are for now (i.e. keep using String). Parser error is a bit complex problem because it's part of an important user-facing UI, and we need to consider how to make it accurate and understandable.
T_EQL => Ok(Matcher::new(MatchOp::Equal, name, value)), | ||
T_NEQ => Ok(Matcher::new(MatchOp::NotEqual, name, value)), | ||
T_EQL_REGEX => { | ||
let re = Regex::new(&value).map_err(|_| format!("illegal regex for {}", &value))?; |
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.
Also display the source error in the error message? It might contains some helpful message.
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.
The error mechanism will be carefully re-designed in the future in Issue #9
src/util/duration.rs
Outdated
] | ||
.into_iter() | ||
// map captured string to Option<Duration> iterator | ||
// FIXME: None is ignored in closure. It is better to tell users which part is wrong. |
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 leave a FIXME here to resolve the issue in the future.
8f1ac97
to
388d4b9
Compare
I almost redo duration.rs. Any review comment is welcome. |
388d4b9
to
13c1e37
Compare
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's Included
Sorry but this is a huge PR, the whole purpose of this PR is to show how to use grmtools and *.y file to generate PromQL parser.
Example
cargo run --example parser
What's to do next