Skip to content

Commit

Permalink
receive: fix multitsdb flush with one sample in head
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaHoffmann committed Mar 4, 2023
1 parent b1d083f commit 08d60c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/receive/multitsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (t *MultiTSDB) Flush() error {
wg.Add(1)
go func() {
head := db.Head()
if err := db.CompactHead(tsdb.NewRangeHead(head, head.MinTime(), head.MaxTime()-1)); err != nil {
if err := db.CompactHead(tsdb.NewRangeHead(head, head.MinTime(), head.MaxTime())); err != nil {
errmtx.Lock()
merr.Add(err)
errmtx.Unlock()
Expand Down
28 changes: 28 additions & 0 deletions pkg/receive/multitsdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,34 @@ func TestMultiTSDB(t *testing.T) {

testMulitTSDBSeries(t, m)
})

t.Run("flush with one sample produces a block", func(t *testing.T) {
m := NewMultiTSDB(
dir, logger, prometheus.NewRegistry(), &tsdb.Options{
MinBlockDuration: (2 * time.Hour).Milliseconds(),
MaxBlockDuration: (2 * time.Hour).Milliseconds(),
RetentionDuration: (6 * time.Hour).Milliseconds(),
NoLockfile: true,
},
labels.FromStrings("replica", "01"),
"tenant_id",
nil,
false,
metadata.NoneFunc,
)
defer func() { testutil.Ok(t, m.Close()) }()

testutil.Ok(t, m.Flush())
testutil.Ok(t, m.Open())
testutil.Ok(t, appendSample(m, "test", time.Now()))

tenant := m.tenants["test"]
db := tenant.readyStorage().Get()

testutil.Equals(t, 0, len(db.Blocks()))
testutil.Ok(t, m.Flush())
testutil.Equals(t, 1, len(db.Blocks()))
})
}

var (
Expand Down

0 comments on commit 08d60c8

Please sign in to comment.