Skip to content

Commit b474cda

Browse files
chaudumgrafana-delivery-bot[bot]
authored andcommitted
chore: Fix regression in bloom gateway that caused nothing to be filtered (#14807)
Pull request #14661 added the series labels to the `FilterChunkRefs` request in order to be able to filter out full series that do not contain the filter key when using bloom filters. However, this change incorrectly assumed that `Chunk.Metric` from the `GetChunks()` call contains the labels of the stream. This information is only populated once the chunk is fetched, though. Therefore the list of labels was empty, and no chunk refs were filtered. Signed-off-by: Christian Haudum <[email protected]> (cherry picked from commit 3b20cb0)
1 parent 02eb024 commit b474cda

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

pkg/indexgateway/gateway.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ func buildResponses(query seriesindex.Query, batch seriesindex.ReadBatchResult,
209209

210210
func (g *Gateway) GetChunkRef(ctx context.Context, req *logproto.GetChunkRefRequest) (result *logproto.GetChunkRefResponse, err error) {
211211
logger := util_log.WithContext(ctx, g.log)
212+
sp, ctx := opentracing.StartSpanFromContext(ctx, "indexgateway.GetChunkRef")
213+
defer sp.Finish()
212214

213215
instanceID, err := tenant.TenantID(ctx)
214216
if err != nil {
@@ -225,16 +227,12 @@ func (g *Gateway) GetChunkRef(ctx context.Context, req *logproto.GetChunkRefRequ
225227
return nil, err
226228
}
227229

228-
series := make(map[uint64]labels.Labels)
229230
result = &logproto.GetChunkRefResponse{
230231
Refs: make([]*logproto.ChunkRef, 0, len(chunks)),
231232
}
232233
for _, cs := range chunks {
233234
for i := range cs {
234235
result.Refs = append(result.Refs, &cs[i].ChunkRef)
235-
if _, ok := series[cs[i].Fingerprint]; !ok {
236-
series[cs[i].Fingerprint] = cs[i].Metric
237-
}
238236
}
239237
}
240238

@@ -261,10 +259,22 @@ func (g *Gateway) GetChunkRef(ctx context.Context, req *logproto.GetChunkRefRequ
261259
return result, nil
262260
}
263261

264-
chunkRefs, used, err := g.bloomQuerier.FilterChunkRefs(ctx, instanceID, req.From, req.Through, series, result.Refs, req.Plan)
262+
// Doing a "duplicate" index lookup is not ideal,
263+
// however, modifying the GetChunkRef() response, which contains the logproto.ChunkRef is neither.
264+
start := time.Now()
265+
series, err := g.indexQuerier.GetSeries(ctx, instanceID, req.From, req.Through, matchers...)
266+
seriesMap := make(map[uint64]labels.Labels, len(series))
267+
for _, s := range series {
268+
seriesMap[s.Hash()] = s
269+
}
270+
sp.LogKV("msg", "indexQuerier.GetSeries", "duration", time.Since(start), "count", len(series))
271+
272+
start = time.Now()
273+
chunkRefs, used, err := g.bloomQuerier.FilterChunkRefs(ctx, instanceID, req.From, req.Through, seriesMap, result.Refs, req.Plan)
265274
if err != nil {
266275
return nil, err
267276
}
277+
sp.LogKV("msg", "bloomQuerier.FilterChunkRefs", "duration", time.Since(start))
268278

269279
result.Refs = chunkRefs
270280
level.Info(logger).Log("msg", "return filtered chunk refs", "unfiltered", initialChunkCount, "filtered", len(result.Refs), "used_blooms", used)

0 commit comments

Comments
 (0)