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

allows more flexible timelion queries #10961

Merged
merged 10 commits into from
Apr 28, 2017

Conversation

ppisljar
Copy link
Member

fixes #10907

allows more flexible usage of whitespace in timelion queries.

this query now executes well:

.es     (    404  )   .yaxis  (   min   :   10   ) ;                 .es(*)      .yaxis    (    2 ,   min   =   10   )   ,  .es( 500)  

adds the option to use ; instead of , but makes one of the separators obligatory (just white space is not allowed any more)

@ppisljar ppisljar added Feature:Timelion Timelion app and visualization Feature:Visualizations Generic visualization features (in case no more specific feature label is available) review v5.4.0 v6.0.0 labels Mar 30, 2017
@epixa
Copy link
Contributor

epixa commented Mar 30, 2017

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?

@cjcenizal
Copy link
Contributor

@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.

@epixa
Copy link
Contributor

epixa commented Mar 30, 2017

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.

@ppisljar
Copy link
Member Author

ppisljar commented Mar 31, 2017

i could catch the error thrown by parser and in case of Error Timelion: Error: in cell #1: metric.split is not a function show the deprecation warning.
but i have no way of telling if this same error is also thrown in some other scenarios.

what do you think ? good enough ?

@epixa
Copy link
Contributor

epixa commented Mar 31, 2017

@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.

@cjcenizal
Copy link
Contributor

cjcenizal commented Mar 31, 2017

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.

@cjcenizal
Copy link
Contributor

cjcenizal commented Mar 31, 2017

@ppisljar Can you add tests for this to verify which expressions are accepted and which throw errors?

  • whitespace used between two expressions
  • whitespace between two functions in a single expression
  • whitespace in a query to ES
  • semicolon-delimited expressions (ignore this, per @rashidkpc's suggestion)
  • comma-delimited expressions
  • any other variations you can think of

@ppisljar
Copy link
Member Author

@cjcenizal thats correct, regarding the parsing. I'll start adding tests.

@rashidkpc
Copy link
Contributor

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.

@rashidkpc
Copy link
Contributor

The pull description says this executes correctly:

.es     (    404  )   .yaxis  (   min   :   10   ) ; 

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.

@rashidkpc
Copy link
Contributor

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

@ppisljar
Copy link
Member Author

ppisljar commented Apr 3, 2017

@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 ...

.es(*)
  .yaxis(1);

.es(404)
  .yaxis(2);

vs

.es(*)
  .yaxis(1),

.es(404)
  .yaxis(2),

@rashidkpc
Copy link
Contributor

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.

@cjcenizal
Copy link
Contributor

@ppisljar If you feel strongly about the semi-colons, can we introduce and debate their merits in a separate PR?

@rashidkpc
Copy link
Contributor

rashidkpc commented Apr 3, 2017

@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.

.yaxis  (   min   :   10   )

For example:

.es(
  q = html,
  index = logstash*
)

@thomasneirynck thomasneirynck self-requested a review April 5, 2017 01:02
@thomasneirynck thomasneirynck removed their assignment Apr 5, 2017
@rashidkpc rashidkpc self-requested a review April 5, 2017 16:47
@rashidkpc rashidkpc removed their assignment Apr 5, 2017
@ppisljar
Copy link
Member Author

ppisljar commented Apr 6, 2017

i removed the semicolon support and added new line support

@rashidkpc

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.

@epixa
Copy link
Contributor

epixa commented Apr 10, 2017

I removed the blocker label from this PR so it's not confused as a blocker for the 5.4.0 release. I added a blocked label to the issue that is blocked on this PR.

timezone: 'Europe/Berlin'
}
};
return await Promise.all(chainRunner.processRequest(request));
Copy link
Contributor

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();
Copy link
Contributor

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:

#10961 (comment)

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.

@tbragin tbragin removed the v5.4.0 label Apr 11, 2017
@tbragin
Copy link
Contributor

tbragin commented Apr 11, 2017

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.

ppisljar and others added 8 commits April 24, 2017 07:23
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.
@thomasneirynck
Copy link
Contributor

jenkins, test this

@@ -21,7 +21,7 @@
}

start
= tree:series+ {
Copy link
Contributor

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.

Copy link
Member Author

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 () {
Copy link
Contributor

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).

Copy link
Member Author

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 ?

Copy link
Contributor

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* {
Copy link
Contributor

Choose a reason for hiding this comment

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

dito

Copy link
Member Author

Choose a reason for hiding this comment

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

dito :)

@ppisljar
Copy link
Member Author

@rashidkpc do you want to take another look ?

@rashidkpc
Copy link
Contributor

LGTM

@rashidkpc
Copy link
Contributor

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.

Copy link
Contributor

@cjcenizal cjcenizal left a 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');
});
});
Copy link
Contributor

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 ppisljar merged commit a3bfc2b into elastic:master Apr 28, 2017
@epixa
Copy link
Contributor

epixa commented May 1, 2017

@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?

@ppisljar
Copy link
Member Author

ppisljar commented May 3, 2017

@epixa thanks for the reminder! it landed in 6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Timelion Timelion app and visualization Feature:Visualizations Generic visualization features (in case no more specific feature label is available) release_note:breaking review v6.0.0-rc1 v6.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timelion grammar needs to strictly require comma-delimitation between expressions.
8 participants