main: exit on invalid rule files on startup.

This commit is contained in:
Fabian Reinartz 2015-06-02 18:44:41 +02:00
parent 867f2ac979
commit 280d11dca8
4 changed files with 17 additions and 8 deletions

View File

@ -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).") 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 return false
} }
success := true
p.webService.StatusHandler.ApplyConfig(conf) success = success && p.webService.StatusHandler.ApplyConfig(conf)
p.targetManager.ApplyConfig(conf) success = success && p.targetManager.ApplyConfig(conf)
p.ruleManager.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 // Serve starts the Prometheus server. It returns after the server has been shut

View File

@ -284,7 +284,8 @@ func (tm *TargetManager) Pools() map[string][]*Target {
// ApplyConfig resets the manager's target providers and job configurations as defined // 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. // 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() tm.m.RLock()
running := tm.running running := tm.running
tm.m.RUnlock() tm.m.RUnlock()
@ -305,6 +306,7 @@ func (tm *TargetManager) ApplyConfig(cfg *config.Config) {
tm.globalLabels = cfg.GlobalConfig.Labels tm.globalLabels = cfg.GlobalConfig.Labels
tm.providers = providers tm.providers = providers
return true
} }
// targetsFromGroup builds targets based on the given TargetGroup and config. // targetsFromGroup builds targets based on the given TargetGroup and config.

View File

@ -271,11 +271,12 @@ func (m *Manager) runIteration() {
} }
// ApplyConfig updates the rule manager's state as the config requires. If // ApplyConfig updates the rule manager's state as the config requires. If
// loading the new rules failed the old rule set is restored. // loading the new rules failed the old rule set is restored. Returns true on success.
func (m *Manager) ApplyConfig(conf *config.Config) { func (m *Manager) ApplyConfig(conf *config.Config) bool {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
success := true
m.interval = time.Duration(conf.GlobalConfig.EvaluationInterval) m.interval = time.Duration(conf.GlobalConfig.EvaluationInterval)
rulesSnapshot := make([]Rule, len(m.rules)) rulesSnapshot := make([]Rule, len(m.rules))
@ -288,6 +289,7 @@ func (m *Manager) ApplyConfig(conf *config.Config) {
if err != nil { if err != nil {
// The only error can be a bad pattern. // The only error can be a bad pattern.
log.Errorf("Error retrieving rule files for %s: %s", pat, err) log.Errorf("Error retrieving rule files for %s: %s", pat, err)
success = false
} }
files = append(files, fs...) 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. // If loading the new rules failed, restore the old rule set.
m.rules = rulesSnapshot m.rules = rulesSnapshot
log.Errorf("Error loading rules, previous rule set restored: %s", err) 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. // loadRuleFiles loads alerting and recording rules from the given files.

View File

@ -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. // 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.mu.Lock()
h.Config = conf.String() h.Config = conf.String()
h.mu.Unlock() h.mu.Unlock()
return true
} }