Fix group and repeat interval differentiation

This commit is contained in:
Fabian Reinartz 2015-09-26 18:03:54 +02:00
parent c05c028975
commit 797bfa1468
3 changed files with 18 additions and 18 deletions

View File

@ -101,10 +101,10 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
// A Route is a node that contains definitions of how to handle alerts.
type Route struct {
SendTo string `yaml:"send_to,omitempty"`
GroupBy []model.LabelName `yaml:"group_by,omitempty"`
GroupWait *model.Duration `yaml:"group_wait,omitempty"`
RepeatInterval *model.Duration `yaml:"repeat_interval,omitempty"`
SendTo string `yaml:"send_to,omitempty"`
GroupBy []model.LabelName `yaml:"group_by,omitempty"`
GroupWait *model.Duration `yaml:"group_wait,omitempty"`
GroupInterval *model.Duration `yaml:"group_interval,omitempty"`
Match map[string]string `yaml:"match,omitempty"`
MatchRE map[string]Regexp `yaml:"match_re,omitempty"`
@ -196,8 +196,8 @@ type NotificationConfig struct {
// Name of this NotificationConfig. Referenced from AggregationRule.
Name string `yaml:"name"`
// Notify when resolved.
SendResolved bool `yaml:"send_resolved"`
SendResolved bool `yaml:"send_resolved"`
RepeatInterval model.Duration `yaml:"repeat_interval"`
PagerdutyConfigs []*PagerdutyConfig `yaml:"pagerduty_configs"`
EmailConfigs []*EmailConfig `yaml:"email_configs"`

View File

@ -203,12 +203,12 @@ func (ag *aggrGroup) run(notify notifyFunc) {
for {
select {
case <-ag.next.C:
// Give the notifcations 2/3 the time of the repeat interval
// to finish before terminating them.
ctx, _ := context.WithTimeout(ag.ctx, ag.opts.RepeatInterval*2/3)
// Give the notifcations time until the next flush to
// finish before terminating them.
ctx, _ := context.WithTimeout(ag.ctx, ag.opts.GroupInterval)
// Wait the configured interval before calling flush again.
ag.next.Reset(ag.opts.RepeatInterval)
ag.next.Reset(ag.opts.GroupInterval)
ag.flush(func(alerts ...*types.Alert) bool {
return notify(ctx, alerts...)

View File

@ -11,8 +11,8 @@ import (
)
var DefaultRouteOpts = RouteOpts{
GroupWait: 1 * time.Second,
RepeatInterval: 10 * time.Second,
GroupWait: 1 * time.Second,
GroupInterval: 10 * time.Second,
}
type Routes []*Route
@ -51,13 +51,13 @@ func NewRoute(cr *config.Route) *Route {
SendTo: cr.SendTo,
GroupBy: groupBy,
hasWait: cr.GroupWait != nil,
hasInterval: cr.RepeatInterval != nil,
hasInterval: cr.GroupInterval != nil,
}
if opts.hasWait {
opts.GroupWait = time.Duration(*cr.GroupWait)
}
if opts.hasInterval {
opts.RepeatInterval = time.Duration(*cr.RepeatInterval)
opts.GroupInterval = time.Duration(*cr.GroupInterval)
}
var matchers types.Matchers
@ -129,8 +129,8 @@ type RouteOpts struct {
// How long to wait to group matching alerts before sending
// a notificaiton
GroupWait time.Duration
RepeatInterval time.Duration
GroupWait time.Duration
GroupInterval time.Duration
hasWait, hasInterval bool
}
@ -140,7 +140,7 @@ func (ro *RouteOpts) String() string {
for ln := range ro.GroupBy {
labels = append(labels, ln)
}
return fmt.Sprintf("<RouteOpts send_to:%q group_by:%q group_wait:%q>", ro.SendTo, labels, ro.GroupWait)
return fmt.Sprintf("<RouteOpts send_to:%q group_by:%q timers:%q|%q>", ro.SendTo, labels, ro.GroupWait, ro.GroupInterval)
}
func (ro *RouteOpts) populateDefault(parent *RouteOpts) {
@ -156,6 +156,6 @@ func (ro *RouteOpts) populateDefault(parent *RouteOpts) {
ro.GroupWait = parent.GroupWait
}
if !ro.hasInterval {
ro.RepeatInterval = parent.RepeatInterval
ro.GroupInterval = parent.GroupInterval
}
}