-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
allows more flexible timelion queries #10961
Conversation
Not support whitespace anymore is going to be a problem for existing saved expressions, no? Unless there was some sort of in-place shim to support whitespace, this is a backwards compatibility break, and something we should consider an upgrade path for for 6.0. Why is this a blocker, by the way? |
@epixa This is a blocker for multi-line expressions (#8881), because multi-line expressions require whitespace. However, whitespace is currently interpreted as a delimiter between expressions. So, we need to remove this interpretation of whitespace, to allow for its use strictly as an organizational tool. This is definitely a BWC break (as noted in #10907), but the use of whitespace as a delimiter isn't documented anywhere, so it's possible that not many people use it for that purpose. My suggestion is to display a warning to the user about the change and suggest using semicolons or commas to delimit expressions as a fix. We can delay to 6.0 if you want. |
Assuming I understand you correctly, I think that's a good plan. Show deprecation notices for missing commas in 5.4, and remove their support entirely in 6.0. If that complicates this feature, then just ship this feature in 6.0. |
i could catch the error thrown by parser and in case of what do you think ? good enough ? |
@ppisljar I don't understand why we'd need to catch the error. We would just need to identify when a space is used between two expressions and show a deprecation notice. This PR would then only go into 6.0. |
Correct me if I'm wrong @ppisljar, but I think the reason we need to catch the error is because we don't know when a space is used between two expressions, or between two functions in a single expression, or in a query to ES. So we need to rely on PEG's parsing of the expression to know if an expression is invalid (possibly due to our BWC breaking change). If this understanding is correct, then I think we should show our deprecation notice when the error is thrown. It's OK if this error is thrown and we show the notice, even if the error is thrown due to some reason other than this change. We can play with the wording of the notice so that it still makes sense. But this error needs to be reliably thrown in all scenarios where this change creates an invalid expression or changes the meaning of an expression. |
@ppisljar Can you add tests for this to verify which expressions are accepted and which throw errors?
|
@cjcenizal thats correct, regarding the parsing. I'll start adding tests. |
Get rid of the semi-colon support. It add complication and ambiguity. Part of the reason for getting rid of whitespace delineation was to remove ambiguity, no reason to re-introduce it. |
The pull description says this executes correctly:
If that is true, then this is a bug, colons are not an acceptable argument assignment character. Some functions implement them for the purpose of string splitting, but they are not part of the grammar and shouldn't be. |
Given that the purpose of #10907 is to make possible multi-line expressions, this would be a good time to introduce newlines and carriage returns as acceptable whitespace characters into the grammar. See here: elastic/timelion@5b21a86#diff-cad677e1524a089d5994bbffedf06119 |
@rashidkpc the min:10 doesn't actually work, but it doesn't throw an error either. however its not related to this PR. i added the semicolon just to see what are the opinions on it ... i would prefer a semicolon there if we introduce the multiline editor ...
vs
|
The semi-colon has no additional function over the comma. We should be making the expressions less ambiguous, not more. Also, in your previous example, if that trailing comma is required, I'd consider that a bug. |
@ppisljar If you feel strongly about the semi-colons, can we introduce and debate their merits in a separate PR? |
@ppisljar This should throw an error if we're requiring comma delimiting as spaces aren't valid in unquoted strings. Currently its parsed as 3 arguments.
For example:
|
a450134
to
15327c8
Compare
i removed the semicolon support and added new line support yeah comma at the end is necessary in this version ... i have no idea how to make comma in the middle a must but comma at the end optional ... if you feel like doing this feel free to submit another PR and close this one. |
I removed the |
timezone: 'Europe/Berlin' | ||
} | ||
}; | ||
return await Promise.all(chainRunner.processRequest(request)); |
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.
This doesn't belong in this file, as it is testing the interpreter. You want to test that the grammar is generating a parser that is producing the expected AST
This will make the tests run faster, as well as make the tests more useful to the reader by conveying that we are only testing the parser.
This will also keep you from having to mock the time
property.
const data = ['.es() .es(404)']; | ||
expect(function () { | ||
parse(data); | ||
}).to.throw(); |
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.
You shouldn't be calling up the interpreter to test this, rather get the properties on the AST. I explain the differences in the generated AST here:
I should've been more specific in that comment. While interpreter tests would be nice the goal of this pull is only related to parsing and the tests should be testing the parser aspect.
Removed the 5.4.0 label, since this pull involves a breaking change in syntax (commas to be required, whereas previously they were optional). Seems like the kind of change we should be introducing in a major release, rather than minor. With 6.0 alphas around the corner, I'd recommend we target it to one of those. |
This make commas requires between arguments and series, but optional at end of either. It would be simple to drop the ','? at the end of each of `arg_list` and `series` if you wanted to require the commas *not* be present.
3c6ce80
to
231b6d4
Compare
jenkins, test this |
@@ -21,7 +21,7 @@ | |||
} | |||
|
|||
start | |||
= tree:series+ { |
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.
any reason why this is removed? Don't entirely see the relation with the other changes.
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.
series now return an array see here
|
||
const expect = require('chai').expect; | ||
|
||
describe('timelion parse_sheet function', function () { |
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 should add tests for the change in white-space behavior too (not just for the new comma-separated behavior).
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 do test for the white space behavior in the test below (it should not be allowed)
or do you mean testing that \n and \r are also accepted as white space ?
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, test that \n and \r are now accepted.
but not sure if we already have tests in place. if not, this could be a separate effort.
|
||
group | ||
= '(' space? grouped:series+ space? ')' functions:function* { |
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.
dito
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.
dito :)
@rashidkpc do you want to take another look ? |
LGTM |
A quick note: white space before the '.' will cause autocomplete to not trigger. Probably not a deal breaker as implementing the multi-line editor will require a reboot of the auto completion system anyway. |
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.
Awesome! Just had a small suggestion.
expect(ast[0][0].type).to.equal('chain'); | ||
expect(ast[0][1].type).to.equal('chain'); | ||
}); | ||
}); |
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 was a little confused by the use of "allow" and "does not allow" in the test descriptions, because I assumed we'd be throwing errors or somehow preventing disallowed input. After I dug into the tests, I realized this was an incorrect assumption. I think it will be a little clearer if we describe the behavior as either "splitting expressions" or "not splitting expressions". Thoughts?
Because I'm not familiar with the structure of the generated AST, I also found it useful to break out the part of the object that represents the list of expressions into a variable, to increase readability.
const parseSheet = require('../lib/parse_sheet');
const expect = require('chai').expect;
describe('timelion parse_sheet function', function () {
it(`doesn't split expressions on whitespace`, async function () {
const data = ['.es() .es(404)'];
const ast = parseSheet(data);
const expressions = ast[0];
expect(expressions.length).to.equal(1);
expect(expressions[0].type).to.equal('chain');
});]
it('splits expressions on commas', function () {
const data = ['.es(), .es(404)'];
const ast = parseSheet(data);
const expressions = ast[0];
expect(expressions.length).to.equal(2);
expect(expressions[0].type).to.equal('chain');
expect(expressions[1].type).to.equal('chain');
});
it('splits expressions on newlines', function () {
const data = [`.es()\n\r ,\n\r .es(404)`];
const ast = parseSheet(data);
const expressions = ast[0];
expect(expressions.length).to.equal(2);
expect(expressions[0].type).to.equal('chain');
expect(expressions[1].type).to.equal('chain');
});
});
@ppisljar I'm not sure where this landed - is it still a breaking change? If so, can you please update the breaking change docs for 6.0 with details? |
@epixa thanks for the reminder! it landed in 6.0 |
fixes #10907
allows more flexible usage of whitespace in timelion queries.
this query now executes well:
adds the option to use
;
instead of,
but makes one of the separators obligatory (just white space is not allowed any more)