diff --git a/route.go b/route.go index 3a14b6e9..d53ccd92 100644 --- a/route.go +++ b/route.go @@ -28,6 +28,9 @@ var DefaultRouteOpts = RouteOpts{ GroupInterval: 5 * time.Minute, RepeatInterval: 4 * time.Hour, SendResolved: true, + GroupBy: map[model.LabelName]struct{}{ + model.AlertNameLabel: struct{}{}, + }, } // A Route is a node that contains definitions of how to handle alerts. @@ -50,18 +53,19 @@ func NewRoute(cr *config.Route, parent *RouteOpts) *Route { if parent == nil { parent = &DefaultRouteOpts } - groupBy := map[model.LabelName]struct{}{} - for _, ln := range cr.GroupBy { - groupBy[ln] = struct{}{} - } // Create default and overwrite with configured settings. opts := *parent - opts.GroupBy = groupBy if cr.SendTo != "" { opts.SendTo = cr.SendTo } + if cr.GroupBy != nil { + opts.GroupBy = map[model.LabelName]struct{}{} + for _, ln := range cr.GroupBy { + opts.GroupBy[ln] = struct{}{} + } + } if cr.GroupWait != nil { opts.GroupWait = time.Duration(*cr.GroupWait) } diff --git a/route_test.go b/route_test.go index 524a2e67..e61cfad4 100644 --- a/route_test.go +++ b/route_test.go @@ -39,6 +39,7 @@ routes: env: 'testing' send_to: 'notify-testing' + group_by: [] - match: env: "production" @@ -72,13 +73,8 @@ routes: t.Fatal(err) } var ( - def = &RouteOpts{ - GroupWait: 20 * time.Second, - GroupInterval: 5 * time.Minute, - RepeatInterval: 1 * time.Hour, - SendResolved: true, - } - tree = NewRoute(&ctree, def) + def = DefaultRouteOpts + tree = NewRoute(&ctree, &def) ) lset := func(labels ...string) map[model.LabelName]struct{} { s := map[model.LabelName]struct{}{} @@ -99,7 +95,7 @@ routes: result: []*RouteOpts{ { SendTo: "notify-A", - GroupBy: lset(), + GroupBy: def.GroupBy, GroupWait: def.GroupWait, GroupInterval: def.GroupInterval, RepeatInterval: def.RepeatInterval, @@ -115,7 +111,7 @@ routes: result: []*RouteOpts{ { SendTo: "notify-A", - GroupBy: lset(), + GroupBy: def.GroupBy, GroupWait: def.GroupWait, GroupInterval: def.GroupInterval, RepeatInterval: def.RepeatInterval, @@ -162,7 +158,7 @@ routes: result: []*RouteOpts{ { SendTo: "notify-productionA", - GroupBy: lset(), + GroupBy: def.GroupBy, GroupWait: 1 * time.Minute, GroupInterval: def.GroupInterval, RepeatInterval: def.RepeatInterval, diff --git a/test/acceptance/inhibit_test.go b/test/acceptance/inhibit_test.go index 2720d562..559bf3dc 100644 --- a/test/acceptance/inhibit_test.go +++ b/test/acceptance/inhibit_test.go @@ -27,6 +27,7 @@ func TestInhibiting(t *testing.T) { conf := ` route: send_to: "default" + group_by: [] group_wait: 1s group_interval: 1s repeat_interval: 1s diff --git a/test/acceptance/send_test.go b/test/acceptance/send_test.go index c7a6917b..acae4dfc 100644 --- a/test/acceptance/send_test.go +++ b/test/acceptance/send_test.go @@ -32,6 +32,7 @@ func TestMergeAlerts(t *testing.T) { conf := ` route: send_to: "default" + group_by: [] group_wait: 1s group_interval: 1s repeat_interval: 1s @@ -73,6 +74,7 @@ func TestRepeat(t *testing.T) { conf := ` route: send_to: "default" + group_by: [] group_wait: 1s group_interval: 1s repeat_interval: 1s @@ -130,6 +132,7 @@ func TestRetry(t *testing.T) { conf := ` route: send_to: "default" + group_by: [] group_wait: 1s group_interval: 1s repeat_interval: 3s @@ -173,6 +176,7 @@ func TestBatching(t *testing.T) { conf := ` route: send_to: "default" + group_by: [] group_wait: 1s group_interval: 1s repeat_interval: 5s diff --git a/test/acceptance/silence_test.go b/test/acceptance/silence_test.go index 9931ce81..3db1ace7 100644 --- a/test/acceptance/silence_test.go +++ b/test/acceptance/silence_test.go @@ -27,6 +27,7 @@ func TestSilencing(t *testing.T) { conf := ` route: send_to: "default" + group_by: [] group_wait: 1s group_interval: 1s repeat_interval: 1s @@ -78,6 +79,7 @@ func TestSilenceDelete(t *testing.T) { conf := ` route: send_to: "default" + group_by: [] group_wait: 1s group_interval: 1s repeat_interval: 1s