From 44057f0a819250653848b6d7026933f92e997b45 Mon Sep 17 00:00:00 2001 From: Mauro Stettler Date: Mon, 15 Feb 2021 19:20:41 +0000 Subject: [PATCH] fix tests Signed-off-by: Mauro Stettler --- pkg/store/bucket_test.go | 30 ++++++++++++++++++---------- pkg/store/postings_codec_test.go | 6 ++++-- pkg/store/storepb/testutil/series.go | 4 +++- pkg/testutil/e2eutil/prometheus.go | 9 +++++---- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/pkg/store/bucket_test.go b/pkg/store/bucket_test.go index ac9a33ffcb6..8f5af9ab0ee 100644 --- a/pkg/store/bucket_test.go +++ b/pkg/store/bucket_test.go @@ -34,7 +34,6 @@ import ( "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/tsdb/chunkenc" - "github.com/prometheus/prometheus/tsdb/chunks" "github.com/prometheus/prometheus/tsdb/encoding" "go.uber.org/atomic" @@ -1025,7 +1024,10 @@ func BenchmarkBucketIndexReader_ExpandedPostings(b *testing.B) { } func uploadTestBlock(t testing.TB, tmpDir string, bkt objstore.Bucket, series int) ulid.ULID { - h, err := tsdb.NewHead(nil, nil, nil, 1000, tmpDir, nil, chunks.DefaultWriteBufferSize, tsdb.DefaultStripeSize, nil) + headOpts := tsdb.DefaultHeadOptions() + headOpts.ChunkDirRoot = tmpDir + headOpts.ChunkRange = 1000 + h, err := tsdb.NewHead(nil, nil, nil, headOpts) testutil.Ok(t, err) defer func() { testutil.Ok(t, h.Close()) @@ -1396,13 +1398,16 @@ func TestBucketSeries_OneBlock_InMemIndexCacheSegfault(t *testing.T) { var b1 *bucketBlock const numSeries = 100 + headOpts := tsdb.DefaultHeadOptions() + headOpts.ChunkDirRoot = tmpDir + headOpts.ChunkRange = 1 // Create 4 blocks. Each will have numSeriesPerBlock number of series that have 1 sample only. // Timestamp will be counted for each new series, so each series will have unique timestamp. // This allows to pick time range that will correspond to number of series picked 1:1. { // Block 1. - h, err := tsdb.NewHead(nil, nil, nil, 1, tmpDir, nil, chunks.DefaultWriteBufferSize, tsdb.DefaultStripeSize, nil) + h, err := tsdb.NewHead(nil, nil, nil, headOpts) testutil.Ok(t, err) defer func() { testutil.Ok(t, h.Close()) }() @@ -1441,7 +1446,7 @@ func TestBucketSeries_OneBlock_InMemIndexCacheSegfault(t *testing.T) { var b2 *bucketBlock { // Block 2, do not load this block yet. - h, err := tsdb.NewHead(nil, nil, nil, 1, tmpDir, nil, chunks.DefaultWriteBufferSize, tsdb.DefaultStripeSize, nil) + h, err := tsdb.NewHead(nil, nil, nil, headOpts) testutil.Ok(t, err) defer func() { testutil.Ok(t, h.Close()) }() @@ -1686,9 +1691,11 @@ func TestSeries_BlockWithMultipleChunks(t *testing.T) { // Create a block with 1 series but an high number of samples, // so that they will span across multiple chunks. - blkDir := filepath.Join(tmpDir, "block") + headOpts := tsdb.DefaultHeadOptions() + headOpts.ChunkDirRoot = filepath.Join(tmpDir, "block") + headOpts.ChunkRange = 10000000000 - h, err := tsdb.NewHead(nil, nil, nil, 10000000000, blkDir, nil, chunks.DefaultWriteBufferSize, tsdb.DefaultStripeSize, nil) + h, err := tsdb.NewHead(nil, nil, nil, headOpts) testutil.Ok(t, err) defer func() { testutil.Ok(t, h.Close()) }() @@ -1702,7 +1709,7 @@ func TestSeries_BlockWithMultipleChunks(t *testing.T) { testutil.Ok(t, app.Commit()) } - blk := createBlockFromHead(t, blkDir, h) + blk := createBlockFromHead(t, headOpts.ChunkDirRoot, h) thanosMeta := metadata.Thanos{ Labels: labels.Labels{{Name: "ext1", Value: "1"}}.Map(), @@ -1710,7 +1717,7 @@ func TestSeries_BlockWithMultipleChunks(t *testing.T) { Source: metadata.TestSource, } - _, err = metadata.InjectThanos(log.NewNopLogger(), filepath.Join(blkDir, blk.String()), thanosMeta, nil) + _, err = metadata.InjectThanos(log.NewNopLogger(), filepath.Join(headOpts.ChunkDirRoot, blk.String()), thanosMeta, nil) testutil.Ok(t, err) // Create a bucket and upload the block there. @@ -1721,7 +1728,7 @@ func TestSeries_BlockWithMultipleChunks(t *testing.T) { instrBkt := objstore.WithNoopInstr(bkt) logger := log.NewNopLogger() - testutil.Ok(t, block.Upload(context.Background(), logger, bkt, filepath.Join(blkDir, blk.String()))) + testutil.Ok(t, block.Upload(context.Background(), logger, bkt, filepath.Join(headOpts.ChunkDirRoot, blk.String()))) // Instance a real bucket store we'll use to query the series. fetcher, err := block.NewMetaFetcher(logger, 10, instrBkt, tmpDir, nil, nil, nil) @@ -1959,7 +1966,10 @@ func createBlockWithLargeChunk(t testutil.TB, dir string, lbls labels.Labels, ra } func createBlockWithOneSeriesWithStep(t testutil.TB, dir string, lbls labels.Labels, blockIndex int, totalSamples int, random *rand.Rand, step int64) ulid.ULID { - h, err := tsdb.NewHead(nil, nil, nil, int64(totalSamples)*step, dir, nil, chunks.DefaultWriteBufferSize, tsdb.DefaultStripeSize, nil) + headOpts := tsdb.DefaultHeadOptions() + headOpts.ChunkDirRoot = dir + headOpts.ChunkRange = int64(totalSamples) * step + h, err := tsdb.NewHead(nil, nil, nil, headOpts) testutil.Ok(t, err) defer func() { testutil.Ok(t, h.Close()) }() diff --git a/pkg/store/postings_codec_test.go b/pkg/store/postings_codec_test.go index 4b9f69fec0d..d343f94ca93 100644 --- a/pkg/store/postings_codec_test.go +++ b/pkg/store/postings_codec_test.go @@ -14,7 +14,6 @@ import ( "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/tsdb" - "github.com/prometheus/prometheus/tsdb/chunks" "github.com/prometheus/prometheus/tsdb/index" storetestutil "github.com/thanos-io/thanos/pkg/store/storepb/testutil" "github.com/thanos-io/thanos/pkg/testutil" @@ -24,7 +23,10 @@ func TestDiffVarintCodec(t *testing.T) { chunksDir, err := ioutil.TempDir("", "diff_varint_codec") testutil.Ok(t, err) - h, err := tsdb.NewHead(nil, nil, nil, 1000, chunksDir, nil, chunks.DefaultWriteBufferSize, tsdb.DefaultStripeSize, nil) + headOpts := tsdb.DefaultHeadOptions() + headOpts.ChunkDirRoot = chunksDir + headOpts.ChunkRange = 1000 + h, err := tsdb.NewHead(nil, nil, nil, headOpts) testutil.Ok(t, err) defer func() { testutil.Ok(t, h.Close()) diff --git a/pkg/store/storepb/testutil/series.go b/pkg/store/storepb/testutil/series.go index b1102e7e0e1..e7dae990edf 100644 --- a/pkg/store/storepb/testutil/series.go +++ b/pkg/store/storepb/testutil/series.go @@ -69,7 +69,9 @@ func CreateHeadWithSeries(t testing.TB, j int, opts HeadGenOptions) (*tsdb.Head, testutil.Ok(t, os.MkdirAll(filepath.Join(opts.TSDBDir, "wal"), os.ModePerm)) } - h, err := tsdb.NewHead(nil, nil, w, tsdb.DefaultBlockDuration, opts.TSDBDir, nil, chunks.DefaultWriteBufferSize, tsdb.DefaultStripeSize, nil) + headOpts := tsdb.DefaultHeadOptions() + headOpts.ChunkDirRoot = opts.TSDBDir + h, err := tsdb.NewHead(nil, nil, w, headOpts) testutil.Ok(t, err) app := h.Appender(context.Background()) diff --git a/pkg/testutil/e2eutil/prometheus.go b/pkg/testutil/e2eutil/prometheus.go index 9274f15d098..59f0552384a 100644 --- a/pkg/testutil/e2eutil/prometheus.go +++ b/pkg/testutil/e2eutil/prometheus.go @@ -29,7 +29,6 @@ import ( "github.com/prometheus/prometheus/pkg/timestamp" "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/tsdb" - "github.com/prometheus/prometheus/tsdb/chunks" "github.com/prometheus/prometheus/tsdb/index" "golang.org/x/sync/errgroup" @@ -409,14 +408,16 @@ func createBlock( resolution int64, tombstones bool, ) (id ulid.ULID, err error) { - chunksRootDir := filepath.Join(dir, "chunks") - h, err := tsdb.NewHead(nil, nil, nil, 10000000000, chunksRootDir, nil, chunks.DefaultWriteBufferSize, tsdb.DefaultStripeSize, nil) + headOpts := tsdb.DefaultHeadOptions() + headOpts.ChunkDirRoot = filepath.Join(dir, "chunks") + headOpts.ChunkRange = 10000000000 + h, err := tsdb.NewHead(nil, nil, nil, headOpts) if err != nil { return id, errors.Wrap(err, "create head block") } defer func() { runutil.CloseWithErrCapture(&err, h, "TSDB Head") - if e := os.RemoveAll(chunksRootDir); e != nil { + if e := os.RemoveAll(headOpts.ChunkDirRoot); e != nil { err = errors.Wrap(e, "delete chunks dir") } }()