Skip to content

Commit

Permalink
stats cleanup and proper propagation
Browse files Browse the repository at this point in the history
Signed-off-by: Owen Diehl <ow.diehl@gmail.com>
  • Loading branch information
owen-d committed Mar 22, 2024
1 parent 5b70e96 commit 6437c38
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
8 changes: 0 additions & 8 deletions pkg/logqlmodel/stats/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down
4 changes: 4 additions & 0 deletions pkg/querier/queryrange/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,10 @@ var (
"queryReferencedStructuredMetadata": true
}
},
"index": {
"postFilterChunks": 0,
"totalChunks": 0
},
"cache": {
"chunk": {
"entriesFound": 0,
Expand Down
4 changes: 4 additions & 0 deletions pkg/querier/queryrange/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
)

var emptyStats = `"stats": {
"index": {
"postFilterChunks": 0,
"totalChunks": 0
},
"ingester" : {
"store": {
"chunksDownloadTime": 0,
Expand Down
29 changes: 19 additions & 10 deletions pkg/storage/stores/shipper/indexshipper/indexgateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down

0 comments on commit 6437c38

Please sign in to comment.