Skip to content

Commit

Permalink
Add receiver name to route key
Browse files Browse the repository at this point in the history
This commit adds the receiver name to the route key to reduce the
chances of having non unique group keys (prometheus#3817). Like the previous
version, it does not guarantee the group key is unique, however
it does make it collisions less likely to occur.

Signed-off-by: George Robinson <[email protected]>
  • Loading branch information
grobinson-grafana committed Apr 29, 2024
1 parent 72b62db commit 62e8736
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
4 changes: 4 additions & 0 deletions dispatch/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ func (r *Route) Key() string {
b.WriteString(r.parent.Key())
b.WriteRune('/')
}
b.WriteRune('(')
b.WriteString(r.RouteOpts.Receiver)
b.WriteRune(',')
b.WriteString(r.Matchers.String())
b.WriteRune(')')
return b.String()
}

Expand Down
54 changes: 27 additions & 27 deletions dispatch/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{owner=\"team-A\"}"},
keys: []string{"(notify-def,{})/(notify-A,{owner=\"team-A\"})"},
},
{
input: model.LabelSet{
Expand All @@ -133,7 +133,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{owner=\"team-A\"}"},
keys: []string{"(notify-def,{})/(notify-A,{owner=\"team-A\"})"},
},
{
input: model.LabelSet{
Expand All @@ -149,7 +149,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{owner=~\"^(?:team-(B|C))$\"}"},
keys: []string{"(notify-def,{})/(notify-BC,{owner=~\"^(?:team-(B|C))$\"})"},
},
{
input: model.LabelSet{
Expand All @@ -166,7 +166,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{owner=\"team-A\"}/{env=\"testing\"}"},
keys: []string{"(notify-def,{})/(notify-A,{owner=\"team-A\"})/(notify-testing,{env=\"testing\"})"},
},
{
input: model.LabelSet{
Expand All @@ -192,8 +192,8 @@ routes:
},
},
keys: []string{
"{}/{owner=\"team-A\"}/{env=\"production\"}",
"{}/{owner=\"team-A\"}/{env=~\"^(?:produ.*)$\",job=~\"^(?:.*)$\"}",
"(notify-def,{})/(notify-A,{owner=\"team-A\"})/(notify-productionA,{env=\"production\"})",
"(notify-def,{})/(notify-A,{owner=\"team-A\"})/(notify-productionB,{env=~\"^(?:produ.*)$\",job=~\"^(?:.*)$\"})",
},
},
{
Expand All @@ -210,7 +210,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{group_by=\"role\"}"},
keys: []string{"(notify-def,{})/(notify-def,{group_by=\"role\"})"},
},
{
input: model.LabelSet{
Expand All @@ -227,7 +227,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{group_by=\"role\"}/{env=\"testing\"}"},
keys: []string{"(notify-def,{})/(notify-def,{group_by=\"role\"})/(notify-testing,{env=\"testing\"})"},
},
{
input: model.LabelSet{
Expand All @@ -245,7 +245,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{group_by=\"role\"}/{env=\"testing\"}/{wait=\"long\"}"},
keys: []string{"(notify-def,{})/(notify-def,{group_by=\"role\"})/(notify-testing,{env=\"testing\"})/(notify-testing,{wait=\"long\"})"},
},
}

Expand Down Expand Up @@ -466,7 +466,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{level!=\"critical\",owner=\"team-A\"}"},
keys: []string{"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})"},
},
{
input: model.LabelSet{
Expand All @@ -483,7 +483,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{level!=\"critical\",owner=\"team-A\"}"},
keys: []string{"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})"},
},
{
input: model.LabelSet{
Expand All @@ -499,7 +499,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{owner=~\"team-(B|C)\"}"},
keys: []string{"(notify-def,{})/(notify-BC,{owner=~\"team-(B|C)\"})"},
},
{
input: model.LabelSet{
Expand All @@ -516,7 +516,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{level!=\"critical\",owner=\"team-A\"}/{baz!~\".*quux\",env=\"testing\"}"},
keys: []string{"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})/(notify-testing,{baz!~\".*quux\",env=\"testing\"})"},
},
{
input: model.LabelSet{
Expand All @@ -542,8 +542,8 @@ routes:
},
},
keys: []string{
"{}/{level!=\"critical\",owner=\"team-A\"}/{env=\"production\"}",
"{}/{level!=\"critical\",owner=\"team-A\"}/{env=~\"produ.*\",job=~\".*\"}",
"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})/(notify-productionA,{env=\"production\"})",
"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})/(notify-productionB,{env=~\"produ.*\",job=~\".*\"})",
},
},
{
Expand All @@ -560,7 +560,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{group_by=\"role\"}"},
keys: []string{"(notify-def,{})/(notify-def,{group_by=\"role\"})"},
},
{
input: model.LabelSet{
Expand All @@ -577,7 +577,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{group_by=\"role\"}/{env=\"testing\"}"},
keys: []string{"(notify-def,{})/(notify-def,{group_by=\"role\"})/(notify-testing,{env=\"testing\"})"},
},
{
input: model.LabelSet{
Expand All @@ -595,7 +595,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{group_by=\"role\"}/{env=\"testing\"}/{wait=\"long\"}"},
keys: []string{"(notify-def,{})/(notify-def,{group_by=\"role\"})/(notify-testing,{env=\"testing\"})/(notify-testing,{wait=\"long\"})"},
},
}

Expand Down Expand Up @@ -702,7 +702,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{level!=\"critical\",owner=\"team-A\"}"},
keys: []string{"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})"},
},
{
input: model.LabelSet{
Expand All @@ -719,7 +719,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{level!=\"critical\",owner=\"team-A\"}"},
keys: []string{"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})"},
},
{
input: model.LabelSet{
Expand All @@ -735,7 +735,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{owner=~\"^(?:team-(B|C))$\"}"},
keys: []string{"(notify-def,{})/(notify-BC,{owner=~\"^(?:team-(B|C))$\"})"},
},
{
input: model.LabelSet{
Expand All @@ -752,7 +752,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{level!=\"critical\",owner=\"team-A\"}/{baz!~\".*quux\",env=\"testing\"}"},
keys: []string{"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})/(notify-testing,{baz!~\".*quux\",env=\"testing\"})"},
},
{
input: model.LabelSet{
Expand All @@ -778,8 +778,8 @@ routes:
},
},
keys: []string{
"{}/{level!=\"critical\",owner=\"team-A\"}/{env=\"production\"}",
"{}/{level!=\"critical\",owner=\"team-A\"}/{env=~\"produ.*\",job=~\".*\"}",
"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})/(notify-productionA,{env=\"production\"})",
"(notify-def,{})/(notify-A,{level!=\"critical\",owner=\"team-A\"})/(notify-productionB,{env=~\"produ.*\",job=~\".*\"})",
},
},
{
Expand All @@ -796,7 +796,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{group_by=\"role\"}"},
keys: []string{"(notify-def,{})/(notify-def,{group_by=\"role\"})"},
},
{
input: model.LabelSet{
Expand All @@ -813,7 +813,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{group_by=\"role\"}/{env=\"testing\"}"},
keys: []string{"(notify-def,{})/(notify-def,{group_by=\"role\"})/(notify-testing,{env=\"testing\"})"},
},
{
input: model.LabelSet{
Expand All @@ -831,7 +831,7 @@ routes:
RepeatInterval: def.RepeatInterval,
},
},
keys: []string{"{}/{group_by=\"role\"}/{env=\"testing\"}/{wait=\"long\"}"},
keys: []string{"(notify-def,{})/(notify-def,{group_by=\"role\"})/(notify-testing,{env=\"testing\"})/(notify-testing,{wait=\"long\"})"},
},
}

Expand Down

0 comments on commit 62e8736

Please sign in to comment.