diff --git a/pkg/logqlmodel/stats/context.go b/pkg/logqlmodel/stats/context.go index b4342581a277e..dc1fe9356f4a6 100644 --- a/pkg/logqlmodel/stats/context.go +++ b/pkg/logqlmodel/stats/context.go @@ -170,14 +170,6 @@ func JoinIngesters(ctx context.Context, inc Ingester) { stats.ingester.Merge(inc) } -func JoinIndex(ctx context.Context, inc Index) { - stats := FromContext(ctx) - stats.mtx.Lock() - defer stats.mtx.Unlock() - - stats.index.Merge(inc) -} - // ComputeSummary compute the summary of the statistics. func (r *Result) ComputeSummary(execTime time.Duration, queueTime time.Duration, totalEntriesReturned int) { r.Summary.TotalBytesProcessed = r.Querier.Store.Chunk.DecompressedBytes + r.Querier.Store.Chunk.HeadChunkBytes + diff --git a/pkg/querier/queryrange/codec_test.go b/pkg/querier/queryrange/codec_test.go index fa6fa9e036711..b615d73b09c01 100644 --- a/pkg/querier/queryrange/codec_test.go +++ b/pkg/querier/queryrange/codec_test.go @@ -1593,6 +1593,10 @@ var ( "queryReferencedStructuredMetadata": true } }, + "index": { + "postFilterChunks": 0, + "totalChunks": 0 + }, "cache": { "chunk": { "entriesFound": 0, diff --git a/pkg/querier/queryrange/prometheus_test.go b/pkg/querier/queryrange/prometheus_test.go index 80e4f5367afb0..624c8b5194eec 100644 --- a/pkg/querier/queryrange/prometheus_test.go +++ b/pkg/querier/queryrange/prometheus_test.go @@ -13,6 +13,10 @@ import ( ) var emptyStats = `"stats": { + "index": { + "postFilterChunks": 0, + "totalChunks": 0 + }, "ingester" : { "store": { "chunksDownloadTime": 0, diff --git a/pkg/storage/stores/shipper/indexshipper/indexgateway/gateway.go b/pkg/storage/stores/shipper/indexshipper/indexgateway/gateway.go index 7eb5b8ad2a678..124fe4f933d32 100644 --- a/pkg/storage/stores/shipper/indexshipper/indexgateway/gateway.go +++ b/pkg/storage/stores/shipper/indexshipper/indexgateway/gateway.go @@ -439,19 +439,25 @@ func (g *Gateway) getShardsWithBlooms( } g.metrics.preFilterChunks.WithLabelValues(routeShards).Observe(float64(ct)) g.metrics.postFilterChunks.WithLabelValues(routeShards).Observe(float64(len(filtered))) - stats.JoinIndex(ctx, stats.Index{ - TotalChunks: int64(ct), - PostFilterChunks: int64(len(filtered)), - }) + + statistics := stats.Result{ + Index: stats.Index{ + TotalChunks: int64(ct), + PostFilterChunks: int64(len(filtered)), + }, + } // Edge case: if there are no chunks after filtering, we still need to return a single shard if len(filtered) == 0 { - return server.Send(&logproto.ShardsResponse{Shards: []logproto.Shard{ - { - Bounds: logproto.FPBounds{Min: 0, Max: math.MaxUint64}, - Stats: &logproto.IndexStatsResponse{}, + return server.Send(&logproto.ShardsResponse{ + Shards: []logproto.Shard{ + { + Bounds: logproto.FPBounds{Min: 0, Max: math.MaxUint64}, + Stats: &logproto.IndexStatsResponse{}, + }, }, - }}) + Statistics: statistics, + }) } shards, err := accumulateChunksToShards(ctx, instanceID, forSeries, req, p, filtered) @@ -460,7 +466,10 @@ func (g *Gateway) getShardsWithBlooms( } // 3) build shards - return server.Send(&logproto.ShardsResponse{Shards: shards}) + return server.Send(&logproto.ShardsResponse{ + Shards: shards, + Statistics: statistics, + }) } // ExtractShardRequestMatchersAndAST extracts the matchers and AST from a query string.