From 4d964a0a0de828470f95681bd8a3e0313d6c6728 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Fri, 24 Nov 2017 08:22:57 +0100 Subject: [PATCH] rules: make glob expansion a concern of main --- cmd/prometheus/main.go | 10 ++++++++++ rules/manager.go | 14 +------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index f696d739db..01bf1710f8 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -278,6 +278,16 @@ func main() { webHandler.ApplyConfig, notifier.ApplyConfig, func(cfg *config.Config) error { + // Get all rule files matching the configuration oaths. + var files []string + for _, pat := range cfg.RuleFiles { + fs, err := filepath.Glob(pat) + if err != nil { + // The only error can be a bad pattern. + return fmt.Errorf("error retrieving rule files for %s: %s", pat, err) + } + files = append(files, fs...) + } return ruleManager.Update(time.Duration(cfg.GlobalConfig.EvaluationInterval), cfg.RuleFiles) }, } diff --git a/rules/manager.go b/rules/manager.go index 4c5ef93824..742d0eb404 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -19,7 +19,6 @@ import ( "fmt" "math" "net/url" - "path/filepath" "sort" "sync" "time" @@ -506,21 +505,10 @@ func (m *Manager) Stop() { // Update the rule manager's state as the config requires. If // loading the new rules failed the old rule set is restored. -func (m *Manager) Update(interval time.Duration, paths []string) error { +func (m *Manager) Update(interval time.Duration, files []string) error { m.mtx.Lock() defer m.mtx.Unlock() - // Get all rule files and load the groups they define. - var files []string - for _, pat := range paths { - fs, err := filepath.Glob(pat) - if err != nil { - // The only error can be a bad pattern. - return fmt.Errorf("error retrieving rule files for %s: %s", pat, err) - } - files = append(files, fs...) - } - // To be replaced with a configurable per-group interval. groups, errs := m.loadGroups(interval, files...) if errs != nil {