Skip to content

Commit

Permalink
Inherit their parent route's grouping when "group_by: [...]"
Browse files Browse the repository at this point in the history
Signed-off-by: Sho Okada <shokada3@gmail.com>
  • Loading branch information
shokada committed Jan 3, 2020
1 parent 134c3c0 commit a9c6b91
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dispatch/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
31 changes: 31 additions & 0 deletions dispatch/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

0 comments on commit a9c6b91

Please sign in to comment.