Skip to content

Commit

Permalink
Improve best case for chunk filtering by day
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum committed Nov 17, 2023
1 parent a64ea37 commit 3595653
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/bloomgateway/multiplexing.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ func (cf filterGroupedChunkRefsByDay) contains(a *logproto.GroupedChunkRefs) boo
}

func (cf filterGroupedChunkRefsByDay) filter(a *logproto.GroupedChunkRefs) *logproto.GroupedChunkRefs {
minTs, maxTs := getFromThrough(a.Refs)

// in most cases, all chunks are within day range
if minTs.Time().Compare(cf.day) >= 0 && maxTs.Time().Before(cf.day.Add(24*time.Hour)) {
return a
}

// case where certain chunks are outside of day range
// using binary search to get min and max index of chunks that fall into the day range
min := sort.Search(len(a.Refs), func(i int) bool {
start := a.Refs[i].From.Time()
return start.Compare(cf.day) >= 0 && start.Compare(cf.day.Add(Day)) < 0
Expand All @@ -86,6 +95,7 @@ func (cf filterGroupedChunkRefsByDay) filter(a *logproto.GroupedChunkRefs) *logp
start := a.Refs[i].From.Time()
return start.Compare(cf.day.Add(Day)) >= 0
})

return &logproto.GroupedChunkRefs{
Tenant: a.Tenant,
Fingerprint: a.Fingerprint,
Expand Down

0 comments on commit 3595653

Please sign in to comment.