Use consistent naming for mute time intervals

Signed-off-by: Ben Ridley <benridley29@gmail.com>
This commit is contained in:
Ben Ridley 2020-11-24 15:02:07 +11:00
parent 5152a2fbba
commit 5d4231b001
6 changed files with 28 additions and 28 deletions

View File

@ -431,7 +431,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
if len(c.Route.Match) > 0 || len(c.Route.MatchRE) > 0 {
return fmt.Errorf("root route must not have any matchers")
}
if len(c.Route.MuteTimes) > 0 {
if len(c.Route.MuteTimeIntervals) > 0 {
return fmt.Errorf("root route cannot have any mute times")
}
@ -473,10 +473,10 @@ func checkTimeInterval(r *Route, timeIntervals map[string]struct{}) error {
return err
}
}
if len(r.MuteTimes) == 0 {
if len(r.MuteTimeIntervals) == 0 {
return nil
}
for _, mt := range r.MuteTimes {
for _, mt := range r.MuteTimeIntervals {
if _, ok := timeIntervals[mt]; !ok {
return fmt.Errorf("undefined time interval %q used in route", mt)
}
@ -632,7 +632,7 @@ type Route struct {
Match map[string]string `yaml:"match,omitempty" json:"match,omitempty"`
MatchRE MatchRegexps `yaml:"match_re,omitempty" json:"match_re,omitempty"`
MuteTimes []string `yaml:"mute_times,omitempty" json:"mute_times,omitempty"`
MuteTimeIntervals []string `yaml:"mute_time_intervals,omitempty" json:"mute_time_intervals,omitempty"`
Continue bool `yaml:"continue" json:"continue,omitempty"`
Routes []*Route `yaml:"routes,omitempty" json:"routes,omitempty"`

View File

@ -158,7 +158,7 @@ route:
routes:
- match:
severity: critical
mute_times:
mute_time_intervals:
- business_hours
receivers:
@ -194,7 +194,7 @@ route:
routes:
- match:
severity: critical
mute_times:
mute_time_intervals:
- business_hours
`
_, err := Load(in)
@ -232,7 +232,7 @@ route:
routes:
- match:
severity: critical
mute_times:
mute_time_intervals:
- business_hours
`
_, err := Load(in)
@ -342,7 +342,7 @@ receivers:
route:
receiver: 'team-X-mails'
mute_times:
mute_time_intervals:
- my_mute_time
`
_, err := Load(in)

View File

@ -404,7 +404,7 @@ func (ag *aggrGroup) run(nf notifyFunc) {
ctx = notify.WithGroupLabels(ctx, ag.labels)
ctx = notify.WithReceiverName(ctx, ag.opts.Receiver)
ctx = notify.WithRepeatInterval(ctx, ag.opts.RepeatInterval)
ctx = notify.WithMuteTimes(ctx, ag.opts.MuteTimes)
ctx = notify.WithMuteTimeIntervals(ctx, ag.opts.MuteTimeIntervals)
// Wait the configured interval before calling flush again.
ag.mtx.Lock()

View File

@ -34,7 +34,7 @@ var DefaultRouteOpts = RouteOpts{
RepeatInterval: 4 * time.Hour,
GroupBy: map[model.LabelName]struct{}{},
GroupByAll: false,
MuteTimes: []string{},
MuteTimeIntervals: []string{},
}
// A Route is a node that contains definitions of how to handle alerts.
@ -117,7 +117,7 @@ func NewRoute(cr *config.Route, parent *Route) *Route {
sort.Sort(matchers)
opts.MuteTimes = cr.MuteTimes
opts.MuteTimeIntervals = cr.MuteTimeIntervals
route := &Route{
parent: parent,
@ -208,8 +208,8 @@ type RouteOpts struct {
GroupInterval time.Duration
RepeatInterval time.Duration
// A list of time intervals for which the route is muted
MuteTimes []string
// A list of time intervals for which the route is muted.
MuteTimeIntervals []string
}
func (ro *RouteOpts) String() string {

View File

@ -109,7 +109,7 @@ const (
keyFiringAlerts
keyResolvedAlerts
keyNow
keyMuteTimes
keyMuteTimeIntervals
)
// WithReceiverName populates a context with a receiver name.
@ -147,9 +147,9 @@ func WithRepeatInterval(ctx context.Context, t time.Duration) context.Context {
return context.WithValue(ctx, keyRepeatInterval, t)
}
// WithMuteTimes populates a context with a slice of mute time names.
func WithMuteTimes(ctx context.Context, mt []string) context.Context {
return context.WithValue(ctx, keyMuteTimes, mt)
// WithMuteTimeIntervals populates a context with a slice of mute time names.
func WithMuteTimeIntervals(ctx context.Context, mt []string) context.Context {
return context.WithValue(ctx, keyMuteTimeIntervals, mt)
}
// RepeatInterval extracts a repeat interval from the context. Iff none exists, the
@ -201,10 +201,10 @@ func ResolvedAlerts(ctx context.Context) ([]uint64, bool) {
return v, ok
}
// MuteTimeNames extracts a slice of mute time names from the context. Iff none exists, the
// MuteTimeIntervalNames extracts a slice of mute time names from the context. Iff none exists, the
// second argument is false.
func MuteTimeNames(ctx context.Context) ([]string, bool) {
v, ok := ctx.Value(keyMuteTimes).([]string)
func MuteTimeIntervalNames(ctx context.Context) ([]string, bool) {
v, ok := ctx.Value(keyMuteTimeIntervals).([]string)
return v, ok
}
@ -783,7 +783,7 @@ func NewTimeMuteStage(mt map[string][]timeinterval.TimeInterval) *TimeMuteStage
// Exec implements the stage interface for TimeMuteStage.
// TimeMuteStage is responsible for muting alerts whose route is not in an active time.
func (tms TimeMuteStage) Exec(ctx context.Context, l log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error) {
muteTimeNames, ok := MuteTimeNames(ctx)
muteTimeIntervalNames, ok := MuteTimeIntervalNames(ctx)
if !ok {
return ctx, alerts, nil
}
@ -794,7 +794,7 @@ func (tms TimeMuteStage) Exec(ctx context.Context, l log.Logger, alerts ...*type
muted := false
Loop:
for _, mtName := range muteTimeNames {
for _, mtName := range muteTimeIntervalNames {
mt, ok := tms.muteTimes[mtName]
if !ok {
return ctx, alerts, errors.Errorf("mute time %s doesn't exist in config", mtName)

View File

@ -787,7 +787,7 @@ func TestTimeMuteStage(t *testing.T) {
alerts := []*types.Alert{{Alert: a}}
ctx := context.Background()
ctx = WithNow(ctx, now)
ctx = WithMuteTimes(ctx, []string{"test"})
ctx = WithMuteTimeIntervals(ctx, []string{"test"})
_, out, err := stage.Exec(ctx, log.NewNopLogger(), alerts...)
if err != nil {