Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix regression in bloom gateway that caused nothing to be filtered #14807

Merged
merged 1 commit into from
Nov 7, 2024
Merged
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
20 changes: 15 additions & 5 deletions pkg/indexgateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func buildResponses(query seriesindex.Query, batch seriesindex.ReadBatchResult,

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

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

series := make(map[uint64]labels.Labels)
result = &logproto.GetChunkRefResponse{
Refs: make([]*logproto.ChunkRef, 0, len(chunks)),
}
for _, cs := range chunks {
for i := range cs {
result.Refs = append(result.Refs, &cs[i].ChunkRef)
if _, ok := series[cs[i].Fingerprint]; !ok {
series[cs[i].Fingerprint] = cs[i].Metric
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: What about adding a comment in the chunk struct about fields not being populated until fetched?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ I would also like this, it seems inevitable that someone is going to run into this again since it's not very obvious.

}
}
}

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

chunkRefs, used, err := g.bloomQuerier.FilterChunkRefs(ctx, instanceID, req.From, req.Through, series, result.Refs, req.Plan)
// Doing a "duplicate" index lookup is not ideal,
// however, modifying the GetChunkRef() response, which contains the logproto.ChunkRef is neither.
start := time.Now()
series, err := g.indexQuerier.GetSeries(ctx, instanceID, req.From, req.Through, matchers...)
seriesMap := make(map[uint64]labels.Labels, len(series))
for _, s := range series {
seriesMap[s.Hash()] = s
}
sp.LogKV("msg", "indexQuerier.GetSeries", "duration", time.Since(start), "count", len(series))

start = time.Now()
chunkRefs, used, err := g.bloomQuerier.FilterChunkRefs(ctx, instanceID, req.From, req.Through, seriesMap, result.Refs, req.Plan)
if err != nil {
return nil, err
}
sp.LogKV("msg", "bloomQuerier.FilterChunkRefs", "duration", time.Since(start))

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