Skip to content

Commit 67b0637

Browse files
chaudumgrafana-delivery-bot[bot]
authored andcommitted
fix: Do not filter out chunks for store when From==Through and From==start (#13117)
This PR fixes a bug where chunks are incorrectly filtered out when their `From` timestamp is equal to their `Through` timestamp (which happens when there is a single log line) and the `From` timestamp is equal to the `from` time of the of the request. How to reproduce: 1. Insert a single log line with a timestamp exactly at point of an hour 2. Flush ingester 3. Query log line with a split interval of 1h Signed-off-by: Christian Haudum <[email protected]> Co-authored-by: Ed Welch <[email protected]> (cherry picked from commit d9cc513)
1 parent 00d3c7a commit 67b0637

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

pkg/storage/stores/composite_store.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ func (c CompositeStore) GetChunks(
172172
) ([][]chunk.Chunk, []*fetcher.Fetcher, error) {
173173
chunkIDs := [][]chunk.Chunk{}
174174
fetchers := []*fetcher.Fetcher{}
175-
err := c.forStores(ctx, from, through, func(innerCtx context.Context, from, through model.Time, store Store) error {
176-
ids, fetcher, err := store.GetChunks(innerCtx, userID, from, through, predicate, storeChunksOverride)
175+
err := c.forStores(ctx, from, through, func(innerCtx context.Context, innerFrom, innerThrough model.Time, store Store) error {
176+
ids, fetcher, err := store.GetChunks(innerCtx, userID, innerFrom, innerThrough, predicate, storeChunksOverride)
177177
if err != nil {
178178
return err
179179
}

pkg/storage/stores/composite_store_entry.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ func (c *storeEntry) GetChunks(
9090
func filterForTimeRange(refs []*logproto.ChunkRef, from, through model.Time) []chunk.Chunk {
9191
filtered := make([]chunk.Chunk, 0, len(refs))
9292
for _, ref := range refs {
93-
if through >= ref.From && from < ref.Through {
93+
// Only include chunks where the query start time (from) is < the chunk end time (ref.Through)
94+
// and the query end time (through) is >= the chunk start time (ref.From)
95+
// A special case also exists where a chunk can contain a single log line which results in ref.From being equal to ref.Through, and that is equal to the from time.
96+
if (through >= ref.From && from < ref.Through) || (ref.From == from && ref.Through == from) {
9497
filtered = append(filtered, chunk.Chunk{
9598
ChunkRef: *ref,
9699
})

pkg/storage/stores/composite_store_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,23 @@ func TestFilterForTimeRange(t *testing.T) {
421421
through: 7,
422422
exp: mkChks(5, 7),
423423
},
424+
{
425+
desc: "ref with from == through",
426+
input: []*logproto.ChunkRef{
427+
{From: 1, Through: 1}, // outside
428+
{From: 2, Through: 2}, // ref.From == from == ref.Through
429+
{From: 3, Through: 3}, // inside
430+
{From: 4, Through: 4}, // ref.From == through == ref.Through
431+
{From: 5, Through: 5}, // outside
432+
},
433+
from: 2,
434+
through: 4,
435+
exp: []chunk.Chunk{
436+
{ChunkRef: logproto.ChunkRef{From: 2, Through: 2}},
437+
{ChunkRef: logproto.ChunkRef{From: 3, Through: 3}},
438+
{ChunkRef: logproto.ChunkRef{From: 4, Through: 4}},
439+
},
440+
},
424441
} {
425442
t.Run(tc.desc, func(t *testing.T) {
426443
got := filterForTimeRange(tc.input, tc.from, tc.through)

0 commit comments

Comments
 (0)