Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
  • Loading branch information
fpetkovski committed Feb 13, 2023
1 parent 217f5d0 commit 3c704dc
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 33 deletions.
5 changes: 3 additions & 2 deletions pkg/block/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/prometheus/prometheus/tsdb/index"

"github.com/efficientgo/core/testutil"

"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/testutil/e2eutil"
)
Expand Down Expand Up @@ -76,10 +77,10 @@ func TestRewrite(t *testing.T) {
testutil.Ok(t, err)

for p := ir2.SortedPostings(all); p.Next(); {
var lset labels.Labels
var builder labels.ScratchBuilder
var chks []chunks.Meta

testutil.Ok(t, ir2.Series(p.At(), &lset, &chks))
testutil.Ok(t, ir2.Series(p.At(), &builder, &chks))
testutil.Equals(t, 1, len(chks))
}
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/compact/downsample/downsample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.uber.org/goleak"

"github.com/efficientgo/core/testutil"

"github.com/thanos-io/thanos/pkg/block"
"github.com/thanos-io/thanos/pkg/block/metadata"
)
Expand Down Expand Up @@ -475,9 +476,12 @@ func TestDownsample(t *testing.T) {
testutil.Ok(t, pall.Err())
testutil.Equals(t, 1, len(series))

var builder labels.ScratchBuilder
var lset labels.Labels
var chks []chunks.Meta
testutil.Ok(t, indexr.Series(series[0], &lset, &chks))
testutil.Ok(t, indexr.Series(series[0], &builder, &chks))

lset = builder.Labels()
testutil.Equals(t, labels.FromStrings("__name__", "a"), lset)

var got []map[AggrType][]sample
Expand Down Expand Up @@ -996,13 +1000,14 @@ func (b *memBlock) Postings(name string, val ...string) (index.Postings, error)
return index.NewListPostings(b.postings), nil
}

func (b *memBlock) Series(id storage.SeriesRef, lset *labels.Labels, chks *[]chunks.Meta) error {
func (b *memBlock) Series(id storage.SeriesRef, builder *labels.ScratchBuilder, chks *[]chunks.Meta) error {
if int(id) >= len(b.series) {
return errors.Wrapf(storage.ErrNotFound, "series with ID %d does not exist", id)
}
s := b.series[id]

*lset = append((*lset)[:0], s.lset...)
builder.Reset()
builder.Assign(s.lset)
*chks = append((*chks)[:0], s.chunks...)

return nil
Expand Down
5 changes: 4 additions & 1 deletion pkg/compactv2/compactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/prometheus/prometheus/tsdb/tombstones"

"github.com/efficientgo/core/testutil"

"github.com/thanos-io/thanos/pkg/block"
"github.com/thanos-io/thanos/pkg/block/metadata"
)
Expand Down Expand Up @@ -662,11 +663,13 @@ func readBlockSeries(t *testing.T, bDir string) []seriesSamples {
testutil.Ok(t, err)
all = indexr.SortedPostings(all)

var builder labels.ScratchBuilder
var series []seriesSamples
var chks []chunks.Meta
for all.Next() {
s := seriesSamples{}
testutil.Ok(t, indexr.Series(all.At(), &s.lset, &chks))
testutil.Ok(t, indexr.Series(all.At(), &builder, &chks))
s.lset = builder.Labels()

for _, c := range chks {
c.Chunk, err = chunkr.Chunk(c)
Expand Down
41 changes: 21 additions & 20 deletions pkg/dedup/chunk_iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/prometheus/prometheus/tsdb/tsdbutil"

"github.com/efficientgo/core/testutil"

"github.com/thanos-io/thanos/pkg/compact/downsample"
)

Expand Down Expand Up @@ -135,8 +136,8 @@ func TestDedupChunkSeriesMerger(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
merged := m(tc.input...)
testutil.Equals(t, tc.expected.Labels(), merged.Labels())
actChks, actErr := storage.ExpandChunks(merged.Iterator())
expChks, expErr := storage.ExpandChunks(tc.expected.Iterator())
actChks, actErr := storage.ExpandChunks(merged.Iterator(nil))
expChks, expErr := storage.ExpandChunks(tc.expected.Iterator(nil))

testutil.Equals(t, expErr, actErr)
testutil.Equals(t, expChks, actChks)
Expand Down Expand Up @@ -166,14 +167,14 @@ func TestDedupChunkSeriesMergerDownsampledChunks(t *testing.T) {
input: []storage.ChunkSeries{
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(emptySamples, downsample.ResLevel1)...)
},
},
},
expected: &storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator()
},
},
Expand All @@ -183,14 +184,14 @@ func TestDedupChunkSeriesMergerDownsampledChunks(t *testing.T) {
input: []storage.ChunkSeries{
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(samples1, downsample.ResLevel1)...)
},
},
},
expected: &storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(samples1, downsample.ResLevel1)...)
},
},
Expand All @@ -200,20 +201,20 @@ func TestDedupChunkSeriesMergerDownsampledChunks(t *testing.T) {
input: []storage.ChunkSeries{
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(emptySamples, downsample.ResLevel1)...)
},
},
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(emptySamples, downsample.ResLevel1)...)
},
},
},
expected: &storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator()
},
},
Expand All @@ -223,20 +224,20 @@ func TestDedupChunkSeriesMergerDownsampledChunks(t *testing.T) {
input: []storage.ChunkSeries{
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(samples1, downsample.ResLevel1)...)
},
},
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(samples2, downsample.ResLevel1)...)
},
},
},
expected: &storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(
append(downsample.DownsampleRaw(samples1, downsample.ResLevel1),
downsample.DownsampleRaw(samples2, downsample.ResLevel1)...)...)
Expand All @@ -249,20 +250,20 @@ func TestDedupChunkSeriesMergerDownsampledChunks(t *testing.T) {
input: []storage.ChunkSeries{
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(samples1, downsample.ResLevel1)...)
},
},
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(samples1, downsample.ResLevel1)...)
},
},
},
expected: &storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(
downsample.DownsampleRaw(samples1, downsample.ResLevel1)...)
},
Expand All @@ -273,20 +274,20 @@ func TestDedupChunkSeriesMergerDownsampledChunks(t *testing.T) {
input: []storage.ChunkSeries{
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(samples1, downsample.ResLevel1)...)
},
},
&storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(downsample.DownsampleRaw(samples3, downsample.ResLevel1)...)
},
},
},
expected: &storage.ChunkSeriesEntry{
Lset: defaultLabels,
ChunkIteratorFn: func() chunks.Iterator {
ChunkIteratorFn: func(chunks.Iterator) chunks.Iterator {
return storage.NewListChunkSeriesIterator(chunks.Meta{
MinTime: 299999,
MaxTime: 540000,
Expand All @@ -305,8 +306,8 @@ func TestDedupChunkSeriesMergerDownsampledChunks(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
merged := m(tc.input...)
testutil.Equals(t, tc.expected.Labels(), merged.Labels())
actChks, actErr := storage.ExpandChunks(merged.Iterator())
expChks, expErr := storage.ExpandChunks(tc.expected.Iterator())
actChks, actErr := storage.ExpandChunks(merged.Iterator(nil))
expChks, expErr := storage.ExpandChunks(tc.expected.Iterator(nil))

testutil.Equals(t, expErr, actErr)
testutil.Equals(t, expChks, actChks)
Expand Down
4 changes: 2 additions & 2 deletions pkg/dedup/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type series struct {
}

func (s series) Labels() labels.Labels { return s.lset }
func (s series) Iterator() chunkenc.Iterator {
func (s series) Iterator(chunkenc.Iterator) chunkenc.Iterator {
return newMockedSeriesIterator(s.samples)
}

Expand Down Expand Up @@ -477,7 +477,7 @@ func TestDedupSeriesSet(t *testing.T) {

for i, s := range ats {
testutil.Equals(t, tcase.exp[i].lset, s.Labels(), "labels mismatch for series %v", i)
res := expandSeries(t, s.Iterator())
res := expandSeries(t, s.Iterator(nil))
testutil.Equals(t, tcase.exp[i].samples, res, "values mismatch for series :%v", i)
}
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/query/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/prometheus/prometheus/util/gate"

"github.com/efficientgo/core/testutil"

"github.com/thanos-io/thanos/pkg/component"
"github.com/thanos-io/thanos/pkg/dedup"
"github.com/thanos-io/thanos/pkg/store"
Expand Down Expand Up @@ -689,7 +690,7 @@ func testSelectResponse(t *testing.T, expected []series, res storage.SeriesSet)

for i, s := range series {
testutil.Equals(t, expected[i].lset, s.Labels())
samples := expandSeries(t, s.Iterator())
samples := expandSeries(t, s.Iterator(nil))
expectedCpy := make([]sample, 0, len(expected[i].samples))
for _, s := range expected[i].samples {
v := s.v
Expand Down
5 changes: 3 additions & 2 deletions pkg/query/query_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/prometheus/prometheus/tsdb/chunkenc"

"github.com/efficientgo/core/testutil"

"github.com/thanos-io/thanos/pkg/gate"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/store/storepb"
Expand Down Expand Up @@ -129,7 +130,7 @@ func testSelect(t testutil.TB, q *querier, expectedSeries []labels.Labels) {
gotSeriesCount++

// This is when resource usage should actually start growing.
iter := s.Iterator()
iter := s.Iterator(nil)
for iter.Next() != chunkenc.ValNone {
testT, testV = iter.At()
}
Expand All @@ -145,7 +146,7 @@ func testSelect(t testutil.TB, q *querier, expectedSeries []labels.Labels) {
gotSeries = append(gotSeries, s.Labels())

// This is when resource usage should actually start growing.
iter := s.Iterator()
iter := s.Iterator(nil)
for iter.Next() != chunkenc.ValNone {
testT, testV = iter.At()
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/rules/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"gopkg.in/yaml.v3"

"github.com/efficientgo/core/testutil"

"github.com/thanos-io/thanos/pkg/extprom"
"github.com/thanos-io/thanos/pkg/runutil"
"github.com/thanos-io/thanos/pkg/store/storepb"
Expand All @@ -45,7 +46,7 @@ func (n nopAppender) AppendExemplar(storage.SeriesRef, labels.Labels, exemplar.E
return 0, nil
}

func (n nopAppender) AppendHistogram(ref storage.SeriesRef, l labels.Labels, t int64, h *histogram.Histogram) (storage.SeriesRef, error) {
func (n nopAppender) AppendHistogram(ref storage.SeriesRef, l labels.Labels, t int64, h *histogram.Histogram, fh *histogram.FloatHistogram) (storage.SeriesRef, error) {
return 0, nil
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/store/storepb/testutil/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/prometheus/prometheus/tsdb/wlog"

"github.com/efficientgo/core/testutil"

"github.com/thanos-io/thanos/pkg/store/hintspb"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/store/storepb"
Expand Down Expand Up @@ -121,9 +122,12 @@ func CreateHeadWithSeries(t testing.TB, j int, opts HeadGenOptions) (*tsdb.Head,
expected = make([]*storepb.Series, 0, opts.Series)
)

var builder labels.ScratchBuilder

all := allPostings(t, ir)
for all.Next() {
testutil.Ok(t, ir.Series(all.At(), &lset, &chunkMetas))
testutil.Ok(t, ir.Series(all.At(), &builder, &chunkMetas))
lset = builder.Labels()
expected = append(expected, &storepb.Series{Labels: labelpb.ZLabelsFromPromLabels(append(opts.PrependLabels.Copy(), lset...))})

if opts.SkipChunks {
Expand Down

0 comments on commit 3c704dc

Please sign in to comment.