From 2764c4653112e59c10a8e0af8b18ebbb6f5851a0 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Fri, 26 Jan 2024 19:38:11 +0100 Subject: [PATCH] Added more test cases to TestDependenciesEdgeCases Signed-off-by: Marco Pracucci --- rules/manager_test.go | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/rules/manager_test.go b/rules/manager_test.go index 4762ef6f5d..ed6fea2532 100644 --- a/rules/manager_test.go +++ b/rules/manager_test.go @@ -1589,6 +1589,50 @@ func TestDependenciesEdgeCases(t *testing.T) { require.False(t, depMap.isIndependent(rule1)) require.False(t, depMap.isIndependent(rule2)) }) + + t.Run("rule querying ALERTS metric", func(t *testing.T) { + expr, err := parser.ParseExpr("sum(requests)") + require.NoError(t, err) + rule1 := NewRecordingRule("first", expr, labels.Labels{}) + + expr, err = parser.ParseExpr(`sum(ALERTS{alertname="test"})`) + require.NoError(t, err) + rule2 := NewRecordingRule("second", expr, labels.Labels{}) + + group := NewGroup(GroupOptions{ + Name: "rule_group", + Interval: time.Second, + Rules: []Rule{rule1, rule2}, + Opts: opts, + }) + + depMap := buildDependencyMap(group.rules) + // A rule querying ALERTS metric causes the whole group to be indeterminate. + require.False(t, depMap.isIndependent(rule1)) + require.False(t, depMap.isIndependent(rule2)) + }) + + t.Run("rule querying ALERTS_FOR_STATE metric", func(t *testing.T) { + expr, err := parser.ParseExpr("sum(requests)") + require.NoError(t, err) + rule1 := NewRecordingRule("first", expr, labels.Labels{}) + + expr, err = parser.ParseExpr(`sum(ALERTS_FOR_STATE{alertname="test"})`) + require.NoError(t, err) + rule2 := NewRecordingRule("second", expr, labels.Labels{}) + + group := NewGroup(GroupOptions{ + Name: "rule_group", + Interval: time.Second, + Rules: []Rule{rule1, rule2}, + Opts: opts, + }) + + depMap := buildDependencyMap(group.rules) + // A rule querying ALERTS_FOR_STATE metric causes the whole group to be indeterminate. + require.False(t, depMap.isIndependent(rule1)) + require.False(t, depMap.isIndependent(rule2)) + }) } func TestNoMetricSelector(t *testing.T) {