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

refactor: Pass query plan down to bloom gateway #12037

Merged
merged 7 commits into from
Feb 23, 2024

Conversation

salvacorts
Copy link
Contributor

What this PR does / why we need it:

Follow-up for #12035.

Before this PR, the FilterChunkRefRequest would contain a list of filters ([]syntax.LineFilter). In order to build a proper bloom test plan with the filters, we would need to have the filters as []syntax. LineFilterExpr but:

  • We would need to serialize syntax. LineFilterExpr which is a tree-like structure which might get cumbersome to marshal.
  • In the future we might want to filter chunks by other filtering expressions than line filters. For example, filtering by structured metadata. That wouldn't be possible by only looking at []syntax. LineFilterExpr.

Instead, we are passing the query plan with FilterChunkRefRequest. Later on, in the bloom-gateway we extract the filters ([]syntax. LineFilterExpr) from the plan.

Special notes for your reviewer:
This PR doesn't modify the bloom test logic. We still extract a slice of syntax.LineFilter (matching filters only. i.e. no regexes not Not Equal matches) out of the plan (regardless of the Or operations) and build ngrams for the matches.
On a followup PR, we will wire the changes from this PR to the new tests from #12035.

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
    • If the change is worth mentioning in the release notes, add add-to-release-notes label
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@salvacorts salvacorts force-pushed the salvacorts/pass-plan-to-boom-gateway branch from d631fec to 488f264 Compare February 22, 2024 13:32
pkg/logproto/compat_test.go Outdated Show resolved Hide resolved
pkg/logproto/logproto.proto Show resolved Hide resolved
Comment on lines 9 to +10
Matchers []*labels.Matcher
Filters []syntax.LineFilter
plan *plan.QueryPlan
Copy link
Contributor

Choose a reason for hiding this comment

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

Matchers and plan now contain redundant information. The plan already contains the matchers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in Slack. We will leave as is right now. We can consider refactoring that on a separate PR.

pkg/querier/plan/plan.go Outdated Show resolved Hide resolved
pkg/querier/plan/plan.go Outdated Show resolved Hide resolved
pkg/logql/syntax/ast.go Outdated Show resolved Hide resolved
@@ -8,6 +8,8 @@ import (

type QueryPlan struct {
AST syntax.Expr

lineFilterExprs *[]syntax.LineFilterExpr
Copy link
Contributor

Choose a reason for hiding this comment

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

QueryPlan should not contain individual parts of the AST separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

related: #12037 (comment)

@salvacorts salvacorts marked this pull request as ready for review February 22, 2024 16:09
@salvacorts salvacorts requested a review from a team as a code owner February 22, 2024 16:09
Copy link
Contributor

@chaudum chaudum left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -334,7 +335,7 @@ func (g *Gateway) FilterChunkRefs(ctx context.Context, req *logproto.FilterChunk

tasks := make([]Task, 0, len(seriesByDay))
for _, seriesWithBounds := range seriesByDay {
task, err := NewTask(ctx, tenantID, seriesWithBounds, req.Plan.LineFilterExprs())
task, err := NewTask(ctx, tenantID, seriesWithBounds, syntax.ExtractLineFilters(req.Plan.AST))
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to avoid traversing the AST multiple times, you could extract the filters once in the beginning of the request handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! Done


return fmt.Sprintf("%d/%s", chunksHash, sb.String())
// TODO(salvacorts): plan.String() will return the whole query. This is not optimal since we are only interested in the filter expressions.
return fmt.Sprintf("%d/%s", chunksHash, plan)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a limit of the cache key length? Plan could be up to 2k characters, right?
Would a query hash be sufficient, since we have the combination with the chunksHash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, changed to use plan hash

Comment on lines 237 to 240
// TODO(chaudum): Take the chunks from the index querier's GetChunks()
// response and send them to the bloom gateway along with the filter
// expression that we got from the request object.
// The bloom gateway returns the list of matching ChunkRefs.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@salvacorts salvacorts merged commit 4fa5148 into main Feb 23, 2024
11 checks passed
@salvacorts salvacorts deleted the salvacorts/pass-plan-to-boom-gateway branch February 23, 2024 09:41
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
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

2 participants