Skip to content

Commit 6907f16

Browse files
pracuccipstibrany
andauthored
Upgrade Thanos to latest master (#3363)
* Update Thanos to latest master. Signed-off-by: Peter Štibraný <[email protected]> * Added forgotten files Signed-off-by: Peter Štibraný <[email protected]> * Go mod tidy, vendor Signed-off-by: Peter Štibraný <[email protected]> * Set segment files when finishing block. Signed-off-by: Peter Štibraný <[email protected]> * Upgraded Thanos to latest master Signed-off-by: Marco Pracucci <[email protected]> * Updated CHANGELOG Signed-off-by: Marco Pracucci <[email protected]> * Rebased master Signed-off-by: Marco Pracucci <[email protected]> Co-authored-by: Peter Štibraný <[email protected]>
1 parent be0606e commit 6907f16

File tree

42 files changed

+1719
-1799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1719
-1799
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
* [ENHANCEMENT] Ruler: only load rules that belong to the ruler. Improves rules synching performances when ruler sharding is enabled. #3269
8282
* [ENHANCEMENT] Added `-<prefix>.redis.tls-insecure-skip-verify` flag. #3298
8383
* [ENHANCEMENT] Added `cortex_alertmanager_config_last_reload_successful_seconds` metric to show timestamp of last successful AM config reload. #3289
84+
* [ENHANCEMENT] Blocks storage: reduced number of bucket listing operations to list block content (applies to newly created blocks only). #3363
8485
* [BUGFIX] No-longer-needed ingester operations for queries triggered by queriers and rulers are now canceled. #3178
8586
* [BUGFIX] Ruler: directories in the configured `rules-path` will be removed on startup and shutdown in order to ensure they don't persist between runs. #3195
8687
* [BUGFIX] Handle hash-collisions in the query path. #3192

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/Masterminds/squirrel v0.0.0-20161115235646-20f192218cf5
1111
github.com/NYTimes/gziphandler v1.1.1
1212
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d
13-
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
1413
github.com/alicebob/miniredis v2.5.0+incompatible
1514
github.com/armon/go-metrics v0.3.3
1615
github.com/aws/aws-sdk-go v1.35.5
@@ -53,10 +52,9 @@ require (
5352
github.com/sony/gobreaker v0.4.1
5453
github.com/spf13/afero v1.2.2
5554
github.com/stretchr/testify v1.6.1
56-
github.com/thanos-io/thanos v0.13.1-0.20200923175059-57035bf8f843
55+
github.com/thanos-io/thanos v0.13.1-0.20201019130456-f41940581d9a
5756
github.com/uber/jaeger-client-go v2.25.0+incompatible
5857
github.com/weaveworks/common v0.0.0-20200914083218-61ffdd448099
59-
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da // indirect
6058
go.etcd.io/bbolt v1.3.5-0.20200615073812-232d8fc87f50
6159
go.etcd.io/etcd v0.5.0-alpha.5.0.20200520232829-54ba9589114f
6260
go.uber.org/atomic v1.7.0

go.sum

Lines changed: 20 additions & 5 deletions
Large diffs are not rendered by default.

pkg/querier/block.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/prometheus/prometheus/pkg/labels"
99
"github.com/prometheus/prometheus/storage"
1010
"github.com/prometheus/prometheus/tsdb/chunkenc"
11+
"github.com/thanos-io/thanos/pkg/store/labelpb"
1112
"github.com/thanos-io/thanos/pkg/store/storepb"
1213

1314
"github.com/cortexproject/cortex/pkg/querier/series"
@@ -55,15 +56,15 @@ func (bqss *blockQuerierSeriesSet) Next() bool {
5556
return false
5657
}
5758

58-
currLabels := bqss.series[bqss.next].Labels
59+
currLabels := labelpb.ZLabelsToPromLabels(bqss.series[bqss.next].Labels)
5960
currChunks := bqss.series[bqss.next].Chunks
6061

6162
bqss.next++
6263

6364
// Merge chunks for current series. Chunks may come in multiple responses, but as soon
6465
// as the response has chunks for a new series, we can stop searching. Series are sorted.
6566
// See documentation for StoreClient.Series call for details.
66-
for bqss.next < len(bqss.series) && storepb.CompareLabels(currLabels, bqss.series[bqss.next].Labels) == 0 {
67+
for bqss.next < len(bqss.series) && labels.Compare(currLabels, labelpb.ZLabelsToPromLabels(bqss.series[bqss.next].Labels)) == 0 {
6768
currChunks = append(currChunks, bqss.series[bqss.next].Chunks...)
6869
bqss.next++
6970
}
@@ -85,12 +86,12 @@ func (bqss *blockQuerierSeriesSet) Warnings() storage.Warnings {
8586
}
8687

8788
// newBlockQuerierSeries makes a new blockQuerierSeries. Input labels must be already sorted by name.
88-
func newBlockQuerierSeries(lbls []storepb.Label, chunks []storepb.AggrChunk) *blockQuerierSeries {
89+
func newBlockQuerierSeries(lbls []labels.Label, chunks []storepb.AggrChunk) *blockQuerierSeries {
8990
sort.Slice(chunks, func(i, j int) bool {
9091
return chunks[i].MinTime < chunks[j].MinTime
9192
})
9293

93-
return &blockQuerierSeries{labels: storepb.LabelsToPromLabelsUnsafe(lbls), chunks: chunks}
94+
return &blockQuerierSeries{labels: lbls, chunks: chunks}
9495
}
9596

9697
type blockQuerierSeries struct {

pkg/querier/block_test.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
278283
func 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.

pkg/querier/blocks_store_queryable_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/stretchr/testify/require"
2525
"github.com/thanos-io/thanos/pkg/block/metadata"
2626
"github.com/thanos-io/thanos/pkg/store/hintspb"
27+
"github.com/thanos-io/thanos/pkg/store/labelpb"
2728
"github.com/thanos-io/thanos/pkg/store/storepb"
2829
"github.com/weaveworks/common/user"
2930
"google.golang.org/grpc"
@@ -624,8 +625,8 @@ func TestBlocksStoreQuerier_SelectSortedShouldHonorQueryStoreAfter(t *testing.T)
624625
func TestBlocksStoreQuerier_PromQLExecution(t *testing.T) {
625626
block1 := ulid.MustNew(1, nil)
626627
block2 := ulid.MustNew(2, nil)
627-
series1 := []storepb.Label{{Name: "__name__", Value: "metric_1"}}
628-
series2 := []storepb.Label{{Name: "__name__", Value: "metric_2"}}
628+
series1 := []labelpb.ZLabel{{Name: "__name__", Value: "metric_1"}}
629+
series2 := []labelpb.ZLabel{{Name: "__name__", Value: "metric_2"}}
629630

630631
series1Samples := []promql.Point{
631632
{T: 1589759955000, V: 1},
@@ -737,8 +738,8 @@ func TestBlocksStoreQuerier_PromQLExecution(t *testing.T) {
737738
require.NoError(t, err)
738739
require.Len(t, matrix, 2)
739740

740-
assert.Equal(t, storepb.LabelsToPromLabels(series1), matrix[0].Metric)
741-
assert.Equal(t, storepb.LabelsToPromLabels(series2), matrix[1].Metric)
741+
assert.Equal(t, labelpb.ZLabelsToPromLabels(series1), matrix[0].Metric)
742+
assert.Equal(t, labelpb.ZLabelsToPromLabels(series2), matrix[1].Metric)
742743
assert.Equal(t, series1Samples, matrix[0].Points)
743744
assert.Equal(t, series2Samples, matrix[1].Points)
744745
}
@@ -840,7 +841,7 @@ func mockSeriesResponse(lbls labels.Labels, timeMillis int64, value float64) *st
840841
return &storepb.SeriesResponse{
841842
Result: &storepb.SeriesResponse_Series{
842843
Series: &storepb.Series{
843-
Labels: storepb.PromLabelsToLabels(lbls),
844+
Labels: labelpb.ZLabelsFromPromLabels(lbls),
844845
Chunks: []storepb.AggrChunk{
845846
{MinTime: timeMillis, MaxTime: timeMillis, Raw: &storepb.Chunk{Type: storepb.Chunk_XOR, Data: chunkData}},
846847
},

pkg/storegateway/bucket_stores_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/stretchr/testify/mock"
1919
"github.com/stretchr/testify/require"
2020
"github.com/thanos-io/thanos/pkg/store"
21+
"github.com/thanos-io/thanos/pkg/store/labelpb"
2122
"github.com/thanos-io/thanos/pkg/store/storepb"
2223
"github.com/weaveworks/common/logging"
2324
"go.uber.org/atomic"
@@ -68,7 +69,7 @@ func TestBucketStores_InitialSync(t *testing.T) {
6869
require.NoError(t, err)
6970
assert.Empty(t, warnings)
7071
require.Len(t, seriesSet, 1)
71-
assert.Equal(t, []storepb.Label{{Name: labels.MetricName, Value: metricName}}, seriesSet[0].Labels)
72+
assert.Equal(t, []labelpb.ZLabel{{Name: labels.MetricName, Value: metricName}}, seriesSet[0].Labels)
7273
}
7374

7475
// Query series of another user.
@@ -146,7 +147,7 @@ func TestBucketStores_SyncBlocks(t *testing.T) {
146147
require.NoError(t, err)
147148
assert.Empty(t, warnings)
148149
assert.Len(t, seriesSet, 1)
149-
assert.Equal(t, []storepb.Label{{Name: labels.MetricName, Value: metricName}}, seriesSet[0].Labels)
150+
assert.Equal(t, []labelpb.ZLabel{{Name: labels.MetricName, Value: metricName}}, seriesSet[0].Labels)
150151

151152
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
152153
# HELP cortex_bucket_store_blocks_loaded Number of currently loaded blocks.

pkg/storegateway/gateway_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/stretchr/testify/require"
2626
"github.com/thanos-io/thanos/pkg/block/metadata"
2727
"github.com/thanos-io/thanos/pkg/extprom"
28+
"github.com/thanos-io/thanos/pkg/store/labelpb"
2829
"github.com/thanos-io/thanos/pkg/store/storepb"
2930

3031
"github.com/cortexproject/cortex/pkg/ring"
@@ -695,7 +696,7 @@ func TestStoreGateway_SeriesQueryingShouldRemoveExternalLabels(t *testing.T) {
695696
actual := srv.SeriesSet[seriesID]
696697

697698
// Ensure Cortex external labels have been removed.
698-
assert.Equal(t, []storepb.Label{{Name: "series_id", Value: strconv.Itoa(seriesID)}}, actual.Labels)
699+
assert.Equal(t, []labelpb.ZLabel{{Name: "series_id", Value: strconv.Itoa(seriesID)}}, actual.Labels)
699700

700701
// Ensure samples have been correctly queried. The Thanos store also deduplicate samples
701702
// in most cases, but it's not strictly required guaranteeing deduplication at this stage.

tools/blocksconvert/builder/tsdb.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/prometheus/prometheus/tsdb/chunkenc"
2020
"github.com/prometheus/prometheus/tsdb/chunks"
2121
"github.com/prometheus/prometheus/tsdb/index"
22+
"github.com/thanos-io/thanos/pkg/block"
2223
"github.com/thanos-io/thanos/pkg/block/metadata"
2324

2425
"github.com/cortexproject/cortex/pkg/chunk"
@@ -204,8 +205,9 @@ func (d *tsdbBuilder) finishBlock(source string, labels map[string]string) (ulid
204205
},
205206

206207
Thanos: metadata.Thanos{
207-
Labels: labels,
208-
Source: metadata.SourceType(source),
208+
Labels: labels,
209+
Source: metadata.SourceType(source),
210+
SegmentFiles: block.GetSegmentFiles(d.tmpBlockDir),
209211
},
210212
}
211213

vendor/github.com/thanos-io/thanos/pkg/block/block.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)