Skip to content

Commit c920d2c

Browse files
committed
fix cortex_compactor_remaining_planned_compactions not set after plan generation
Signed-off-by: Roy Chiang <[email protected]>
1 parent 108b4b7 commit c920d2c

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* [BUGFIX] Memberlist: Avoid clock skew by limiting the timestamp accepted on gossip. #4750
4848
* [BUGFIX] Compactor: skip compaction if there is only 1 block available for shuffle-sharding compactor. #4756
4949
* [BUGFIX] Compactor: Fixes #4770 - an edge case in compactor with shulffle sharding where compaction stops when a tenant stops ingesting samples. #4771
50+
* [BUGFIX] Compactor: fix cortex_compactor_remaining_planned_compactions not set after plan generation for shuffle sharding compactor. #4772
5051

5152
## 1.11.0 2021-11-25
5253

pkg/compactor/shuffle_sharding_grouper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (g *ShuffleShardingGrouper) Groups(blocks map[ulid.ULID]*metadata.Meta) (re
134134
}
135135
// Metrics for the remaining planned compactions
136136
var remainingCompactions = 0.
137-
defer g.remainingPlannedCompactions.Set(remainingCompactions)
137+
defer func() { g.remainingPlannedCompactions.Set(remainingCompactions) }()
138138

139139
for _, mainBlocks := range mainGroups {
140140
for _, group := range groupBlocksByCompactableRanges(mainBlocks, g.compactorCfg.BlockRanges.ToMilliseconds()) {

pkg/compactor/shuffle_sharding_grouper_test.go

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package compactor
22

33
import (
4+
"bytes"
45
"testing"
56
"time"
67

8+
"github.com/prometheus/client_golang/prometheus/testutil"
9+
710
"github.com/oklog/ulid"
811
"github.com/prometheus/client_golang/prometheus"
912
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -112,6 +115,7 @@ func TestShuffleShardingGrouper_Groups(t *testing.T) {
112115
ranges []time.Duration
113116
blocks map[ulid.ULID]*metadata.Meta
114117
expected [][]ulid.ULID
118+
metrics string
115119
}{
116120
"test basic grouping": {
117121
ranges: []time.Duration{2 * time.Hour, 4 * time.Hour},
@@ -121,11 +125,19 @@ func TestShuffleShardingGrouper_Groups(t *testing.T) {
121125
{block1hto2hExt1Ulid, block0hto1hExt1Ulid},
122126
{block3hto4hExt1Ulid, block2hto3hExt1Ulid},
123127
},
128+
metrics: `# HELP cortex_compactor_remaining_planned_compactions Total number of plans that remain to be compacted.
129+
# TYPE cortex_compactor_remaining_planned_compactions gauge
130+
cortex_compactor_remaining_planned_compactions 3
131+
`,
124132
},
125133
"test no compaction": {
126134
ranges: []time.Duration{2 * time.Hour, 4 * time.Hour},
127135
blocks: map[ulid.ULID]*metadata.Meta{block0hto1hExt1Ulid: blocks[block0hto1hExt1Ulid], block0hto1hExt2Ulid: blocks[block0hto1hExt2Ulid], block0to1hExt3Ulid: blocks[block0to1hExt3Ulid]},
128136
expected: [][]ulid.ULID{},
137+
metrics: `# HELP cortex_compactor_remaining_planned_compactions Total number of plans that remain to be compacted.
138+
# TYPE cortex_compactor_remaining_planned_compactions gauge
139+
cortex_compactor_remaining_planned_compactions 0
140+
`,
129141
},
130142
"test smallest range first": {
131143
ranges: []time.Duration{2 * time.Hour, 4 * time.Hour},
@@ -135,6 +147,10 @@ func TestShuffleShardingGrouper_Groups(t *testing.T) {
135147
{block3hto4hExt1Ulid, block2hto3hExt1Ulid},
136148
{block4hto6hExt2Ulid, block6hto8hExt2Ulid},
137149
},
150+
metrics: `# HELP cortex_compactor_remaining_planned_compactions Total number of plans that remain to be compacted.
151+
# TYPE cortex_compactor_remaining_planned_compactions gauge
152+
cortex_compactor_remaining_planned_compactions 3
153+
`,
138154
},
139155
"test oldest min time first": {
140156
ranges: []time.Duration{2 * time.Hour, 4 * time.Hour},
@@ -143,25 +159,41 @@ func TestShuffleShardingGrouper_Groups(t *testing.T) {
143159
{block1hto2hExt1Ulid, block0hto1hExt1Ulid, block1hto2hExt1UlidCopy},
144160
{block3hto4hExt1Ulid, block2hto3hExt1Ulid},
145161
},
162+
metrics: `# HELP cortex_compactor_remaining_planned_compactions Total number of plans that remain to be compacted.
163+
# TYPE cortex_compactor_remaining_planned_compactions gauge
164+
cortex_compactor_remaining_planned_compactions 2
165+
`,
146166
},
147167
"test overlapping blocks": {
148168
ranges: []time.Duration{20 * time.Hour, 40 * time.Hour},
149169
blocks: map[ulid.ULID]*metadata.Meta{block0hto20hExt1Ulid: blocks[block0hto20hExt1Ulid], block21hto40hExt1Ulid: blocks[block21hto40hExt1Ulid], block21hto40hExt1UlidCopy: blocks[block21hto40hExt1UlidCopy]},
150170
expected: [][]ulid.ULID{
151171
{block21hto40hExt1Ulid, block21hto40hExt1UlidCopy},
152172
},
173+
metrics: `# HELP cortex_compactor_remaining_planned_compactions Total number of plans that remain to be compacted.
174+
# TYPE cortex_compactor_remaining_planned_compactions gauge
175+
cortex_compactor_remaining_planned_compactions 1
176+
`,
153177
},
154178
"test imperfect maxTime blocks": {
155179
ranges: []time.Duration{2 * time.Hour},
156180
blocks: map[ulid.ULID]*metadata.Meta{block0hto1h30mExt1Ulid: blocks[block0hto1h30mExt1Ulid], block0hto45mExt1Ulid: blocks[block0hto45mExt1Ulid]},
157181
expected: [][]ulid.ULID{
158182
{block0hto45mExt1Ulid, block0hto1h30mExt1Ulid},
159183
},
184+
metrics: `# HELP cortex_compactor_remaining_planned_compactions Total number of plans that remain to be compacted.
185+
# TYPE cortex_compactor_remaining_planned_compactions gauge
186+
cortex_compactor_remaining_planned_compactions 1
187+
`,
160188
},
161189
"test prematurely created blocks": {
162190
ranges: []time.Duration{2 * time.Hour},
163191
blocks: map[ulid.ULID]*metadata.Meta{blocklast1hExt1UlidCopy: blocks[blocklast1hExt1UlidCopy], blocklast1hExt1Ulid: blocks[blocklast1hExt1Ulid]},
164192
expected: [][]ulid.ULID{},
193+
metrics: `# HELP cortex_compactor_remaining_planned_compactions Total number of plans that remain to be compacted.
194+
# TYPE cortex_compactor_remaining_planned_compactions gauge
195+
cortex_compactor_remaining_planned_compactions 0
196+
`,
165197
},
166198
}
167199

@@ -188,7 +220,7 @@ func TestShuffleShardingGrouper_Groups(t *testing.T) {
188220
ring := &RingMock{}
189221
ring.On("ShuffleShard", mock.Anything, mock.Anything).Return(subring, nil)
190222

191-
registerer := prometheus.NewRegistry()
223+
registerer := prometheus.NewPedanticRegistry()
192224
remainingPlannedCompactions := promauto.With(registerer).NewGauge(prometheus.GaugeOpts{
193225
Name: "cortex_compactor_remaining_planned_compactions",
194226
Help: "Total number of plans that remain to be compacted.",
@@ -216,6 +248,9 @@ func TestShuffleShardingGrouper_Groups(t *testing.T) {
216248
for idx, expectedIDs := range testData.expected {
217249
assert.Equal(t, expectedIDs, actual[idx].IDs())
218250
}
251+
252+
err = testutil.GatherAndCompare(registerer, bytes.NewBufferString(testData.metrics), "cortex_compactor_remaining_planned_compactions")
253+
require.NoError(t, err)
219254
})
220255
}
221256
}

0 commit comments

Comments
 (0)