mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
vmalert - validate template in labels (#439)
This commit is contained in:
parent
eeadfccdc5
commit
5f61d43db9
4 changed files with 19 additions and 1 deletions
|
@ -40,7 +40,10 @@ func Parse(pathPatterns []string, validateAnnotations bool) ([]Group, error) {
|
||||||
rule.alerts = make(map[uint64]*notifier.Alert)
|
rule.alerts = make(map[uint64]*notifier.Alert)
|
||||||
if validateAnnotations {
|
if validateAnnotations {
|
||||||
if err = notifier.ValidateAnnotations(rule.Annotations); err != nil {
|
if err = notifier.ValidateAnnotations(rule.Annotations); err != nil {
|
||||||
return nil, fmt.Errorf("invalida annotations filepath:%s, group %s:%w", file, group.Name, err)
|
return nil, fmt.Errorf("invalid annotations filepath:%s, group %s:%w", file, group.Name, err)
|
||||||
|
}
|
||||||
|
if err = notifier.ValidateAnnotations(rule.Labels); err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid labels filepath:%s, group %s:%w", file, group.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rule.group = &group
|
rule.group = &group
|
||||||
|
|
|
@ -30,6 +30,9 @@ func TestParseBad(t *testing.T) {
|
||||||
if _, err := Parse([]string{"testdata/dir/rules1-bad.rules"}, true); err == nil {
|
if _, err := Parse([]string{"testdata/dir/rules1-bad.rules"}, true); err == nil {
|
||||||
t.Errorf("expected same group error")
|
t.Errorf("expected same group error")
|
||||||
}
|
}
|
||||||
|
if _, err := Parse([]string{"testdata/dir/rules2-bad.rules"}, true); err == nil {
|
||||||
|
t.Errorf("expected template label error")
|
||||||
|
}
|
||||||
if _, err := Parse([]string{"testdata/*.yaml"}, true); err == nil {
|
if _, err := Parse([]string{"testdata/*.yaml"}, true); err == nil {
|
||||||
t.Errorf("expected empty group")
|
t.Errorf("expected empty group")
|
||||||
}
|
}
|
||||||
|
|
11
app/vmalert/testdata/dir/rules2-bad.rules
vendored
Normal file
11
app/vmalert/testdata/dir/rules2-bad.rules
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
groups:
|
||||||
|
- name: group
|
||||||
|
rules:
|
||||||
|
- alert: UnkownLabelFunction
|
||||||
|
for: 5m
|
||||||
|
expr: vm_rows > 0
|
||||||
|
labels:
|
||||||
|
label: bar
|
||||||
|
summary: "{{ value|query }}"
|
||||||
|
annotations:
|
||||||
|
description: "{{$labels}}"
|
1
app/vmalert/testdata/rules0-good.rules
vendored
1
app/vmalert/testdata/rules0-good.rules
vendored
|
@ -6,6 +6,7 @@ groups:
|
||||||
expr: vm_rows > 0
|
expr: vm_rows > 0
|
||||||
labels:
|
labels:
|
||||||
label: bar
|
label: bar
|
||||||
|
template: "{{ $value|humanize }}"
|
||||||
annotations:
|
annotations:
|
||||||
summary: "{{ $value|humanize }}"
|
summary: "{{ $value|humanize }}"
|
||||||
description: "{{$labels}}"
|
description: "{{$labels}}"
|
||||||
|
|
Loading…
Reference in a new issue