mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Set evaluation interval on Group construction
Prevents having object in invalid state, and allows users of public API to construct valid Groups.
This commit is contained in:
parent
31fc357cd8
commit
d78dd3593d
|
@ -126,9 +126,10 @@ type Group struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGroup makes a new Group with the given name, options, and rules.
|
// NewGroup makes a new Group with the given name, options, and rules.
|
||||||
func NewGroup(name string, rules []Rule, opts *ManagerOptions) *Group {
|
func NewGroup(name string, interval time.Duration, rules []Rule, opts *ManagerOptions) *Group {
|
||||||
return &Group{
|
return &Group{
|
||||||
name: name,
|
name: name,
|
||||||
|
interval: interval,
|
||||||
rules: rules,
|
rules: rules,
|
||||||
opts: opts,
|
opts: opts,
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
|
@ -396,7 +397,8 @@ func (m *Manager) ApplyConfig(conf *config.Config) error {
|
||||||
files = append(files, fs...)
|
files = append(files, fs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
groups, err := m.loadGroups(files...)
|
// To be replaced with a configurable per-group interval.
|
||||||
|
groups, err := m.loadGroups(time.Duration(conf.GlobalConfig.EvaluationInterval), files...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error loading rules, previous rule set restored: %s", err)
|
return fmt.Errorf("error loading rules, previous rule set restored: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -404,9 +406,6 @@ func (m *Manager) ApplyConfig(conf *config.Config) error {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
for _, newg := range groups {
|
for _, newg := range groups {
|
||||||
// To be replaced with a configurable per-group interval.
|
|
||||||
newg.interval = time.Duration(conf.GlobalConfig.EvaluationInterval)
|
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
// If there is an old group with the same identifier, stop it and wait for
|
// If there is an old group with the same identifier, stop it and wait for
|
||||||
|
@ -444,7 +443,7 @@ func (m *Manager) ApplyConfig(conf *config.Config) error {
|
||||||
// loadGroups reads groups from a list of files.
|
// loadGroups reads groups from a list of files.
|
||||||
// As there's currently no group syntax a single group named "default" containing
|
// As there's currently no group syntax a single group named "default" containing
|
||||||
// all rules will be returned.
|
// all rules will be returned.
|
||||||
func (m *Manager) loadGroups(filenames ...string) (map[string]*Group, error) {
|
func (m *Manager) loadGroups(interval time.Duration, filenames ...string) (map[string]*Group, error) {
|
||||||
rules := []Rule{}
|
rules := []Rule{}
|
||||||
for _, fn := range filenames {
|
for _, fn := range filenames {
|
||||||
content, err := ioutil.ReadFile(fn)
|
content, err := ioutil.ReadFile(fn)
|
||||||
|
@ -475,7 +474,7 @@ func (m *Manager) loadGroups(filenames ...string) (map[string]*Group, error) {
|
||||||
|
|
||||||
// Currently there is no group syntax implemented. Thus all rules
|
// Currently there is no group syntax implemented. Thus all rules
|
||||||
// are read into a single default group.
|
// are read into a single default group.
|
||||||
g := NewGroup("default", rules, m.opts)
|
g := NewGroup("default", interval, rules, m.opts)
|
||||||
groups := map[string]*Group{g.name: g}
|
groups := map[string]*Group{g.name: g}
|
||||||
return groups, nil
|
return groups, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue