From 3c1911a2ee9add848fe4e8bb1995f2eda5be9ca7 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Sun, 16 Jun 2024 00:09:03 -0700 Subject: [PATCH] lint Signed-off-by: Ben Ye --- pkg/store/acceptance_test.go | 2 +- pkg/store/bucket_test.go | 38 ++++++++++------------------ pkg/store/storepb/testutil/series.go | 5 ++-- pkg/store/tsdb_test.go | 6 ++--- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/pkg/store/acceptance_test.go b/pkg/store/acceptance_test.go index fcf93073a3..4fd762c2d6 100644 --- a/pkg/store/acceptance_test.go +++ b/pkg/store/acceptance_test.go @@ -887,7 +887,7 @@ func TestBucketStore_Acceptance(t *testing.T) { } for _, replica := range []string{"r1", "r2"} { - id := createBlockFromHead(tt, auxDir, h) + id := storetestutil.CreateBlockFromHead(tt, auxDir, h) auxBlockDir := filepath.Join(auxDir, id.String()) meta, err := metadata.ReadFromDir(auxBlockDir) diff --git a/pkg/store/bucket_test.go b/pkg/store/bucket_test.go index 7afda70ebd..c0f9d5aa75 100644 --- a/pkg/store/bucket_test.go +++ b/pkg/store/bucket_test.go @@ -1197,7 +1197,7 @@ func uploadTestBlock(t testing.TB, tmpDir string, bkt objstore.Bucket, series in dir := filepath.Join(tmpDir, "tmp") testutil.Ok(t, os.MkdirAll(dir, os.ModePerm)) - id := createBlockFromHead(t, dir, h) + id := storetestutil.CreateBlockFromHead(t, dir, h) bdir := filepath.Join(dir, id.String()) meta, err := metadata.ReadFromDir(bdir) testutil.Ok(t, err) @@ -1238,18 +1238,6 @@ func appendTestData(t testing.TB, app storage.Appender, series int) { testutil.Ok(t, app.Commit()) } -func createBlockFromHead(t testing.TB, dir string, head *tsdb.Head) ulid.ULID { - compactor, err := tsdb.NewLeveledCompactor(context.Background(), nil, log.NewNopLogger(), []int64{1000000}, nil, nil) - testutil.Ok(t, err) - testutil.Ok(t, os.MkdirAll(dir, 0777)) - - // Add +1 millisecond to block maxt because block intervals are half-open: [b.MinTime, b.MaxTime). - // Because of this block intervals are always +1 than the total samples it includes. - ulid, err := compactor.Write(dir, head, head.MinTime(), head.MaxTime()+1, nil) - testutil.Ok(t, err) - return ulid -} - // Very similar benchmark to ths: https://github.com/prometheus/prometheus/blob/1d1732bc25cc4b47f513cb98009a4eb91879f175/tsdb/querier_bench_test.go#L82, // but with postings results check when run as test. func benchmarkExpandedPostings( @@ -1498,7 +1486,7 @@ func benchBucketSeries(t testutil.TB, sampleType chunkenc.ValueType, skipChunk, SkipChunks: t.IsBenchmark() || skipChunk, SampleType: sampleType, }) - id := createBlockFromHead(t, blockDir, head) + id := storetestutil.CreateBlockFromHead(t, blockDir, head) testutil.Ok(t, head.Close()) blockIDDir := filepath.Join(blockDir, id.String()) meta, err := metadata.ReadFromDir(blockIDDir) @@ -1715,7 +1703,7 @@ func TestBucketSeries_OneBlock_InMemIndexCacheSegfault(t *testing.T) { testutil.Ok(t, app.Commit()) blockDir := filepath.Join(tmpDir, "tmp") - id := createBlockFromHead(t, blockDir, h) + id := storetestutil.CreateBlockFromHead(t, blockDir, h) meta, err := metadata.InjectThanos(log.NewNopLogger(), filepath.Join(blockDir, id.String()), thanosMeta, nil) testutil.Ok(t, err) @@ -1755,7 +1743,7 @@ func TestBucketSeries_OneBlock_InMemIndexCacheSegfault(t *testing.T) { testutil.Ok(t, app.Commit()) blockDir := filepath.Join(tmpDir, "tmp2") - id := createBlockFromHead(t, blockDir, h) + id := storetestutil.CreateBlockFromHead(t, blockDir, h) meta, err := metadata.InjectThanos(log.NewNopLogger(), filepath.Join(blockDir, id.String()), thanosMeta, nil) testutil.Ok(t, err) @@ -2049,7 +2037,7 @@ func TestSeries_BlockWithMultipleChunks(t *testing.T) { testutil.Ok(t, app.Commit()) } - blk := createBlockFromHead(t, headOpts.ChunkDirRoot, h) + blk := storetestutil.CreateBlockFromHead(t, headOpts.ChunkDirRoot, h) thanosMeta := metadata.Thanos{ Labels: labels.FromStrings("ext1", "1").Map(), @@ -2362,7 +2350,7 @@ func createBlockWithOneSeriesWithStep(t testutil.TB, dir string, lbls labels.Lab } testutil.Ok(t, app.Commit()) - return createBlockFromHead(t, dir, h) + return storetestutil.CreateBlockFromHead(t, dir, h) } func setupStoreForHintsTest(t *testing.T) (testutil.TB, *BucketStore, []*storepb.Series, []*storepb.Series, ulid.ULID, ulid.ULID, func()) { @@ -2399,7 +2387,7 @@ func setupStoreForHintsTest(t *testing.T) (testutil.TB, *BucketStore, []*storepb PrependLabels: extLset, Random: random, }) - block1 := createBlockFromHead(t, bktDir, head) + block1 := storetestutil.CreateBlockFromHead(t, bktDir, head) testutil.Ok(t, head.Close()) head2, seriesSet2 := storetestutil.CreateHeadWithSeries(t, 1, storetestutil.HeadGenOptions{ TSDBDir: filepath.Join(tmpDir, "1"), @@ -2408,7 +2396,7 @@ func setupStoreForHintsTest(t *testing.T) (testutil.TB, *BucketStore, []*storepb PrependLabels: extLset, Random: random, }) - block2 := createBlockFromHead(t, bktDir, head2) + block2 := storetestutil.CreateBlockFromHead(t, bktDir, head2) testutil.Ok(t, head2.Close()) for _, blockID := range []ulid.ULID{block1, block2} { @@ -2612,7 +2600,7 @@ func TestSeries_ChunksHaveHashRepresentation(t *testing.T) { } testutil.Ok(t, app.Commit()) - blk := createBlockFromHead(t, headOpts.ChunkDirRoot, h) + blk := storetestutil.CreateBlockFromHead(t, headOpts.ChunkDirRoot, h) thanosMeta := metadata.Thanos{ Labels: labels.FromStrings("ext1", "1").Map(), @@ -2811,7 +2799,7 @@ func prepareBucket(b *testing.B, resolutionLevel compact.ResolutionLevel) (*buck Random: rand.New(rand.NewSource(120)), SkipChunks: true, }) - blockID := createBlockFromHead(b, tmpDir, head) + blockID := storetestutil.CreateBlockFromHead(b, tmpDir, head) // Upload the block to the bucket. thanosMeta := metadata.Thanos{ @@ -3476,7 +3464,7 @@ func TestExpandedPostingsRace(t *testing.T) { Random: rand.New(rand.NewSource(120)), SkipChunks: true, }) - blockID := createBlockFromHead(t, tmpDir, head) + blockID := storetestutil.CreateBlockFromHead(t, tmpDir, head) bucketBlocks := make([]*bucketBlock, 0, blockCount) @@ -3612,7 +3600,7 @@ func TestBucketStoreDedupOnBlockSeriesSet(t *testing.T) { testutil.Ok(t, err) testutil.Ok(t, app.Commit()) - id := createBlockFromHead(t, auxDir, h) + id := storetestutil.CreateBlockFromHead(t, auxDir, h) auxBlockDir := filepath.Join(auxDir, id.String()) _, err = metadata.InjectThanos(log.NewNopLogger(), auxBlockDir, metadata.Thanos{ @@ -3831,7 +3819,7 @@ func TestBucketStoreStreamingSeriesLimit(t *testing.T) { testutil.Ok(t, err) testutil.Ok(t, app.Commit()) - id := createBlockFromHead(t, auxDir, h) + id := storetestutil.CreateBlockFromHead(t, auxDir, h) auxBlockDir := filepath.Join(auxDir, id.String()) _, err = metadata.InjectThanos(log.NewNopLogger(), auxBlockDir, metadata.Thanos{ diff --git a/pkg/store/storepb/testutil/series.go b/pkg/store/storepb/testutil/series.go index c5c4896bd7..d7d719e281 100644 --- a/pkg/store/storepb/testutil/series.go +++ b/pkg/store/storepb/testutil/series.go @@ -68,9 +68,10 @@ func CreateBlockFromHead(t testing.TB, dir string, head *tsdb.Head) ulid.ULID { // Add +1 millisecond to block maxt because block intervals are half-open: [b.MinTime, b.MaxTime). // Because of this block intervals are always +1 than the total samples it includes. - ulid, err := compactor.Write(dir, head, head.MinTime(), head.MaxTime()+1, nil) + ulids, err := compactor.Write(dir, head, head.MinTime(), head.MaxTime()+1, nil) testutil.Ok(t, err) - return ulid + testutil.Assert(t, len(ulids) > 0) + return ulids[0] } // CreateHeadWithSeries returns head filled with given samples and same series returned in separate list for assertion purposes. diff --git a/pkg/store/tsdb_test.go b/pkg/store/tsdb_test.go index 285d8bc37a..acd9daf02a 100644 --- a/pkg/store/tsdb_test.go +++ b/pkg/store/tsdb_test.go @@ -257,7 +257,7 @@ func TestTSDBStore_SeriesAccessWithDelegateClosing(t *testing.T) { Random: random, SkipChunks: true, }) - _ = createBlockFromHead(t, tmpDir, head) + _ = storetestutil.CreateBlockFromHead(t, tmpDir, head) testutil.Ok(t, head.Close()) head, _ = storetestutil.CreateHeadWithSeries(t, 1, storetestutil.HeadGenOptions{ @@ -426,7 +426,7 @@ func TestTSDBStore_SeriesAccessWithoutDelegateClosing(t *testing.T) { Random: random, SkipChunks: true, }) - _ = createBlockFromHead(t, tmpDir, head) + _ = storetestutil.CreateBlockFromHead(t, tmpDir, head) testutil.Ok(t, head.Close()) head, _ = storetestutil.CreateHeadWithSeries(t, 1, storetestutil.HeadGenOptions{ @@ -566,7 +566,7 @@ func benchTSDBStoreSeries(t testutil.TB, totalSamples, totalSeries int) { resps[j] = append(resps[j], storepb.NewSeriesResponse(created[i])) } - _ = createBlockFromHead(t, tmpDir, head) + _ = storetestutil.CreateBlockFromHead(t, tmpDir, head) testutil.Ok(t, head.Close()) }