mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
Alerting: Update default route groupBy to [grafana_folder, alertname] (#50052)
* Alerting: Update default route groupBy to [grafana_folder, alertname] Default group by for new routes and migrations is now [grafana_folder, alertname]
This commit is contained in:
@@ -7,8 +7,10 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/prometheus/alertmanager/pkg/labels"
|
||||
"github.com/prometheus/common/model"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
ngModels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -229,8 +231,9 @@ func (m *migration) createDefaultRouteAndReceiver(defaultChannels []*notificatio
|
||||
}
|
||||
|
||||
defaultRoute := &Route{
|
||||
Receiver: defaultReceiverName,
|
||||
Routes: make([]*Route, 0),
|
||||
Receiver: defaultReceiverName,
|
||||
Routes: make([]*Route, 0),
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, // To keep parity with pre-migration notifications.
|
||||
}
|
||||
|
||||
return defaultReceiver, defaultRoute, nil
|
||||
@@ -438,10 +441,11 @@ type PostableApiAlertingConfig struct {
|
||||
}
|
||||
|
||||
type Route struct {
|
||||
Receiver string `yaml:"receiver,omitempty" json:"receiver,omitempty"`
|
||||
Matchers Matchers `yaml:"matchers,omitempty" json:"matchers,omitempty"`
|
||||
Routes []*Route `yaml:"routes,omitempty" json:"routes,omitempty"`
|
||||
Continue bool `yaml:"continue,omitempty" json:"continue,omitempty"`
|
||||
Receiver string `yaml:"receiver,omitempty" json:"receiver,omitempty"`
|
||||
Matchers Matchers `yaml:"matchers,omitempty" json:"matchers,omitempty"`
|
||||
Routes []*Route `yaml:"routes,omitempty" json:"routes,omitempty"`
|
||||
Continue bool `yaml:"continue,omitempty" json:"continue,omitempty"`
|
||||
GroupByStr []string `yaml:"group_by,omitempty" json:"group_by,omitempty"`
|
||||
}
|
||||
|
||||
type Matchers labels.Matchers
|
||||
|
||||
@@ -3,9 +3,11 @@ package ualert
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
ngModels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
)
|
||||
|
||||
func TestFilterReceiversForAlert(t *testing.T) {
|
||||
@@ -144,10 +146,11 @@ func TestCreateRoute(t *testing.T) {
|
||||
"recv1": struct{}{},
|
||||
},
|
||||
expected: &Route{
|
||||
Receiver: "recv1",
|
||||
Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}},
|
||||
Routes: nil,
|
||||
Continue: false,
|
||||
Receiver: "recv1",
|
||||
Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}},
|
||||
Routes: nil,
|
||||
Continue: false,
|
||||
GroupByStr: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -162,19 +165,22 @@ func TestCreateRoute(t *testing.T) {
|
||||
Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}},
|
||||
Routes: []*Route{
|
||||
{
|
||||
Receiver: "recv1",
|
||||
Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}},
|
||||
Routes: nil,
|
||||
Continue: true,
|
||||
Receiver: "recv1",
|
||||
Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}},
|
||||
Routes: nil,
|
||||
Continue: true,
|
||||
GroupByStr: nil,
|
||||
},
|
||||
{
|
||||
Receiver: "recv2",
|
||||
Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}},
|
||||
Routes: nil,
|
||||
Continue: true,
|
||||
Receiver: "recv2",
|
||||
Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}},
|
||||
Routes: nil,
|
||||
Continue: true,
|
||||
GroupByStr: nil,
|
||||
},
|
||||
},
|
||||
Continue: false,
|
||||
Continue: false,
|
||||
GroupByStr: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -294,8 +300,9 @@ func TestCreateDefaultRouteAndReceiver(t *testing.T) {
|
||||
GrafanaManagedReceivers: []*PostableGrafanaReceiver{{Name: "name1"}, {Name: "name2"}},
|
||||
},
|
||||
expRoute: &Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Routes: make([]*Route, 0),
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Routes: make([]*Route, 0),
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -306,8 +313,9 @@ func TestCreateDefaultRouteAndReceiver(t *testing.T) {
|
||||
GrafanaManagedReceivers: []*PostableGrafanaReceiver{},
|
||||
},
|
||||
expRoute: &Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Routes: make([]*Route, 0),
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Routes: make([]*Route, 0),
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -315,8 +323,9 @@ func TestCreateDefaultRouteAndReceiver(t *testing.T) {
|
||||
defaultChannels: []*notificationChannel{createNotChannel(t, "uid1", int64(1), "name1")},
|
||||
expRecv: nil,
|
||||
expRoute: &Route{
|
||||
Receiver: "name1",
|
||||
Routes: make([]*Route, 0),
|
||||
Receiver: "name1",
|
||||
Routes: make([]*Route, 0),
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/prometheus/alertmanager/pkg/labels"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
"xorm.io/xorm"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
ngModels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrations/ualert"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
@@ -156,7 +158,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Receiver: "autogen-contact-point-default",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
Routes: []*ualert.Route{
|
||||
{Receiver: "notifier1", Matchers: createAlertNameMatchers("alert1")}, // These Matchers are temporary and will be replaced below with generated rule_uid.
|
||||
{Matchers: createAlertNameMatchers("alert2"), Routes: []*ualert.Route{
|
||||
@@ -177,7 +180,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(2): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "notifier6",
|
||||
Receiver: "notifier6",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
Routes: []*ualert.Route{
|
||||
{Matchers: createAlertNameMatchers("alert4"), Routes: []*ualert.Route{
|
||||
{Receiver: "notifier4", Matchers: createAlertNameMatchers("alert4"), Continue: true},
|
||||
@@ -209,7 +213,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Receiver: "autogen-contact-point-default",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
Receivers: []*ualert.PostableApiReceiver{
|
||||
{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}},
|
||||
@@ -229,7 +234,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "notifier1",
|
||||
Receiver: "notifier1",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
Receivers: []*ualert.PostableApiReceiver{
|
||||
{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}},
|
||||
@@ -249,7 +255,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Receiver: "autogen-contact-point-default",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
Receivers: []*ualert.PostableApiReceiver{
|
||||
{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}},
|
||||
@@ -272,7 +279,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Receiver: "autogen-contact-point-default",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
Receivers: []*ualert.PostableApiReceiver{
|
||||
{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}},
|
||||
@@ -297,7 +305,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Receiver: "autogen-contact-point-default",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
Receivers: []*ualert.PostableApiReceiver{
|
||||
{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}},
|
||||
@@ -322,7 +331,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Receiver: "autogen-contact-point-default",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
Routes: []*ualert.Route{
|
||||
{Receiver: "notifier1", Matchers: createAlertNameMatchers("alert1")},
|
||||
{Matchers: createAlertNameMatchers("alert2"), Routes: []*ualert.Route{
|
||||
@@ -350,7 +360,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Receiver: "autogen-contact-point-default",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
Receivers: []*ualert.PostableApiReceiver{
|
||||
{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}},
|
||||
@@ -372,7 +383,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Receiver: "autogen-contact-point-default",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
},
|
||||
Receivers: []*ualert.PostableApiReceiver{
|
||||
{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}},
|
||||
@@ -395,7 +407,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
int64(1): {
|
||||
AlertmanagerConfig: ualert.PostableApiAlertingConfig{
|
||||
Route: &ualert.Route{
|
||||
Receiver: "autogen-contact-point-default",
|
||||
Receiver: "autogen-contact-point-default",
|
||||
GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel},
|
||||
Routes: []*ualert.Route{
|
||||
{Receiver: "notifier1", Matchers: createAlertNameMatchers("alert1")},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user