diff --git a/pkg/compact/compact_test.go b/pkg/compact/compact_test.go index 907e47e5cd5..ae83c9b088e 100644 --- a/pkg/compact/compact_test.go +++ b/pkg/compact/compact_test.go @@ -14,7 +14,6 @@ import ( "time" "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/oklog/ulid" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -184,11 +183,14 @@ func createBlockMeta(id uint64, minTime, maxTime int64, labels map[string]string m := &metadata.Meta{ BlockMeta: tsdb.BlockMeta{ ULID: ulid.MustNew(id, nil), - MinTime: int64(time.Duration(minTime) * time.Hour / time.Millisecond), - MaxTime: int64(time.Duration(maxTime) * time.Hour / time.Millisecond), + MinTime: minTime, + MaxTime: maxTime, }, Thanos: metadata.Thanos{ Labels: labels, + Downsample: metadata.ThanosDownsample{ + Resolution: resolution, + }, }, } @@ -234,14 +236,14 @@ func TestCompactProgressCalculate(t *testing.T) { { testName: "first_test", input: []*metadata.Meta{ - createBlockMeta(0, 0, 2, map[string]string{"a": "1"}, 0), - createBlockMeta(1, 2, 4, map[string]string{"a": "1"}, 0), - createBlockMeta(2, 4, 6, map[string]string{"b": "2"}, 0), - createBlockMeta(3, 6, 8, map[string]string{"b": "2"}, 0), - createBlockMeta(4, 8, 10, map[string]string{"b": "2"}, 0), - createBlockMeta(5, 10, 12, map[string]string{"a": "1", "b": "2"}, 1), - createBlockMeta(6, 12, 20, map[string]string{"a": "1", "b": "2"}, 1), - createBlockMeta(7, 20, 28, map[string]string{"a": "1", "b": "2"}, 1), + createBlockMeta(0, 0, int64(time.Duration(2)*time.Hour/time.Millisecond), map[string]string{"a": "1"}, 0), + createBlockMeta(1, int64(time.Duration(2)*time.Hour/time.Millisecond), int64(time.Duration(4)*time.Hour/time.Millisecond), map[string]string{"a": "1"}, 0), + createBlockMeta(2, int64(time.Duration(4)*time.Hour/time.Millisecond), int64(time.Duration(6)*time.Hour/time.Millisecond), map[string]string{"b": "2"}, 0), + createBlockMeta(3, int64(time.Duration(6)*time.Hour/time.Millisecond), int64(time.Duration(8)*time.Hour/time.Millisecond), map[string]string{"b": "2"}, 0), + createBlockMeta(4, int64(time.Duration(8)*time.Hour/time.Millisecond), int64(time.Duration(10)*time.Hour/time.Millisecond), map[string]string{"b": "2"}, 0), + createBlockMeta(5, int64(time.Duration(10)*time.Hour/time.Millisecond), int64(time.Duration(12)*time.Hour/time.Millisecond), map[string]string{"a": "1", "b": "2"}, 1), + createBlockMeta(6, int64(time.Duration(12)*time.Hour/time.Millisecond), int64(time.Duration(20)*time.Hour/time.Millisecond), map[string]string{"a": "1", "b": "2"}, 1), + createBlockMeta(7, int64(time.Duration(20)*time.Hour/time.Millisecond), int64(time.Duration(28)*time.Hour/time.Millisecond), map[string]string{"a": "1", "b": "2"}, 1), }, expected: map[string]planResult{ keys[0]: { @@ -261,12 +263,12 @@ func TestCompactProgressCalculate(t *testing.T) { { testName: "second_test", input: []*metadata.Meta{ - createBlockMeta(0, 0, 2, map[string]string{"a": "1"}, 0), - createBlockMeta(1, 2, 4, map[string]string{"b": "2"}, 0), - createBlockMeta(2, 4, 6, map[string]string{"b": "2"}, 0), - createBlockMeta(3, 6, 10, map[string]string{"a": "1", "b": "2"}, 1), - createBlockMeta(4, 10, 14, map[string]string{"a": "1", "b": "2"}, 1), - createBlockMeta(5, 14, 16, map[string]string{"a": "1", "b": "2"}, 1), + createBlockMeta(0, 0, int64(time.Duration(2)*time.Hour/time.Millisecond), map[string]string{"a": "1"}, 0), + createBlockMeta(1, int64(time.Duration(2)*time.Hour/time.Millisecond), int64(time.Duration(4)*time.Hour/time.Millisecond), map[string]string{"b": "2"}, 0), + createBlockMeta(2, int64(time.Duration(4)*time.Hour/time.Millisecond), int64(time.Duration(6)*time.Hour/time.Millisecond), map[string]string{"b": "2"}, 0), + createBlockMeta(3, int64(time.Duration(6)*time.Hour/time.Millisecond), int64(time.Duration(10)*time.Hour/time.Millisecond), map[string]string{"a": "1", "b": "2"}, 1), + createBlockMeta(4, int64(time.Duration(10)*time.Hour/time.Millisecond), int64(time.Duration(14)*time.Hour/time.Millisecond), map[string]string{"a": "1", "b": "2"}, 1), + createBlockMeta(5, int64(time.Duration(14)*time.Hour/time.Millisecond), int64(time.Duration(16)*time.Hour/time.Millisecond), map[string]string{"a": "1", "b": "2"}, 1), }, expected: map[string]planResult{ keys[0]: { @@ -286,11 +288,11 @@ func TestCompactProgressCalculate(t *testing.T) { { testName: "third_test", input: []*metadata.Meta{ - createBlockMeta(0, 0, 2, map[string]string{"a": "1"}, 0), - createBlockMeta(1, 2, 4, map[string]string{"b": "2"}, 0), - createBlockMeta(2, 4, 6, map[string]string{"b": "2"}, 0), - createBlockMeta(3, 6, 8, map[string]string{"a": "1", "b": "2"}, 1), - createBlockMeta(4, 8, 10, map[string]string{"a": "1", "b": "2"}, 1), + createBlockMeta(0, 0, int64(time.Duration(2)*time.Hour/time.Millisecond), map[string]string{"a": "1"}, 0), + createBlockMeta(1, int64(time.Duration(2)*time.Hour/time.Millisecond), int64(time.Duration(4)*time.Hour/time.Millisecond), map[string]string{"b": "2"}, 0), + createBlockMeta(2, int64(time.Duration(4)*time.Hour/time.Millisecond), int64(time.Duration(6)*time.Hour/time.Millisecond), map[string]string{"b": "2"}, 0), + createBlockMeta(3, int64(time.Duration(6)*time.Hour/time.Millisecond), int64(time.Duration(8)*time.Hour/time.Millisecond), map[string]string{"a": "1", "b": "2"}, 1), + createBlockMeta(4, int64(time.Duration(8)*time.Hour/time.Millisecond), int64(time.Duration(10)*time.Hour/time.Millisecond), map[string]string{"a": "1", "b": "2"}, 1), }, expected: map[string]planResult{ keys[0]: { @@ -595,11 +597,10 @@ func TestDownsampleProgressCalculate(t *testing.T) { err = ds.ProgressCalculate(context.Background(), groups) testutil.Ok(t, err) metrics := ds.DownsampleProgressMetrics - for _, key := range keys { + for key := range tcase.expected { a, err := metrics.NumberOfBlocksDownsampled.GetMetricWithLabelValues(key) - if err != nil { - level.Warn(logger).Log("msg", "could not get number of blocks") - } + + testutil.Ok(t, err) testutil.Equals(t, tcase.expected[key], promtestutil.ToFloat64(a)) } }); !ok {