mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 22:07:27 -08:00
fix issue #9432(uses reference to loop iterator variable ) (#9483)
This commit is contained in:
parent
55f9147b44
commit
4e1dacf2d1
|
@ -83,7 +83,7 @@ func (g *RuleGroups) Validate(node ruleGroups) (errs []error) {
|
|||
set[g.Name] = struct{}{}
|
||||
|
||||
for i, r := range g.Rules {
|
||||
for _, node := range r.Validate() {
|
||||
for _, node := range g.Rules[i].Validate() {
|
||||
var ruleName yaml.Node
|
||||
if r.Alert.Value != "" {
|
||||
ruleName = r.Alert
|
||||
|
|
|
@ -156,5 +156,31 @@ groups:
|
|||
passed := (tst.shouldPass && len(errs) == 0) || (!tst.shouldPass && len(errs) > 0)
|
||||
require.True(t, passed, "Rule validation failed, rule=\n"+tst.ruleString)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestUniqueErrorNodes(t *testing.T) {
|
||||
group := `
|
||||
groups:
|
||||
- name: example
|
||||
rules:
|
||||
- alert: InstanceDown
|
||||
expr: up ===== 0
|
||||
for: 5m
|
||||
labels:
|
||||
severity: "page"
|
||||
annotations:
|
||||
summary: "Instance {{ $labels.instance }} down"
|
||||
- alert: InstanceUp
|
||||
expr: up ===== 1
|
||||
for: 5m
|
||||
labels:
|
||||
severity: "page"
|
||||
annotations:
|
||||
summary: "Instance {{ $labels.instance }} up"
|
||||
`
|
||||
_, errs := Parse([]byte(group))
|
||||
require.Len(t, errs, 2, "Expected two errors")
|
||||
err0 := errs[0].(*Error).Err.node
|
||||
err1 := errs[1].(*Error).Err.node
|
||||
require.NotEqual(t, err0, err1, "Error nodes should not be the same")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue