Alerting: Modify configuration apply and save semantics - v2 (#34143)

* Save default configuration to the database and copy over secure settings
This commit is contained in:
gotjosh
2021-05-14 19:49:54 +01:00
committed by GitHub
parent 4d161f9fb2
commit eb74994b8b
10 changed files with 391 additions and 47 deletions
@@ -447,6 +447,21 @@ func (c *PostableApiAlertingConfig) validate() error {
return fmt.Errorf("cannot mix Alertmanager & Grafana receiver types")
}
if hasGrafReceivers {
// Taken from https://github.com/prometheus/alertmanager/blob/master/config/config.go#L170-L191
// Check if we have a root route. We cannot check for it in the
// UnmarshalYAML method because it won't be called if the input is empty
// (e.g. the config file is empty or only contains whitespace).
if c.Route == nil {
return fmt.Errorf("no route provided in config")
}
// Check if continue in root route.
if c.Route.Continue {
return fmt.Errorf("cannot have continue in root route")
}
}
for _, receiver := range AllReceivers(c.Route) {
_, ok := receivers[receiver]
if !ok {
@@ -475,9 +490,14 @@ func (c *PostableApiAlertingConfig) ReceiverType() ReceiverType {
// AllReceivers will recursively walk a routing tree and return a list of all the
// referenced receiver names.
func AllReceivers(route *config.Route) (res []string) {
if route == nil {
return res
}
if route.Receiver != "" {
res = append(res, route.Receiver)
}
for _, subRoute := range route.Routes {
res = append(res, AllReceivers(subRoute)...)
}