Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
db: add test for chunks that span beyond a block's boundaries
Browse files Browse the repository at this point in the history
Signed-off-by: Benoît Knecht <benoit.knecht@fsfe.org
  • Loading branch information
BenoitKnecht committed Jun 13, 2018
1 parent 2befe19 commit e663c7f
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -1098,3 +1100,52 @@ 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()

p, err := r.Postings(index.AllPostingsKey())
testutil.Ok(t, err)

var (
lset labels.Labels
chks []chunks.Meta
)

for p.Next() {
err = r.Series(p.At(), &lset, &chks)
testutil.Ok(t, err)
for _, c := range chks {
testutil.Assert(t, block.Meta().MinTime <= c.MinTime && c.MaxTime <= block.Meta().MaxTime,
"chunk spans beyond block boundaries: [block.MinTime=%d, block.MaxTime=%d]; [chunk.MinTime=%d, chunk.MaxTime=%d]",
block.Meta().MinTime, block.Meta().MaxTime, c.MinTime, c.MaxTime)
}
}
}
}

0 comments on commit e663c7f

Please sign in to comment.