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

fix(blooms): Fix partitionSeriesByDay function #12900

Merged
merged 2 commits into from
May 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion pkg/bloomgateway/bloomgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (g *Gateway) FilterChunkRefs(ctx context.Context, req *logproto.FilterChunk
"series_requested", len(req.Refs),
)

if len(seriesByDay) != 1 {
if len(seriesByDay) > 1 {
stats.Status = labelFailure
return nil, errors.New("request time range must span exactly one day")
}
Expand Down
11 changes: 2 additions & 9 deletions pkg/bloomgateway/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bloomgateway

import (
"sort"
"time"

"github.com/prometheus/common/model"
"golang.org/x/exp/slices"
Expand All @@ -13,13 +12,8 @@ import (
"github.com/grafana/loki/v3/pkg/storage/stores/shipper/bloomshipper"
)

func getDayTime(ts model.Time) time.Time {
return ts.Time().UTC().Truncate(Day)
}

func truncateDay(ts model.Time) model.Time {
// model.minimumTick is time.Millisecond
return ts - (ts % model.Time(24*time.Hour/time.Millisecond))
return model.TimeFromUnix(ts.Time().Truncate(Day).Unix())
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

}

// getFromThrough assumes a list of ShortRefs sorted by From time
Expand Down Expand Up @@ -125,7 +119,7 @@ func partitionSeriesByDay(from, through model.Time, seriesWithChunks []*logproto
})

// All chunks fall outside of the range
if min == len(chunks) || max == 0 {
if min == len(chunks) || max == 0 || min == max {
Copy link
Contributor

Choose a reason for hiding this comment

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

idea: I feel we have run already too many times into forgetting to check min==max maybe we should wrap this search use-case into some Template function or something.

continue
}

Expand All @@ -135,7 +129,6 @@ func partitionSeriesByDay(from, through model.Time, seriesWithChunks []*logproto
if chunks[max-1].Through > maxTs {
maxTs = chunks[max-1].Through
}
// fmt.Println("day", day, "series", series.Fingerprint, "minTs", minTs, "maxTs", maxTs)

res = append(res, &logproto.GroupedChunkRefs{
Fingerprint: series.Fingerprint,
Expand Down
42 changes: 39 additions & 3 deletions pkg/bloomgateway/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,46 @@ func TestPartitionRequest(t *testing.T) {
exp []seriesWithInterval
}{

"empty": {
"no series": {
inp: &logproto.FilterChunkRefRequest{
From: ts.Add(-24 * time.Hour),
Through: ts,
From: ts.Add(-12 * time.Hour),
Through: ts.Add(12 * time.Hour),
Refs: []*logproto.GroupedChunkRefs{},
},
exp: []seriesWithInterval{},
},

"no chunks for series": {
inp: &logproto.FilterChunkRefRequest{
From: ts.Add(-12 * time.Hour),
Through: ts.Add(12 * time.Hour),
Refs: []*logproto.GroupedChunkRefs{
{
Fingerprint: 0x00,
Refs: []*logproto.ShortRef{},
},
{
Fingerprint: 0x10,
Refs: []*logproto.ShortRef{},
},
},
},
exp: []seriesWithInterval{},
},

"chunks before and after requested day": {
inp: &logproto.FilterChunkRefRequest{
From: ts.Add(-2 * time.Hour),
Through: ts.Add(2 * time.Hour),
Refs: []*logproto.GroupedChunkRefs{
{
Fingerprint: 0x00,
Refs: []*logproto.ShortRef{
{From: ts.Add(-13 * time.Hour), Through: ts.Add(-12 * time.Hour)},
{From: ts.Add(13 * time.Hour), Through: ts.Add(14 * time.Hour)},
},
},
},
},
exp: []seriesWithInterval{},
},
Expand Down
Loading