From 5742a18590f2c342efb9c0ecb6c20fd8ce0b0863 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Sun, 7 Mar 2021 09:19:33 +0100 Subject: [PATCH] Fix subqueries with default resolution in promql unit tests Signed-off-by: Julien Pivotto --- cmd/promtool/testdata/rules.yml | 4 ++++ cmd/promtool/unittest.go | 1 + docs/configuration/unit_testing_rules.md | 3 +-- promql/test.go | 14 ++++++++------ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cmd/promtool/testdata/rules.yml b/cmd/promtool/testdata/rules.yml index 590998d88..7880d3cab 100644 --- a/cmd/promtool/testdata/rules.yml +++ b/cmd/promtool/testdata/rules.yml @@ -22,3 +22,7 @@ groups: # A recording rule that doesn't depend on input series. - record: fixed_data expr: 1 + + # Subquery with default resolution test. + - record: suquery_interval_test + expr: count_over_time(up[5m:]) diff --git a/cmd/promtool/unittest.go b/cmd/promtool/unittest.go index 6069ec3f9..c55db94da 100644 --- a/cmd/promtool/unittest.go +++ b/cmd/promtool/unittest.go @@ -157,6 +157,7 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i return []error{err} } defer suite.Close() + suite.SubqueryInterval = evalInterval // Load the rule files. opts := &rules.ManagerOptions{ diff --git a/docs/configuration/unit_testing_rules.md b/docs/configuration/unit_testing_rules.md index 3043b2edf..644b35a17 100644 --- a/docs/configuration/unit_testing_rules.md +++ b/docs/configuration/unit_testing_rules.md @@ -22,8 +22,7 @@ You can use `promtool` to test your rules. rule_files: [ - ] -# optional, default = 1m -evaluation_interval: +[ evaluation_interval: | default = 1m ] # The order in which group names are listed below will be the order of evaluation of # rule groups (at a given evaluation time). The order is guaranteed only for the groups mentioned below. diff --git a/promql/test.go b/promql/test.go index 8ee3fc150..2e48f25cc 100644 --- a/promql/test.go +++ b/promql/test.go @@ -657,7 +657,8 @@ type LazyLoader struct { loadCmd *loadCmd - storage storage.Storage + storage storage.Storage + SubqueryInterval time.Duration queryEngine *Engine context context.Context @@ -710,11 +711,12 @@ func (ll *LazyLoader) clear() { ll.storage = teststorage.New(ll) opts := EngineOpts{ - Logger: nil, - Reg: nil, - MaxSamples: 10000, - Timeout: 100 * time.Second, - EnableAtModifier: true, + Logger: nil, + Reg: nil, + MaxSamples: 10000, + Timeout: 100 * time.Second, + NoStepSubqueryIntervalFn: func(int64) int64 { return durationMilliseconds(ll.SubqueryInterval) }, + EnableAtModifier: true, } ll.queryEngine = NewEngine(opts)