mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
db: add test for chunks that span beyond a block's boundaries
Signed-off-by: Benoît Knecht <benoit.knecht@fsfe.org>
This commit is contained in:
parent
0e4be5226a
commit
4ed6b9ed72
57
db_test.go
57
db_test.go
|
@ -26,6 +26,8 @@ import (
|
|||
|
||||
"github.com/oklog/ulid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/tsdb/chunks"
|
||||
"github.com/prometheus/tsdb/index"
|
||||
"github.com/prometheus/tsdb/labels"
|
||||
"github.com/prometheus/tsdb/testutil"
|
||||
)
|
||||
|
@ -1096,3 +1098,58 @@ func TestOverlappingBlocksDetectsAllOverlaps(t *testing.T) {
|
|||
{Min: 8, Max: 9}: {nc1[8], nc1[9]}, // 7-10, 8-9
|
||||
}, OverlappingBlocks(nc1))
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/prometheus/tsdb/issues/347
|
||||
func TestChunkAtBlockBoundary(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 < 3; i++ {
|
||||
_, err := app.Add(label, i*blockRange, 0)
|
||||
testutil.Ok(t, err)
|
||||
_, err = app.Add(label, i*blockRange+1000, 0)
|
||||
testutil.Ok(t, err)
|
||||
}
|
||||
|
||||
err := app.Commit()
|
||||
testutil.Ok(t, err)
|
||||
|
||||
_, err = db.compact()
|
||||
testutil.Ok(t, err)
|
||||
|
||||
for _, block := range db.blocks {
|
||||
r, err := block.Index()
|
||||
testutil.Ok(t, err)
|
||||
defer r.Close()
|
||||
|
||||
meta := block.Meta()
|
||||
|
||||
p, err := r.Postings(index.AllPostingsKey())
|
||||
testutil.Ok(t, err)
|
||||
|
||||
var (
|
||||
lset labels.Labels
|
||||
chks []chunks.Meta
|
||||
)
|
||||
|
||||
chunkCount := 0
|
||||
|
||||
for p.Next() {
|
||||
err = r.Series(p.At(), &lset, &chks)
|
||||
testutil.Ok(t, err)
|
||||
for _, c := range chks {
|
||||
testutil.Assert(t, meta.MinTime <= c.MinTime && c.MaxTime <= meta.MaxTime,
|
||||
"chunk spans beyond block boundaries: [block.MinTime=%d, block.MaxTime=%d]; [chunk.MinTime=%d, chunk.MaxTime=%d]",
|
||||
meta.MinTime, meta.MaxTime, c.MinTime, c.MaxTime)
|
||||
chunkCount++
|
||||
}
|
||||
}
|
||||
testutil.Assert(t, chunkCount == 1, "expected 1 chunk in block %s, got %d", meta.ULID, chunkCount)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue