Inherit their parent route's grouping when "group_by: [...]" (#2154)
Signed-off-by: Sho Okada <shokada3@gmail.com>
This commit is contained in:
parent
b4ac213809
commit
04ca507125
|
@ -70,10 +70,13 @@ func NewRoute(cr *config.Route, parent *Route) *Route {
|
||||||
for _, ln := range cr.GroupBy {
|
for _, ln := range cr.GroupBy {
|
||||||
opts.GroupBy[ln] = struct{}{}
|
opts.GroupBy[ln] = struct{}{}
|
||||||
}
|
}
|
||||||
|
opts.GroupByAll = false
|
||||||
|
} else {
|
||||||
|
if cr.GroupByAll {
|
||||||
|
opts.GroupByAll = cr.GroupByAll
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.GroupByAll = cr.GroupByAll
|
|
||||||
|
|
||||||
if cr.GroupWait != nil {
|
if cr.GroupWait != nil {
|
||||||
opts.GroupWait = time.Duration(*cr.GroupWait)
|
opts.GroupWait = time.Duration(*cr.GroupWait)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
"github.com/prometheus/alertmanager/config"
|
"github.com/prometheus/alertmanager/config"
|
||||||
|
@ -352,3 +353,33 @@ routes:
|
||||||
t.Errorf("\nexpected:\n%v\ngot:\n%v", expected, got)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue