mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Add more test cases to TestDependenciesEdgeCases
Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
parent
21a03dc018
commit
52bc568d04
|
@ -1523,6 +1523,72 @@ func TestDependenciesEdgeCases(t *testing.T) {
|
|||
require.True(t, depMap.isIndependent(rule1))
|
||||
require.True(t, depMap.isIndependent(rule2))
|
||||
})
|
||||
|
||||
t.Run("rule with regexp matcher on metric name", 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({__name__=~".+"})`)
|
||||
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 with regexp matcher on metric name causes the whole group to be indeterminate.
|
||||
require.False(t, depMap.isIndependent(rule1))
|
||||
require.False(t, depMap.isIndependent(rule2))
|
||||
})
|
||||
|
||||
t.Run("rule with not equal matcher on metric name", 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({__name__!="requests", service="app"})`)
|
||||
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 with not equal matcher on metric name causes the whole group to be indeterminate.
|
||||
require.False(t, depMap.isIndependent(rule1))
|
||||
require.False(t, depMap.isIndependent(rule2))
|
||||
})
|
||||
|
||||
t.Run("rule with not regexp matcher on metric name", 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({__name__!~"requests.+", service="app"})`)
|
||||
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 with not regexp matcher on metric name causes the whole group to be indeterminate.
|
||||
require.False(t, depMap.isIndependent(rule1))
|
||||
require.False(t, depMap.isIndependent(rule2))
|
||||
})
|
||||
}
|
||||
|
||||
func TestNoMetricSelector(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue