Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 committed Jun 16, 2024
1 parent 6c20c67 commit 3c1911a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pkg/store/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 13 additions & 25 deletions pkg/store/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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"),
Expand All @@ -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} {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions pkg/store/storepb/testutil/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/store/tsdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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())
}

Expand Down

0 comments on commit 3c1911a

Please sign in to comment.