Skip to content

Commit

Permalink
Replace extracting line filters with extracting label filters
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
  • Loading branch information
chaudum committed Sep 13, 2024
1 parent 1308d90 commit 8787c2c
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
receivedMatchers prometheus.Histogram
}

func NewMiddlewareQueryMetrics(registerer prometheus.Registerer, metricsNamespace string) *QueryMetrics {
return &QueryMetrics{
receivedFilters: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{
receivedMatchers: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{
Namespace: metricsNamespace,
Name: "query_frontend_query_filters",
Help: "Number of filters per query.",
Name: "query_frontend_query_matchers",
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)))
matchers := v1.ExtractTestableLabelMatchers(expr)
metrics.receivedMatchers.Observe(float64(len(matchers)))

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

0 comments on commit 8787c2c

Please sign in to comment.