MCPcopy
hub / github.com/prometheus/prometheus / TestLeveledCompactor

Function TestLeveledCompactor

tsdb/compact_test.go:178–446  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

176}
177
178func TestLeveledCompactor(t *testing.T) {
179 // Tests for the private plan() method.
180 t.Run("plan", func(t *testing.T) {
181 // This mimics our default ExponentialBlockRanges with min block size equals to 20.
182 compactor, err := NewLeveledCompactor(context.Background(), nil, nil, []int64{
183 20,
184 60,
185 180,
186 540,
187 1620,
188 }, nil, nil)
189 require.NoError(t, err)
190
191 cases := map[string]struct {
192 metas []dirMeta
193 expected []string
194 }{
195 "Outside Range": {
196 metas: []dirMeta{
197 metaRange("1", 0, 20, nil),
198 },
199 expected: nil,
200 },
201 "We should wait for four blocks of size 20 to appear before compacting.": {
202 metas: []dirMeta{
203 metaRange("1", 0, 20, nil),
204 metaRange("2", 20, 40, nil),
205 },
206 expected: nil,
207 },
208 `We should wait for a next block of size 20 to appear before compacting
209 the existing ones. We have three, but we ignore the fresh one from WAl`: {
210 metas: []dirMeta{
211 metaRange("1", 0, 20, nil),
212 metaRange("2", 20, 40, nil),
213 metaRange("3", 40, 60, nil),
214 },
215 expected: nil,
216 },
217 "Block to fill the entire parent range appeared – should be compacted": {
218 metas: []dirMeta{
219 metaRange("1", 0, 20, nil),
220 metaRange("2", 20, 40, nil),
221 metaRange("3", 40, 60, nil),
222 metaRange("4", 60, 80, nil),
223 },
224 expected: []string{"1", "2", "3"},
225 },
226 `Block for the next parent range appeared with gap with size 20. Nothing will happen in the first one
227 anymore but we ignore fresh one still, so no compaction`: {
228 metas: []dirMeta{
229 metaRange("1", 0, 20, nil),
230 metaRange("2", 20, 40, nil),
231 metaRange("3", 60, 80, nil),
232 },
233 expected: nil,
234 },
235 `Block for the next parent range appeared, and we have a gap with size 20 between second and third block.

Callers

nothing calls this directly

Calls 10

planMethod · 0.95
NewPoolFunction · 0.92
NewLeveledCompactorFunction · 0.85
metaRangeFunction · 0.85
writeMetaFileFunction · 0.85
RunMethod · 0.65
StringMethod · 0.65
PlanMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…