fix(blooms): Check length of tasks before accessing first element in 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 <christian.haudum@gmail.com>
pull/14636/head
Christian Haudum 1 year ago committed by GitHub
parent ea798e0f2a
commit 601f549656
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      pkg/bloomgateway/bloomgateway.go

@ -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))
@ -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)
@ -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")

Loading…
Cancel
Save