Skip to content

Commit

Permalink
improved downsampling test cases; CI fix
Browse files Browse the repository at this point in the history
Signed-off-by: metonymic-smokey <ahuja.aditi@gmail.com>
  • Loading branch information
metonymic-smokey committed Nov 6, 2021
1 parent 3d0d375 commit 41c971a
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions pkg/compact/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ func TestCompactProgressCalculate(t *testing.T) {
int64(8 * time.Hour / time.Millisecond),
})

// pre calculating group keys
keys := make([]string, 3)
m := make([]metadata.Meta, 3)
m[0].Thanos.Labels = map[string]string{"a": "1"}
Expand All @@ -233,7 +232,7 @@ func TestCompactProgressCalculate(t *testing.T) {
}

var bkt objstore.Bucket
temp := promauto.NewCounter(prometheus.CounterOpts{Name: "test_metric_for_group", Help: "this is a test metric for compact progress tests"})
temp := promauto.With(reg).NewCounter(prometheus.CounterOpts{Name: "test_metric_for_group", Help: "this is a test metric for compact progress tests"})
grouper := NewDefaultGrouper(logger, bkt, false, false, reg, temp, temp, temp, "")

for _, tcase := range []struct {
Expand Down Expand Up @@ -323,7 +322,6 @@ func TestCompactProgressCalculate(t *testing.T) {
for _, meta := range tcase.input {
blocks[meta.ULID] = meta
}
// form groups from the input metadata - do not hardcode groups. hence, grouper.Groups should stay
groups, err := grouper.Groups(blocks)
testutil.Ok(t, err)
ps := NewCompactionProgressCalculator(unRegisterer, planner)
Expand Down Expand Up @@ -351,7 +349,6 @@ func TestDownsampleProgressCalculate(t *testing.T) {
logger := log.NewNopLogger()
type groupedResult map[string]float64

// pre calculating group keys
keys := make([]string, 3)
m := make([]metadata.Meta, 3)
m[0].Thanos.Labels = map[string]string{"a": "1"}
Expand All @@ -365,7 +362,7 @@ func TestDownsampleProgressCalculate(t *testing.T) {
}

var bkt objstore.Bucket
temp := promauto.NewCounter(prometheus.CounterOpts{Name: "test_metric_for_group", Help: "this is a test metric for downsample progress tests"})
temp := promauto.With(reg).NewCounter(prometheus.CounterOpts{Name: "test_metric_for_group", Help: "this is a test metric for downsample progress tests"})
grouper := NewDefaultGrouper(logger, bkt, false, false, reg, temp, temp, temp, "")

for _, tcase := range []struct {
Expand All @@ -374,55 +371,68 @@ func TestDownsampleProgressCalculate(t *testing.T) {
expected groupedResult
}{
{
testName: "first_test",
input: []*metadata.Meta{
createBlockMeta(0, 0, downsample.DownsampleRange0, map[string]string{"a": "1"}, downsample.ResLevel0, []uint64{1, 2}),
createBlockMeta(3, 1, downsample.DownsampleRange1, map[string]string{"b": "2"}, downsample.ResLevel0, []uint64{4, 5}),
createBlockMeta(6, 1, downsample.DownsampleRange1, map[string]string{"a": "1", "b": "2"}, downsample.ResLevel2, []uint64{7, 8}),
},
expected: map[string]float64{
keys[0]: 1.0,
keys[1]: 0.0,
keys[2]: 0.0,
},
},
{
testName: "second_test",
// This test case has blocks from multiple groups and resolution levels. Only the second block should be downsampled since the others either have time differences not in the range for their resolution, or a resolution which should not be downsampled.
testName: "multi_group_test",
input: []*metadata.Meta{
createBlockMeta(6, 1, downsample.DownsampleRange0, map[string]string{"a": "1"}, downsample.ResLevel0, []uint64{7, 8}),
createBlockMeta(7, 1, downsample.DownsampleRange1, map[string]string{"b": "2"}, downsample.ResLevel1, []uint64{7, 8}),
createBlockMeta(8, 1, downsample.DownsampleRange1, map[string]string{"a": "1", "b": "2"}, downsample.ResLevel2, []uint64{7, 8}),
createBlockMeta(7, 0, downsample.DownsampleRange1, map[string]string{"b": "2"}, downsample.ResLevel1, []uint64{8, 9}),
createBlockMeta(8, 0, downsample.DownsampleRange1, map[string]string{"a": "1", "b": "2"}, downsample.ResLevel2, []uint64{9, 10}),
},
expected: map[string]float64{
keys[0]: 0.0,
keys[1]: 0.0,
keys[1]: 1.0,
keys[2]: 0.0,
},
}, {
testName: "third_test",
// This is a test case for resLevel0, with the correct time difference threshold.
// This block should be downsampled.
testName: "res_level0_test",
input: []*metadata.Meta{
createBlockMeta(9, 0, downsample.DownsampleRange0, map[string]string{"a": "1"}, downsample.ResLevel0, []uint64{10, 11}),
},
expected: map[string]float64{
keys[0]: 1.0,
},
}, {
testName: "fourth_test",
// This is a test case for resLevel1, with the correct time difference threshold.
// This block should be downsampled.
testName: "res_level1_test",
input: []*metadata.Meta{
createBlockMeta(10, 0, downsample.DownsampleRange1, map[string]string{"a": "1"}, downsample.ResLevel1, []uint64{11, 12}),
createBlockMeta(9, 0, downsample.DownsampleRange1, map[string]string{"b": "2"}, downsample.ResLevel1, []uint64{10, 11}),
},
expected: map[string]float64{
keys[0]: 0.0,
keys[1]: 1.0,
},
},
{
testName: "fifth_test",
// This is a test case for resLevel2.
// Blocks with this resolution should not be downsampled.
testName: "res_level2_test",
input: []*metadata.Meta{
createBlockMeta(10, 0, downsample.DownsampleRange1, map[string]string{"a": "1", "b": "2"}, downsample.ResLevel2, []uint64{11, 12}),
},
expected: map[string]float64{
keys[2]: 0.0,
},
}, {
// This is a test case for resLevel0, with incorrect time difference, below the threshold.
// This block should be downsampled.
testName: "res_level0_test_incorrect",
input: []*metadata.Meta{
createBlockMeta(10, 0, downsample.DownsampleRange1, map[string]string{"a": "1"}, downsample.ResLevel1, []uint64{1, 2}),
createBlockMeta(3, 0, downsample.DownsampleRange0, map[string]string{"b": "2"}, downsample.ResLevel0, []uint64{4, 5}),
createBlockMeta(9, 1, downsample.DownsampleRange0, map[string]string{"a": "1"}, downsample.ResLevel0, []uint64{10, 11}),
},
expected: map[string]float64{
keys[0]: 0.0,
},
},
{
// This is a test case for resLevel1, with incorrect time difference, below the threshold.
// This block should be downsampled.
testName: "res_level1_test",
input: []*metadata.Meta{
createBlockMeta(9, 1, downsample.DownsampleRange1, map[string]string{"b": "2"}, downsample.ResLevel1, []uint64{10, 11}),
},
expected: map[string]float64{
keys[1]: 0.0,
},
},
Expand Down

0 comments on commit 41c971a

Please sign in to comment.