diff --git a/CHANGELOG.md b/CHANGELOG.md index 534de25cb..dca10c25f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## master / unreleased + - [BUGFIX] Update `last` after appending a non-overlapping chunk in `chunks.MergeOverlappingChunks`. [#539](https://github.com/prometheus/tsdb/pull/539) ## 0.6.0 - [CHANGE] `AllowOverlappingBlock` is now `AllowOverlappingBlocks`. diff --git a/chunks/chunks.go b/chunks/chunks.go index 3f643bc74..dd5a5f8c2 100644 --- a/chunks/chunks.go +++ b/chunks/chunks.go @@ -213,6 +213,7 @@ func MergeOverlappingChunks(chks []Meta) ([]Meta, error) { // So never overlaps with newChks[last-1] or anything before that. if c.MinTime > newChks[last].MaxTime { newChks = append(newChks, c) + last += 1 continue } nc := &newChks[last] diff --git a/compact_test.go b/compact_test.go index 9dc9396a7..1e06b39fc 100644 --- a/compact_test.go +++ b/compact_test.go @@ -653,7 +653,8 @@ func TestCompaction_populateBlock(t *testing.T) { expErr: errors.New("found chunk with minTime: 10 maxTime: 20 outside of compacted minTime: 0 maxTime: 10"), }, { - // No special deduplication expected. + // Deduplication expected. + // Introduced by pull/370 and pull/539. title: "Populate from two blocks containing duplicated chunk.", inputSeriesSamples: [][]seriesSamples{ { @@ -672,7 +673,53 @@ func TestCompaction_populateBlock(t *testing.T) { expSeriesSamples: []seriesSamples{ { lset: map[string]string{"a": "b"}, - chunks: [][]sample{{{t: 1}, {t: 2}}, {{t: 10}, {t: 20}}, {{t: 10}, {t: 20}}}, + chunks: [][]sample{{{t: 1}, {t: 2}}, {{t: 10}, {t: 20}}}, + }, + }, + }, + { + // Introduced by https://github.com/prometheus/tsdb/pull/539. + title: "Populate from three blocks that the last two are overlapping.", + inputSeriesSamples: [][]seriesSamples{ + { + { + lset: map[string]string{"before": "fix"}, + chunks: [][]sample{{{t: 0}, {t: 10}, {t: 11}, {t: 20}}}, + }, + { + lset: map[string]string{"after": "fix"}, + chunks: [][]sample{{{t: 0}, {t: 10}, {t: 11}, {t: 20}}}, + }, + }, + { + { + lset: map[string]string{"before": "fix"}, + chunks: [][]sample{{{t: 19}, {t: 30}}}, + }, + { + lset: map[string]string{"after": "fix"}, + chunks: [][]sample{{{t: 21}, {t: 30}}}, + }, + }, + { + { + lset: map[string]string{"before": "fix"}, + chunks: [][]sample{{{t: 27}, {t: 35}}}, + }, + { + lset: map[string]string{"after": "fix"}, + chunks: [][]sample{{{t: 27}, {t: 35}}}, + }, + }, + }, + expSeriesSamples: []seriesSamples{ + { + lset: map[string]string{"after": "fix"}, + chunks: [][]sample{{{t: 0}, {t: 10}, {t: 11}, {t: 20}}, {{t: 21}, {t: 27}, {t: 30}, {t: 35}}}, + }, + { + lset: map[string]string{"before": "fix"}, + chunks: [][]sample{{{t: 0}, {t: 10}, {t: 11}, {t: 19}, {t: 20}, {t: 27}, {t: 30}, {t: 35}}}, }, }, },