Skip to content

Commit

Permalink
db: add test for Querier returning too many blocks
Browse files Browse the repository at this point in the history
Due to the way blocks used to overlap by 1 millisecond (see prometheus-junkyard#347), when
requesting a 2-hour interval starting at `blocks[1].MinTime`, the
`Querier` would consider three blocks: `blocks[0]`, `blocks[1]` and
`blocks[2]`, because `blocks[0].MaxTime` and `blocks[2].MinTime` were in
that interval.

However, if the blocks don't overlap, only two blocks should be
returned: `blocks[1]` and `blocks[2]`. This test ensures that it's
indeed the case.

Signed-off-by: Benoît Knecht <benoit.knecht@fsfe.org>
  • Loading branch information
BenoitKnecht committed Jun 18, 2018
1 parent d81d209 commit a2c8f48
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,3 +1155,35 @@ func TestChunkAtBlockBoundary(t *testing.T) {
testutil.Assert(t, chunkCount == 1, "expected 1 chunk in block %s, got %d", meta.ULID, chunkCount)
}
}

func TestQuerierWithBoundaryChunks(t *testing.T) {
db, close := openTestDB(t, nil)
defer close()
defer db.Close()

app := db.Appender()

blockRange := DefaultOptions.BlockRanges[0]
label := labels.FromStrings("foo", "bar")

for i := int64(0); i < 5; i++ {
_, err := app.Add(label, i*blockRange, 0)
testutil.Ok(t, err)
}

err := app.Commit()
testutil.Ok(t, err)

_, err = db.compact()
testutil.Ok(t, err)

testutil.Assert(t, len(db.blocks) >= 3, "invalid test, less than three blocks in DB")

q, err := db.Querier(blockRange, 2*blockRange)
testutil.Ok(t, err)
defer q.Close()

// The requested interval covers 2 blocks, so the querier should contain 2 blocks.
count := len(q.(*querier).blocks)
testutil.Assert(t, count == 2, "expected 2 blocks in querier, got %d", count)
}

0 comments on commit a2c8f48

Please sign in to comment.