Skip to content

Commit

Permalink
fix(blooms): Check length of tasks before accessing first element in …
Browse files Browse the repository at this point in the history
…slice (#14634)

This PR adds a length check for the partitioned series before accessing the first element of the resulting slice.

Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum authored Oct 29, 2024
1 parent ea798e0 commit 601f549
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/bloomgateway/bloomgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ func (g *Gateway) FilterChunkRefs(ctx context.Context, req *logproto.FilterChunk
// Shortcut if request does not contain filters
if len(matchers) == 0 {
stats.Status = labelSuccess
return &logproto.FilterChunkRefResponse{
ChunkRefs: req.Refs,
}, nil
return &logproto.FilterChunkRefResponse{ChunkRefs: req.Refs}, nil
}

blocks := make([]bloomshipper.BlockRef, 0, len(req.Blocks))
Expand All @@ -218,9 +216,7 @@ func (g *Gateway) FilterChunkRefs(ctx context.Context, req *logproto.FilterChunk
// Shortcut if request does not contain blocks
if len(blocks) == 0 {
stats.Status = labelSuccess
return &logproto.FilterChunkRefResponse{
ChunkRefs: req.Refs,
}, nil
return &logproto.FilterChunkRefResponse{ChunkRefs: req.Refs}, nil
}

seriesByDay := partitionRequest(req)
Expand All @@ -233,6 +229,14 @@ func (g *Gateway) FilterChunkRefs(ctx context.Context, req *logproto.FilterChunk
"series_requested", len(req.Refs),
)

// len(seriesByDay) should never be 0
// Not sure how this can happen, but there was a bug report
// https://github.com/grafana/loki/issues/14623
if len(seriesByDay) == 0 {
stats.Status = labelSuccess
return &logproto.FilterChunkRefResponse{ChunkRefs: req.Refs}, nil
}

if len(seriesByDay) > 1 {
stats.Status = labelFailure
return nil, errors.New("request time range must span exactly one day")
Expand Down

0 comments on commit 601f549

Please sign in to comment.