rules: make glob expansion a concern of main

This commit is contained in:
Fabian Reinartz 2017-11-24 08:22:57 +01:00
parent bd9f7460eb
commit 4d964a0a0d
2 changed files with 11 additions and 13 deletions

View File

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

View File

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