diff --git a/pkg/indexgateway/gateway.go b/pkg/indexgateway/gateway.go index 8f2a24a18f03f..d282884d547e4 100644 --- a/pkg/indexgateway/gateway.go +++ b/pkg/indexgateway/gateway.go @@ -247,6 +247,16 @@ func (g *Gateway) GetChunkRef(ctx context.Context, req *logproto.GetChunkRefRequ result.Stats.PostFilterChunks = int64(initialChunkCount) // populate early for error reponses result.Stats.ChunkRefsLookupTime = chunkRefsLookupDuration.Seconds() + // Compute unique streams matched from chunk refs + // Allocate map size based on chunk count since unique streams <= number of chunks + { + seen := make(map[uint64]struct{}, initialChunkCount) + for _, ref := range result.Refs { + seen[ref.Fingerprint] = struct{}{} + } + result.Stats.TotalStreams = int64(len(seen)) + } + defer func() { if err == nil { g.metrics.preFilterChunks.WithLabelValues(routeChunkRefs).Observe(float64(initialChunkCount)) diff --git a/pkg/logql/metrics.go b/pkg/logql/metrics.go index 259ff6d067fd6..92a3a24fa9401 100644 --- a/pkg/logql/metrics.go +++ b/pkg/logql/metrics.go @@ -261,7 +261,7 @@ func RecordRangeAndInstantQueryMetrics( // This is only logged from the querier component, not from the frontend // (where stats are merged and this value would be inaccurate) if !isFrontendContext(ctx) && stats.Index.TotalStreams > 0 { - logValues = append(logValues, "total_stream_count", stats.Index.TotalStreams) + logValues = append(logValues, "index_total_streams", stats.Index.TotalStreams) } // Add frontend-specific metrics: approximate result size, streams count, lines count