From 9bf18ec4a5c845073e79159d6c470ebf3162df0b Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Fri, 9 Oct 2015 09:05:21 +0200 Subject: [PATCH] Always assume success on reload of valid config --- dispatch.go | 4 +--- inhibit.go | 4 +--- main.go | 18 +++++++++--------- notify/notify.go | 4 +--- types/types.go | 2 +- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/dispatch.go b/dispatch.go index dae4408f..8fcba8c6 100644 --- a/dispatch.go +++ b/dispatch.go @@ -44,7 +44,7 @@ func NewDispatcher(ap provider.Alerts, n notify.Notifier) *Dispatcher { } // ApplyConfig updates the dispatcher to match the new configuration. -func (d *Dispatcher) ApplyConfig(conf *config.Config) bool { +func (d *Dispatcher) ApplyConfig(conf *config.Config) { d.mtx.Lock() defer d.mtx.Unlock() @@ -55,8 +55,6 @@ func (d *Dispatcher) ApplyConfig(conf *config.Config) bool { } d.routes = NewRoutes(conf.Routes, nil) - - return true } // Run starts dispatching alerts incoming via the updates channel. diff --git a/inhibit.go b/inhibit.go index 2e466661..fbe23945 100644 --- a/inhibit.go +++ b/inhibit.go @@ -45,7 +45,7 @@ func (ih *Inhibitor) Mutes(lset model.LabelSet) bool { return false } -func (ih *Inhibitor) ApplyConfig(conf *config.Config) bool { +func (ih *Inhibitor) ApplyConfig(conf *config.Config) { ih.mtx.Lock() defer ih.mtx.Unlock() @@ -53,8 +53,6 @@ func (ih *Inhibitor) ApplyConfig(conf *config.Config) bool { for _, cr := range conf.InhibitRules { ih.rules = append(ih.rules, NewInhibitRule(cr)) } - - return true } // An InhibitRule specifies that a class of (source) alerts should inhibit diff --git a/main.go b/main.go index b9a387b6..81c4c7b3 100644 --- a/main.go +++ b/main.go @@ -107,8 +107,8 @@ func main() { disp := NewDispatcher(alerts, notifier) - if !reloadConfig(*configFile, disp, routedNotifier, inhibitor) { - os.Exit(1) + if err := reloadConfig(*configFile, disp, routedNotifier, inhibitor); err != nil { + log.Fatalf("Couldn't load configuration (-config.file=%s): %v", *configFile, err) } go disp.Run() @@ -129,7 +129,9 @@ func main() { go func() { for range hup { - reloadConfig(*configFile, disp, routedNotifier, inhibitor) + if err := reloadConfig(*configFile, disp, routedNotifier, inhibitor); err != nil { + log.Errorf("Couldn't load configuration (-config.file=%s): %v", *configFile, err) + } } }() @@ -139,18 +141,16 @@ func main() { os.Exit(0) } -func reloadConfig(filename string, rls ...types.Reloadable) (success bool) { +func reloadConfig(filename string, rls ...types.Reloadable) error { log.Infof("Loading configuration file %s", filename) conf, err := config.LoadFile(filename) if err != nil { - log.Errorf("Couldn't load configuration (-config.file=%s): %v", filename, err) - return false + return err } - success = true for _, rl := range rls { - success = success && rl.ApplyConfig(conf) + rl.ApplyConfig(conf) } - return success + return nil } diff --git a/notify/notify.go b/notify/notify.go index cf3aa7a9..47274c47 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -250,13 +250,11 @@ func (n *RoutedNotifier) Notify(ctx context.Context, alerts ...*types.Alert) err return notifier.Notify(ctx, alerts...) } -func (n *RoutedNotifier) ApplyConfig(conf *config.Config) bool { +func (n *RoutedNotifier) ApplyConfig(conf *config.Config) { n.mtx.Lock() defer n.mtx.Unlock() n.notifiers = n.build(conf.NotificationConfigs) - - return true } // MutingNotifier wraps a notifier and applies a Silencer diff --git a/types/types.go b/types/types.go index 6380a523..0af91ea8 100644 --- a/types/types.go +++ b/types/types.go @@ -13,7 +13,7 @@ import ( // Reloadable is a component that can change its state based // on a new configuration. type Reloadable interface { - ApplyConfig(*config.Config) bool + ApplyConfig(*config.Config) } // Alert wraps a model.Alert with additional information relevant