From a961062c37f1675d5925d8b74ddda0a6322ed82d Mon Sep 17 00:00:00 2001 From: David Leadbeater Date: Mon, 3 Jan 2022 09:46:03 +1100 Subject: [PATCH] Disable time based retention in tests (#8818) Fixes #7699. Signed-off-by: David Leadbeater --- cmd/promtool/testdata/long-period.yml | 34 +++++++++++++++++++++++++++ cmd/promtool/unittest_test.go | 7 ++++++ util/teststorage/storage.go | 1 + 3 files changed, 42 insertions(+) create mode 100644 cmd/promtool/testdata/long-period.yml diff --git a/cmd/promtool/testdata/long-period.yml b/cmd/promtool/testdata/long-period.yml new file mode 100644 index 000000000..cac74094a --- /dev/null +++ b/cmd/promtool/testdata/long-period.yml @@ -0,0 +1,34 @@ +# Evaluate once every 100d to avoid this taking too long. +evaluation_interval: 100d + +rule_files: + - rules.yml + +tests: + - interval: 100d + input_series: + - series: test + # Max time in time.Duration is 106751d from 1970 (2^63/10^9), i.e. 2262. + # We use the nearest 100 days to that to ensure the unit tests can fully + # cover the expected range. + values: '0+1x1067' + + promql_expr_test: + - expr: timestamp(test) + eval_time: 0m + exp_samples: + - value: 0 + - expr: test + eval_time: 100d # one evaluation_interval. + exp_samples: + - labels: test + value: 1 + - expr: timestamp(test) + eval_time: 106700d + exp_samples: + - value: 9218880000 # 106700d -> seconds. + - expr: fixed_data + eval_time: 106700d + exp_samples: + - labels: fixed_data + value: 1 diff --git a/cmd/promtool/unittest_test.go b/cmd/promtool/unittest_test.go index 0f528471a..1e0244054 100644 --- a/cmd/promtool/unittest_test.go +++ b/cmd/promtool/unittest_test.go @@ -36,6 +36,13 @@ func TestRulesUnitTest(t *testing.T) { }, want: 0, }, + { + name: "Long evaluation interval", + args: args{ + files: []string{"./testdata/long-period.yml"}, + }, + want: 0, + }, { name: "Bad input series", args: args{ diff --git a/util/teststorage/storage.go b/util/teststorage/storage.go index a82989477..9f9cb4ceb 100644 --- a/util/teststorage/storage.go +++ b/util/teststorage/storage.go @@ -39,6 +39,7 @@ func New(t testutil.T) *TestStorage { opts := tsdb.DefaultOptions() opts.MinBlockDuration = int64(24 * time.Hour / time.Millisecond) opts.MaxBlockDuration = int64(24 * time.Hour / time.Millisecond) + opts.RetentionDuration = 0 db, err := tsdb.Open(dir, nil, nil, opts, tsdb.NewDBStats()) require.NoError(t, err, "unexpected error while opening test storage") reg := prometheus.NewRegistry()