Skip to content

Add Position metadata to the parser#6061

Closed
slrtbtfs wants to merge 24 commits intoprometheus:masterfrom
slrtbtfs:master
Closed

Add Position metadata to the parser#6061
slrtbtfs wants to merge 24 commits intoprometheus:masterfrom
slrtbtfs:master

Conversation

@slrtbtfs
Copy link
Contributor

@slrtbtfs slrtbtfs commented Sep 26, 2019

This aims to implement part one of proposal https://github.com/slrtbtfs/promql-lsp/blob/master/doc/proposals/2019_promql-parser-improvements.md

It introduces position metadata in the error messages and the AST.

Current state:

  • For error messages, the implementation is done.
  • The AST is able to store position metadata but currently mostly uses zeros as placeholders.
  • The last commit fills some of the position fields with real data. Unfortunately it triggers a data race. Despite staring at the code for quite a while I haven't been able to figure out the root cause of that race, so any help there would be appreciated.

@brancz
Copy link
Member

brancz commented Sep 26, 2019

We looked at the code a little and couldn't find the data race, maybe someone sees it or can think of a data race that may had been there all along, but only now triggers the race detector.

@brancz
Copy link
Member

brancz commented Sep 26, 2019

@slrtbtfs
Copy link
Contributor Author

Output of the race detector: https://gist.github.com/slrtbtfs/359c05c7a5f28c1df3f9d9a1b6be99c6

@slrtbtfs
Copy link
Contributor Author

Data race has been found by Casey and Simon approx. at the same time.

@slrtbtfs
Copy link
Contributor Author

slrtbtfs commented Sep 27, 2019

Update: All AST Nodes have Position information now. There are still two edge cases where that the positions are not accurate:

  • NumberLiterals that are the right hand side of a vector matching report positions that are off by one. Edit: The error was in the test case
  • Offset modifiers are not handled correctly.

@slrtbtfs
Copy link
Contributor Author

slrtbtfs commented Oct 7, 2019

The PR should be in a sane state now.

@slrtbtfs slrtbtfs changed the title WIP: Add Position metadata to the parser Add Position metadata to the parser Oct 7, 2019
Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

I'm that familiar with the promql code but here are some comments.

Deprecate old file location API of the lexer and add new one

Add File Option in lexer initialisation

Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
ATM they are still populated with zeros

Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
slrtbtfs and others added 10 commits October 25, 2019 19:06
Offset modifiers are not yet reflected in the syntax tree

Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
@slrtbtfs
Copy link
Contributor Author

The merge conflict should be resolved now.

Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
@slrtbtfs
Copy link
Contributor Author

Is there any specific reason stopping this from being merged?

cc @simonpasquier @krasi-georgiev @brian-brazil @juliusv

@krasi-georgiev
Copy link
Contributor

sorry I don't think I will be able to provide a review here as I am focused on the cert rotation PR in Thanos.

@brancz
Copy link
Member

brancz commented Oct 30, 2019

lgtm from an implementation side, @juliusv @brian-brazil @beorn7 are you happy with moving forward with this in general?

As a side note we're going to be investigating a generated parser next, our investigation so far have shown that even if we go with that, the overwhelming majority of this PR would still be required (more comprehensive proposal in progress).

@juliusv
Copy link
Member

juliusv commented Oct 30, 2019

Yeah, I haven't checked the implementation in detail, but in general I'm all for it. I'm very much looking forward to PromQL syntax highlighting and autocompletion :)

Will be part of a separate PR

Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
@beorn7
Copy link
Member

beorn7 commented Oct 30, 2019

I guess @tomwilkie is way more qualified than I am to comment on this.

Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
@slrtbtfs
Copy link
Contributor Author

Here are some benchmarks for this PR.

https://gist.github.com/slrtbtfs/07fec8f8e023e70e50ee220c9bd29ca8

@slrtbtfs
Copy link
Contributor Author

Looks like there is no performance hit. The number of allocations actually seems to have gone slightly down.

@slrtbtfs
Copy link
Contributor Author

The benchmarks above test the whole PromQL engine. Since the parser is only a small part of these workloads, the changes of this PR might get buried in the noise.

I've added another benchmark (see #6355) , that exclusively tests the parser. Here a negative performance impact is visible, but not dramatic. It can be seen that the position logic adds 5 allocations per parser run.

https://gist.github.com/slrtbtfs/e95ffda4b8cd12b77428d57ac2cdb774

@brian-brazil
Copy link
Contributor

I'd consider if the changes are lost in the noise, then all is good.

@slrtbtfs
Copy link
Contributor Author

Closed in favour of adding the features of this PR, after the parser has been replaced by a generated one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants