Altering: validate that the mute time intervals exist when updating routing tree (#51573) (#51762)

* validate that the mute time intervals exist when updating routing tree

* run lint

* add tests

(cherry picked from commit 4a76436be2)

Co-authored-by: Jean-Philippe Quéméner <JohnnyQQQQ@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2022-07-05 13:26:38 -04:00
committed by GitHub
co-authored by Jean-Philippe Quéméner
parent 7f5dec12bd
commit 7955efc62f
3 changed files with 102 additions and 1 deletions
@@ -114,6 +114,21 @@ func (r *Route) ValidateReceivers(receivers map[string]struct{}) error {
return nil
}
func (r *Route) ValidateMuteTimes(muteTimes map[string]struct{}) error {
for _, name := range r.MuteTimeIntervals {
if _, exists := muteTimes[name]; !exists {
return fmt.Errorf("mute time interval '%s' does not exist", name)
}
}
for _, child := range r.Routes {
err := child.ValidateMuteTimes(muteTimes)
if err != nil {
return err
}
}
return nil
}
func (mt *MuteTimeInterval) Validate() error {
s, err := yaml.Marshal(mt.MuteTimeInterval)
if err != nil {