Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/indexgateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion pkg/logql/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down