mirror of
https://github.com/prometheus/alertmanager
synced 2025-04-08 10:12:35 +00:00
config: root route should have empty matchers
Unmarshal should validate that the root route does not contain any matchers. Prior to this change, only the deprecated match structures were checked. Signed-off-by: Philip Gough <philip.p.gough@gmail.com>
This commit is contained in:
parent
ec83f71257
commit
f8c06b4dc8
@ -471,7 +471,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
if len(c.Route.Receiver) == 0 {
|
if len(c.Route.Receiver) == 0 {
|
||||||
return fmt.Errorf("root route must specify a default receiver")
|
return fmt.Errorf("root route must specify a default receiver")
|
||||||
}
|
}
|
||||||
if len(c.Route.Match) > 0 || len(c.Route.MatchRE) > 0 {
|
if len(c.Route.Match) > 0 || len(c.Route.MatchRE) > 0 || len(c.Route.Matchers) > 0 {
|
||||||
return fmt.Errorf("root route must not have any matchers")
|
return fmt.Errorf("root route must not have any matchers")
|
||||||
}
|
}
|
||||||
if len(c.Route.MuteTimeIntervals) > 0 {
|
if len(c.Route.MuteTimeIntervals) > 0 {
|
||||||
|
@ -359,26 +359,47 @@ route:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRootRouteHasNoMatcher(t *testing.T) {
|
func TestRootRouteHasNoMatcher(t *testing.T) {
|
||||||
in := `
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
in string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Test deprecated matchers on root route not allowed",
|
||||||
|
in: `
|
||||||
route:
|
route:
|
||||||
receiver: 'team-X'
|
receiver: 'team-X'
|
||||||
match:
|
match:
|
||||||
severity: critical
|
severity: critical
|
||||||
|
|
||||||
receivers:
|
receivers:
|
||||||
- name: 'team-X'
|
- name: 'team-X'
|
||||||
`
|
`,
|
||||||
_, err := Load(in)
|
},
|
||||||
|
{
|
||||||
|
name: "Test matchers not allowed on root route",
|
||||||
|
in: `
|
||||||
|
route:
|
||||||
|
receiver: 'team-X'
|
||||||
|
matchers:
|
||||||
|
- severity=critical
|
||||||
|
receivers:
|
||||||
|
- name: 'team-X'
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
}
|
||||||
expected := "root route must not have any matchers"
|
expected := "root route must not have any matchers"
|
||||||
|
|
||||||
if err == nil {
|
for _, tc := range testCases {
|
||||||
t.Fatalf("no error returned, expected:\n%q", expected)
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
}
|
_, err := Load(tc.in)
|
||||||
if err.Error() != expected {
|
|
||||||
t.Errorf("\nexpected:\n%q\ngot:\n%q", expected, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("no error returned, expected:\n%q", expected)
|
||||||
|
}
|
||||||
|
if err.Error() != expected {
|
||||||
|
t.Errorf("\nexpected:\n%q\ngot:\n%q", expected, err.Error())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContinueErrorInRouteRoot(t *testing.T) {
|
func TestContinueErrorInRouteRoot(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user