diff --git a/dispatch/route.go b/dispatch/route.go index b4606b7f..ae301aaa 100644 --- a/dispatch/route.go +++ b/dispatch/route.go @@ -70,10 +70,13 @@ func NewRoute(cr *config.Route, parent *Route) *Route { for _, ln := range cr.GroupBy { opts.GroupBy[ln] = struct{}{} } + opts.GroupByAll = false + } else { + if cr.GroupByAll { + opts.GroupByAll = cr.GroupByAll + } } - opts.GroupByAll = cr.GroupByAll - if cr.GroupWait != nil { opts.GroupWait = time.Duration(*cr.GroupWait) } diff --git a/dispatch/route_test.go b/dispatch/route_test.go index fdfa7f3d..c87c92c1 100644 --- a/dispatch/route_test.go +++ b/dispatch/route_test.go @@ -19,6 +19,7 @@ import ( "time" "github.com/prometheus/common/model" + "github.com/stretchr/testify/require" "gopkg.in/yaml.v2" "github.com/prometheus/alertmanager/config" @@ -352,3 +353,33 @@ routes: t.Errorf("\nexpected:\n%v\ngot:\n%v", expected, got) } } + +func TestInheritParentGroupByAll(t *testing.T) { + in := ` +routes: +- match: + env: 'parent' + group_by: ['...'] + + routes: + - match: + env: 'child1' + + - match: + env: 'child2' + group_by: ['foo'] +` + + var ctree config.Route + if err := yaml.UnmarshalStrict([]byte(in), &ctree); err != nil { + t.Fatal(err) + } + + tree := NewRoute(&ctree, nil) + parent := tree.Routes[0] + child1 := parent.Routes[0] + child2 := parent.Routes[1] + require.Equal(t, parent.RouteOpts.GroupByAll, true) + require.Equal(t, child1.RouteOpts.GroupByAll, true) + require.Equal(t, child2.RouteOpts.GroupByAll, false) +}