Always assume success on reload of valid config

This commit is contained in:
Fabian Reinartz 2015-10-09 09:05:21 +02:00
parent 42e1963715
commit 9bf18ec4a5
5 changed files with 13 additions and 19 deletions

View File

@ -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.

View File

@ -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

18
main.go
View File

@ -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
}

View File

@ -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

View File

@ -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