Skip to content

Commit

Permalink
chore(blooms): Replace extracting line filters with extracting label …
Browse files Browse the repository at this point in the history
…filters (#14137)

Replace the logic for extracting line filters with extracting label filters on the bloom gateway client, because otherwise the bloom gateway server would receive requests with no label matchers.

Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum authored Sep 13, 2024
1 parent 1308d90 commit 5bffc10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pkg/indexgateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ func (g *Gateway) GetChunkRef(ctx context.Context, req *logproto.GetChunkRefRequ
return result, nil
}

// Extract LineFiltersExpr from the plan. If there is none, we can short-circuit and return before making a req
// to the bloom-gateway (through the g.bloomQuerier)
// Extract testable LabelFilters from the plan. If there is none, we can
// short-circuit and return before making a req to the bloom-gateway (through
// the g.bloomQuerier)
if len(v1.ExtractTestableLabelMatchers(req.Plan.AST)) == 0 {
return result, nil
}
Expand Down Expand Up @@ -464,7 +465,7 @@ func (g *Gateway) boundedShards(
filtered := refs

// 2) filter via blooms if enabled
filters := syntax.ExtractLineFilters(p.Plan().AST)
filters := v1.ExtractTestableLabelMatchers(p.Plan().AST)
if g.bloomQuerier != nil && len(filters) > 0 {
xs, err := g.bloomQuerier.FilterChunkRefs(ctx, instanceID, req.From, req.Through, refs, p.Plan())
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions pkg/querier/queryrange/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/grafana/loki/v3/pkg/logql"
"github.com/grafana/loki/v3/pkg/logql/syntax"
"github.com/grafana/loki/v3/pkg/querier/queryrange/queryrangebase"
v1 "github.com/grafana/loki/v3/pkg/storage/bloom/v1"
)

type Metrics struct {
Expand Down Expand Up @@ -46,15 +47,15 @@ func NewMetrics(registerer prometheus.Registerer, metricsNamespace string) *Metr
}

type QueryMetrics struct {
receivedFilters prometheus.Histogram
receivedLabelFilters prometheus.Histogram
}

func NewMiddlewareQueryMetrics(registerer prometheus.Registerer, metricsNamespace string) *QueryMetrics {
return &QueryMetrics{
receivedFilters: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{
receivedLabelFilters: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{
Namespace: metricsNamespace,
Name: "query_frontend_query_filters",
Help: "Number of filters per query.",
Name: "query_frontend_query_label_filters",
Help: "Number of label matcher expressions per query.",
Buckets: prometheus.ExponentialBuckets(1, 2, 9), // 1 -> 256
}),
}
Expand Down Expand Up @@ -87,8 +88,8 @@ func QueryMetricsMiddleware(metrics *QueryMetrics) queryrangebase.Middleware {
}
}

filters := syntax.ExtractLineFilters(expr)
metrics.receivedFilters.Observe(float64(len(filters)))
filters := v1.ExtractTestableLabelMatchers(expr)
metrics.receivedLabelFilters.Observe(float64(len(filters)))

return next.Do(ctx, req)
})
Expand Down

0 comments on commit 5bffc10

Please sign in to comment.