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
Signed-off-by: Michael Hoffmann <mhoffm@posteo.de>
  • Loading branch information
MichaHoffmann committed Mar 4, 2023
1 parent b1d083f commit 54fc7dc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

- [#6172](https://github.com/thanos-io/thanos/pull/6172) query-frontend: return JSON formatted errors for invalid PromQL expression in the split by interval middleware.
- [#6171](https://github.com/thanos-io/thanos/pull/6171) Store: fix error handling on limits.
- [#6183](https://github.com/thanos-io/thanos/pull/6183) Receiver: fix off by one in multitsdb flush that will result in empty blocks if the head only contains one sample

### Changed
- [#6168](https://github.com/thanos-io/thanos/pull/6168) Receiver: Make ketama hashring fail early when configured with number of nodes lower than the replication factor.
Expand Down
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 54fc7dc

Please sign in to comment.