rules: make glob expansion a concern of main
This commit is contained in:
parent
bd9f7460eb
commit
4d964a0a0d
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue