diff --git a/main.go b/main.go index a739e00dc..5edcf0689 100644 --- a/main.go +++ b/main.go @@ -225,12 +225,13 @@ func (p *prometheus) reloadConfig() bool { log.Errorf("Note: The configuration format has changed with version 0.14. Please see the documentation (http://prometheus.io/docs/operating/configuration/) and the provided configuration migration tool (https://github.com/prometheus/migrate).") return false } + success := true - p.webService.StatusHandler.ApplyConfig(conf) - p.targetManager.ApplyConfig(conf) - p.ruleManager.ApplyConfig(conf) + success = success && p.webService.StatusHandler.ApplyConfig(conf) + success = success && p.targetManager.ApplyConfig(conf) + success = success && p.ruleManager.ApplyConfig(conf) - return true + return success } // Serve starts the Prometheus server. It returns after the server has been shut diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index 9875d8851..76e1ba33c 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -284,7 +284,8 @@ func (tm *TargetManager) Pools() map[string][]*Target { // ApplyConfig resets the manager's target providers and job configurations as defined // by the new cfg. The state of targets that are valid in the new configuration remains unchanged. -func (tm *TargetManager) ApplyConfig(cfg *config.Config) { +// Returns true on success. +func (tm *TargetManager) ApplyConfig(cfg *config.Config) bool { tm.m.RLock() running := tm.running tm.m.RUnlock() @@ -305,6 +306,7 @@ func (tm *TargetManager) ApplyConfig(cfg *config.Config) { tm.globalLabels = cfg.GlobalConfig.Labels tm.providers = providers + return true } // targetsFromGroup builds targets based on the given TargetGroup and config. diff --git a/rules/manager.go b/rules/manager.go index 6ee51ab40..13b137cee 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -271,11 +271,12 @@ func (m *Manager) runIteration() { } // ApplyConfig updates the rule manager's state as the config requires. If -// loading the new rules failed the old rule set is restored. -func (m *Manager) ApplyConfig(conf *config.Config) { +// loading the new rules failed the old rule set is restored. Returns true on success. +func (m *Manager) ApplyConfig(conf *config.Config) bool { m.Lock() defer m.Unlock() + success := true m.interval = time.Duration(conf.GlobalConfig.EvaluationInterval) rulesSnapshot := make([]Rule, len(m.rules)) @@ -288,6 +289,7 @@ func (m *Manager) ApplyConfig(conf *config.Config) { if err != nil { // The only error can be a bad pattern. log.Errorf("Error retrieving rule files for %s: %s", pat, err) + success = false } files = append(files, fs...) } @@ -295,7 +297,9 @@ func (m *Manager) ApplyConfig(conf *config.Config) { // If loading the new rules failed, restore the old rule set. m.rules = rulesSnapshot log.Errorf("Error loading rules, previous rule set restored: %s", err) + success = false } + return success } // loadRuleFiles loads alerting and recording rules from the given files. diff --git a/web/status.go b/web/status.go index 6f92c51c4..082ce01fc 100644 --- a/web/status.go +++ b/web/status.go @@ -54,8 +54,10 @@ func (h *PrometheusStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque } // ApplyConfig updates the status handler's state as the new config requires. -func (h *PrometheusStatusHandler) ApplyConfig(conf *config.Config) { +// Returns true on success. +func (h *PrometheusStatusHandler) ApplyConfig(conf *config.Config) bool { h.mu.Lock() h.Config = conf.String() h.mu.Unlock() + return true }