@@ -14,6 +14,7 @@ import (
1414 "github.com/prometheus/prometheus/tsdb/chunkenc"
1515 "github.com/stretchr/testify/assert"
1616 "github.com/stretchr/testify/require"
17+ "github.com/thanos-io/thanos/pkg/store/labelpb"
1718 "github.com/thanos-io/thanos/pkg/store/storepb"
1819
1920 "github.com/cortexproject/cortex/pkg/util"
@@ -39,7 +40,7 @@ func TestBlockQuerierSeries(t *testing.T) {
3940 },
4041 "should return series on success" : {
4142 series : & storepb.Series {
42- Labels : []storepb. Label {
43+ Labels : []labelpb. ZLabel {
4344 {Name : "foo" , Value : "bar" },
4445 },
4546 Chunks : []storepb.AggrChunk {
@@ -56,7 +57,7 @@ func TestBlockQuerierSeries(t *testing.T) {
5657 },
5758 "should return error on failure while reading encoded chunk data" : {
5859 series : & storepb.Series {
59- Labels : []storepb. Label {{Name : "foo" , Value : "bar" }},
60+ Labels : []labelpb. ZLabel {{Name : "foo" , Value : "bar" }},
6061 Chunks : []storepb.AggrChunk {
6162 {MinTime : minTimestamp .Unix () * 1000 , MaxTime : maxTimestamp .Unix () * 1000 , Raw : & storepb.Chunk {Type : storepb .Chunk_XOR , Data : []byte {0 , 1 }}},
6263 },
@@ -70,7 +71,7 @@ func TestBlockQuerierSeries(t *testing.T) {
7071 testData := testData
7172
7273 t .Run (testName , func (t * testing.T ) {
73- series := newBlockQuerierSeries (testData .series .Labels , testData .series .Chunks )
74+ series := newBlockQuerierSeries (labelpb . ZLabelsToPromLabels ( testData .series .Labels ) , testData .series .Chunks )
7475
7576 assert .Equal (t , testData .expectedMetric , series .Labels ())
7677
@@ -119,23 +120,23 @@ func TestBlockQuerierSeriesSet(t *testing.T) {
119120 series : []* storepb.Series {
120121 // first, with one chunk.
121122 {
122- Labels : mkLabels ("__name__" , "first" , "a" , "a" ),
123+ Labels : mkZLabels ("__name__" , "first" , "a" , "a" ),
123124 Chunks : []storepb.AggrChunk {
124125 createAggrChunkWithSineSamples (now , now .Add (100 * time .Second ), 3 * time .Millisecond ), // ceil(100 / 0.003) samples (= 33334)
125126 },
126127 },
127128
128129 // continuation of previous series. Must have exact same labels.
129130 {
130- Labels : mkLabels ("__name__" , "first" , "a" , "a" ),
131+ Labels : mkZLabels ("__name__" , "first" , "a" , "a" ),
131132 Chunks : []storepb.AggrChunk {
132133 createAggrChunkWithSineSamples (now .Add (100 * time .Second ), now .Add (200 * time .Second ), 3 * time .Millisecond ), // ceil(100 / 0.003) samples more, 66668 in total
133134 },
134135 },
135136
136137 // second, with multiple chunks
137138 {
138- Labels : mkLabels ("__name__" , "second" ),
139+ Labels : mkZLabels ("__name__" , "second" ),
139140 Chunks : []storepb.AggrChunk {
140141 // unordered chunks
141142 createAggrChunkWithSineSamples (now .Add (400 * time .Second ), now .Add (600 * time .Second ), 5 * time .Millisecond ), // 200 / 0.005 (= 40000 samples, = 120000 in total)
@@ -146,13 +147,13 @@ func TestBlockQuerierSeriesSet(t *testing.T) {
146147
147148 // overlapping
148149 {
149- Labels : mkLabels ("__name__" , "overlapping" ),
150+ Labels : mkZLabels ("__name__" , "overlapping" ),
150151 Chunks : []storepb.AggrChunk {
151152 createAggrChunkWithSineSamples (now , now .Add (10 * time .Second ), 5 * time .Millisecond ), // 10 / 0.005 = 2000 samples
152153 },
153154 },
154155 {
155- Labels : mkLabels ("__name__" , "overlapping" ),
156+ Labels : mkZLabels ("__name__" , "overlapping" ),
156157 Chunks : []storepb.AggrChunk {
157158 // 10 / 0.005 = 2000 samples, but first 1000 are overlapping with previous series, so this chunk only contributes 1000
158159 createAggrChunkWithSineSamples (now .Add (5 * time .Second ), now .Add (15 * time .Second ), 5 * time .Millisecond ),
@@ -161,29 +162,29 @@ func TestBlockQuerierSeriesSet(t *testing.T) {
161162
162163 // overlapping 2. Chunks here come in wrong order.
163164 {
164- Labels : mkLabels ("__name__" , "overlapping2" ),
165+ Labels : mkZLabels ("__name__" , "overlapping2" ),
165166 Chunks : []storepb.AggrChunk {
166167 // entire range overlaps with the next chunk, so this chunks contributes 0 samples (it will be sorted as second)
167168 createAggrChunkWithSineSamples (now .Add (3 * time .Second ), now .Add (7 * time .Second ), 5 * time .Millisecond ),
168169 },
169170 },
170171 {
171- Labels : mkLabels ("__name__" , "overlapping2" ),
172+ Labels : mkZLabels ("__name__" , "overlapping2" ),
172173 Chunks : []storepb.AggrChunk {
173174 // this chunk has completely overlaps previous chunk. Since its minTime is lower, it will be sorted as first.
174175 createAggrChunkWithSineSamples (now , now .Add (10 * time .Second ), 5 * time .Millisecond ), // 10 / 0.005 = 2000 samples
175176 },
176177 },
177178 {
178- Labels : mkLabels ("__name__" , "overlapping2" ),
179+ Labels : mkZLabels ("__name__" , "overlapping2" ),
179180 Chunks : []storepb.AggrChunk {
180181 // no samples
181182 createAggrChunkWithSineSamples (now , now , 5 * time .Millisecond ),
182183 },
183184 },
184185
185186 {
186- Labels : mkLabels ("__name__" , "overlapping2" ),
187+ Labels : mkZLabels ("__name__" , "overlapping2" ),
187188 Chunks : []storepb.AggrChunk {
188189 // 2000 samples more (10 / 0.005)
189190 createAggrChunkWithSineSamples (now .Add (20 * time .Second ), now .Add (30 * time .Second ), 5 * time .Millisecond ),
@@ -262,11 +263,11 @@ func createAggrChunk(minTime, maxTime int64, samples ...promql.Point) storepb.Ag
262263 }
263264}
264265
265- func mkLabels (s ... string ) []storepb. Label {
266- result := []storepb. Label {}
266+ func mkZLabels (s ... string ) []labelpb. ZLabel {
267+ var result []labelpb. ZLabel
267268
268269 for i := 0 ; i + 1 < len (s ); i = i + 2 {
269- result = append (result , storepb. Label {
270+ result = append (result , labelpb. ZLabel {
270271 Name : s [i ],
271272 Value : s [i + 1 ],
272273 })
@@ -275,6 +276,10 @@ func mkLabels(s ...string) []storepb.Label {
275276 return result
276277}
277278
279+ func mkLabels (s ... string ) []labels.Label {
280+ return labelpb .ZLabelsToPromLabels (mkZLabels (s ... ))
281+ }
282+
278283func Benchmark_newBlockQuerierSeries (b * testing.B ) {
279284 lbls := mkLabels (
280285 "__name__" , "test" ,
@@ -308,7 +313,7 @@ func Benchmark_blockQuerierSeriesSet_iteration(b *testing.B) {
308313 // Generate series.
309314 series := make ([]* storepb.Series , 0 , numSeries )
310315 for seriesID := 0 ; seriesID < numSeries ; seriesID ++ {
311- lbls := mkLabels ("__name__" , "test" , "series_id" , strconv .Itoa (seriesID ))
316+ lbls := mkZLabels ("__name__" , "test" , "series_id" , strconv .Itoa (seriesID ))
312317 chunks := make ([]storepb.AggrChunk , 0 , numChunksPerSeries )
313318
314319 // Create chunks with 1 sample per second.
0 commit comments