Inherit their parent route's grouping when "group_by: [...]" (#2154)

Signed-off-by: Sho Okada <shokada3@gmail.com>
This commit is contained in:
Sho Okada 2020-01-10 22:20:03 +09:00 committed by Simon Pasquier
parent b4ac213809
commit 04ca507125
2 changed files with 36 additions and 2 deletions

View File

@ -70,9 +70,12 @@ 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
}
}
if cr.GroupWait != nil {
opts.GroupWait = time.Duration(*cr.GroupWait)

View File

@ -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)
}