Skip to content

Commit

Permalink
blocksconvert: Set compaction sources correctly (#3122)
Browse files Browse the repository at this point in the history
* Set compaction sources correctly, otherwise compactor deletes these blocks.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>

* Added test showing that deduplication filter doesn't remove the block anymore.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>

* Make lint happy.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
  • Loading branch information
pstibrany committed Sep 14, 2020
1 parent f6122f4 commit df09540
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/blocksconvert/builder/tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func (d *tsdbBuilder) finishBlock(source string, labels map[string]string) (ulid
Version: 1,
MinTime: math.MaxInt64,
MaxTime: math.MinInt64,
Compaction: tsdb.BlockMetaCompaction{
Level: 1,
Sources: []ulid.ULID{d.ulid},
},
},

Thanos: metadata.Thanos{
Expand Down
33 changes: 33 additions & 0 deletions tools/blocksconvert/builder/tsdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ import (
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"sync"
"testing"
"time"

"github.com/oklog/ulid"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/tsdb"
"github.com/stretchr/testify/require"
"github.com/thanos-io/thanos/pkg/block"
"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/extprom"
"go.uber.org/atomic"

"github.com/cortexproject/cortex/pkg/chunk"
Expand Down Expand Up @@ -78,6 +83,7 @@ func TestTsdbBuilder(t *testing.T) {
blocks := db.Blocks()
require.Equal(t, 1, len(blocks))
require.Equal(t, id, blocks[0].Meta().ULID)
require.Equal(t, id, blocks[0].Meta().Compaction.Sources[0])
require.Equal(t, uint64(seriesCount), blocks[0].Meta().Stats.NumSeries)
require.Equal(t, uint64(totalSamples.Load()), blocks[0].Meta().Stats.NumSamples)

Expand Down Expand Up @@ -107,6 +113,33 @@ func TestTsdbBuilder(t *testing.T) {
require.NoError(t, q.Close())

require.NoError(t, db.Close())

m, err := metadata.Read(filepath.Join(dir, id.String()))
require.NoError(t, err)

otherID := ulid.MustNew(ulid.Now(), nil)

// Make sure that deduplicate filter doesn't remove this block (thanks to correct sources).
df := block.NewDeduplicateFilter()
inp := map[ulid.ULID]*metadata.Meta{
otherID: {
BlockMeta: tsdb.BlockMeta{
ULID: otherID,
MinTime: 0,
MaxTime: 0,
Compaction: tsdb.BlockMetaCompaction{
Sources: []ulid.ULID{otherID},
},
Version: 0,
},
},

id: m,
}

err = df.Filter(context.Background(), inp, extprom.NewTxGaugeVec(nil, prometheus.GaugeOpts{}, []string{"state"}))
require.NoError(t, err)
require.NotNil(t, inp[id])
}

func metricInfo(ix int) (labels.Labels, int) {
Expand Down

0 comments on commit df09540

Please sign in to comment.