Inherit grouping labels, default grouping labels

This commit is contained in:
Fabian Reinartz 2015-10-19 17:35:59 +02:00
parent cb0ecd9416
commit 6cbd7f5511
5 changed files with 22 additions and 15 deletions

View File

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

View File

@ -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,

View File

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

View File

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

View File

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