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

Decouple logql engine/AST from execution context #1605

Merged
merged 4 commits into from
Jan 29, 2020

Conversation

owen-d
Copy link
Member

@owen-d owen-d commented Jan 29, 2020

What

This PR introduces a few changes/refactorings designed to decouple the LogQL engine and AST from its execution context. The idea is that an AST is just a stateless tree structure which can be processed by an evaluation engine. Separating the evaluation from AST will allow us to more easily build different evaluation contexts (sharding comes to mind).

  • logql Engine is now an interface
  • iterators and evaluators are no longer struct fields on AST nodes
  • introduces an Evaluator interface
  • evaluators can be combined with ast nodes in order to resolve the underlying queries.

Why

Previously, evaluators and iterators were tied directly into the AST nodes themselves. This makes them difficult to extend/refactor/etc.

$ benchcmp /tmp/master.out /tmp/refactor.out
benchmark                        old ns/op      new ns/op      delta
BenchmarkContainsFilter-8        8.30           8.41           +1.33%
BenchmarkRangeQuery100000-8      2516982        2213231        -12.07%
BenchmarkRangeQuery200000-8      10473399       12376741       +18.17%
BenchmarkRangeQuery500000-8      1937572837     1888996274     -2.51%
BenchmarkRangeQuery1000000-8     4224820576     3931777379     -6.94%

benchmark                        old allocs     new allocs     delta
BenchmarkRangeQuery100000-8      2848           2907           +2.07%
BenchmarkRangeQuery200000-8      3333           3514           +5.43%
BenchmarkRangeQuery500000-8      136397         136449         +0.04%
BenchmarkRangeQuery1000000-8     269751         269815         +0.02%

benchmark                        old bytes     new bytes     delta
BenchmarkRangeQuery100000-8      412186        405320        -1.67%
BenchmarkRangeQuery200000-8      894959        1009403       +12.79%
BenchmarkRangeQuery500000-8      135070672     135033424     -0.03%
BenchmarkRangeQuery1000000-8     270658240     270658704     +0.00%

@codecov-io
Copy link

Codecov Report

Merging #1605 into master will increase coverage by 0.09%.
The diff coverage is 89.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1605      +/-   ##
==========================================
+ Coverage   60.65%   60.75%   +0.09%     
==========================================
  Files         106      107       +1     
  Lines        8052     8075      +23     
==========================================
+ Hits         4884     4906      +22     
- Misses       2783     2784       +1     
  Partials      385      385
Impacted Files Coverage Δ
pkg/querier/http.go 7.06% <0%> (ø) ⬆️
pkg/querier/querier.go 70.06% <100%> (ø) ⬆️
pkg/logql/ast.go 84.37% <69.23%> (-1%) ⬇️
pkg/logql/engine.go 87.78% <86.04%> (-3.75%) ⬇️
pkg/logql/evaluator.go 92.78% <92.78%> (ø)
pkg/promtail/targets/filetarget.go 70.55% <0%> (+1.84%) ⬆️
pkg/promtail/targets/tailer.go 75.86% <0%> (+2.29%) ⬆️

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena cyriltovena merged commit b7d23f4 into grafana:master Jan 29, 2020
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.

None yet

3 participants