|
|
|
@ -272,12 +272,14 @@ func main() {
|
|
|
|
|
conntrack.DialWithTracing(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
reloadables := []Reloadable{
|
|
|
|
|
remoteStorage,
|
|
|
|
|
targetManager,
|
|
|
|
|
ruleManager,
|
|
|
|
|
webHandler,
|
|
|
|
|
notifier,
|
|
|
|
|
reloaders := []func(cfg *config.Config) error{
|
|
|
|
|
remoteStorage.ApplyConfig,
|
|
|
|
|
targetManager.ApplyConfig,
|
|
|
|
|
webHandler.ApplyConfig,
|
|
|
|
|
notifier.ApplyConfig,
|
|
|
|
|
func(cfg *config.Config) error {
|
|
|
|
|
return ruleManager.Update(time.Duration(cfg.GlobalConfig.EvaluationInterval), cfg.RuleFiles)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prometheus.MustRegister(configSuccess)
|
|
|
|
@ -330,11 +332,11 @@ func main() {
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case <-hup:
|
|
|
|
|
if err := reloadConfig(cfg.configFile, logger, reloadables...); err != nil {
|
|
|
|
|
if err := reloadConfig(cfg.configFile, logger, reloaders...); err != nil {
|
|
|
|
|
level.Error(logger).Log("msg", "Error reloading config", "err", err)
|
|
|
|
|
}
|
|
|
|
|
case rc := <-webHandler.Reload():
|
|
|
|
|
if err := reloadConfig(cfg.configFile, logger, reloadables...); err != nil {
|
|
|
|
|
if err := reloadConfig(cfg.configFile, logger, reloaders...); err != nil {
|
|
|
|
|
level.Error(logger).Log("msg", "Error reloading config", "err", err)
|
|
|
|
|
rc <- err
|
|
|
|
|
} else {
|
|
|
|
@ -363,7 +365,7 @@ func main() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := reloadConfig(cfg.configFile, logger, reloadables...); err != nil {
|
|
|
|
|
if err := reloadConfig(cfg.configFile, logger, reloaders...); err != nil {
|
|
|
|
|
return fmt.Errorf("Error loading config %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -473,13 +475,7 @@ func main() {
|
|
|
|
|
level.Info(logger).Log("msg", "See you next time!")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reloadable things can change their internal state to match a new config
|
|
|
|
|
// and handle failure gracefully.
|
|
|
|
|
type Reloadable interface {
|
|
|
|
|
ApplyConfig(*config.Config) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func reloadConfig(filename string, logger log.Logger, rls ...Reloadable) (err error) {
|
|
|
|
|
func reloadConfig(filename string, logger log.Logger, rls ...func(*config.Config) error) (err error) {
|
|
|
|
|
level.Info(logger).Log("msg", "Loading configuration file", "filename", filename)
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
@ -498,7 +494,7 @@ func reloadConfig(filename string, logger log.Logger, rls ...Reloadable) (err er
|
|
|
|
|
|
|
|
|
|
failed := false
|
|
|
|
|
for _, rl := range rls {
|
|
|
|
|
if err := rl.ApplyConfig(conf); err != nil {
|
|
|
|
|
if err := rl(conf); err != nil {
|
|
|
|
|
level.Error(logger).Log("msg", "Failed to apply configuration", "err", err)
|
|
|
|
|
failed = true
|
|
|
|
|
}
|
|
|
|
|