From 5bffc10d857a3ffaab2700cacc703bbf0f813379 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Fri, 13 Sep 2024 20:19:53 +0200 Subject: [PATCH] chore(blooms): Replace extracting line filters with extracting label 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 --- pkg/indexgateway/gateway.go | 7 ++++--- pkg/querier/queryrange/metrics.go | 13 +++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/indexgateway/gateway.go b/pkg/indexgateway/gateway.go index 83dfcfe0b79ba..745b114c08ac0 100644 --- a/pkg/indexgateway/gateway.go +++ b/pkg/indexgateway/gateway.go @@ -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 } @@ -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 { diff --git a/pkg/querier/queryrange/metrics.go b/pkg/querier/queryrange/metrics.go index bd9ce6fa79bac..d3c949b9bb3af 100644 --- a/pkg/querier/queryrange/metrics.go +++ b/pkg/querier/queryrange/metrics.go @@ -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 { @@ -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 }), } @@ -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) })