Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
MAtcher nå på ressurs-navn, ikke team-label
Browse files Browse the repository at this point in the history
Dette vil være bakoverkompatibelt, da gamle routes/matches kun blir endret når de applyer nå konfig. Endringen går heller ikke i beina til Naisd-alerts, da de fortsatt bruker team-label, mens nye alerts ikke bruker team-label i det hele tatt.
  • Loading branch information
Kyrremann committed May 6, 2019
1 parent 2c20282 commit 19b0dfe
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
18 changes: 9 additions & 9 deletions api/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var AlertResource = &v1alpha1.Alert{
ObjectMeta: metav1.ObjectMeta{
Name: "aura",
Labels: map[string]string{
"team": "aura",
"alert": "aura",
},
},
Spec: v1alpha1.AlertSpec{
Expand Down Expand Up @@ -42,7 +42,7 @@ var MinimalAlertResource = &v1alpha1.Alert{
ObjectMeta: metav1.ObjectMeta{
Name: "aura",
Labels: map[string]string{
"team": "aura",
"alert": "aura",
},
},
Spec: v1alpha1.AlertSpec{
Expand Down Expand Up @@ -101,11 +101,11 @@ route:
- receiver: aura
continue: true
match:
team: aura
alert: aura
- receiver: testmann
continue: true
match:
team: testmann`,
alert: testmann`,
},
}

Expand Down Expand Up @@ -141,7 +141,7 @@ route:
- receiver: testmann
continue: true
match:
team: testmann
alert: testmann
templates:
- /etc/config/alert.tmpl
`,
Expand Down Expand Up @@ -181,7 +181,7 @@ route:
- receiver: testmann
continue: true
match:
team: testmann
alert: testmann
templates:
- /etc/config/alert.tmpl`,
},
Expand Down Expand Up @@ -230,11 +230,11 @@ route:
- receiver: testmann
continue: true
match:
team: testmann
alert: testmann
- receiver: aura
continue: true
match:
team: aura
alert: aura
templates:
- /etc/config/alert.tmpl
`,
Expand All @@ -261,7 +261,7 @@ var ExpectedConfigMapAfterAlerts = &v1.ConfigMap{
severity: '#eeeeee'
sla: we need to fix this ASAP
labels:
team: aura
alert: aura
`,
},
}
2 changes: 1 addition & 1 deletion api/updater/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func createAlertRules(alert *v1alpha1.Alert) (alertRules []AlertRule) {
Expr: rule.Expr,
For: rule.For,
Labels: map[string]string{
"team": alert.GetTeamName(),
"alert": alert.Name,
},
Annotations: map[string]string{
"action": rule.Action,
Expand Down
2 changes: 1 addition & 1 deletion api/updater/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestAlerts(t *testing.T) {
assert.Len(t, alertRules, 1)

alertRule := alertRules[0]
assert.Equal(t, fixtures.AlertResource.GetTeamName(), alertRule.Labels["team"])
assert.Equal(t, fixtures.AlertResource.Name, alertRule.Labels["alert"])

alert := fixtures.AlertResource.Spec.Alerts[0]
assert.Equal(t, alert.For, alertRule.For)
Expand Down
4 changes: 2 additions & 2 deletions api/updater/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type matchConfig struct {
Team string `mapstructure:"team" yaml:"team"`
Alert string `mapstructure:"alert" yaml:"alert"`
}

type routeConfig struct {
Expand Down Expand Up @@ -60,7 +60,7 @@ func AddOrUpdateRoutes(alert *v1alpha1.Alert, alertManager map[interface{}]inter
Receiver: alert.Name,
Continue: true,
Match: matchConfig{
Team: alert.GetTeamName(),
Alert: alert.Name,
},
}
route.Routes = append(route.Routes, routes)
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/alerterator/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ type AlertSpec struct {
Alerts []Rule `json:"alerts"`
}

func (in *Alert) GetTeamName() string {
return in.Labels["team"]
}

func (in *Alert) CreateEvent(reason, message, typeStr string) *corev1.Event {
return &corev1.Event{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 19b0dfe

Please sign in to comment.