mirror of https://github.com/grafana/grafana.git
				
				
				
			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:
		
							parent
							
								
									32c2b62dc7
								
							
						
					
					
						commit
						434e94ef2b
					
				|  | @ -223,7 +223,7 @@ func TestNotificationPolicyService(t *testing.T) { | ||||||
| 		require.NoError(t, err) | 		require.NoError(t, err) | ||||||
| 		require.Equal(t, "grafana-default-email", tree.Receiver) | 		require.Equal(t, "grafana-default-email", tree.Receiver) | ||||||
| 		require.Nil(t, tree.Routes) | 		require.Nil(t, tree.Routes) | ||||||
| 		require.Nil(t, tree.GroupBy) | 		require.Equal(t, []model.LabelName{models.FolderTitleLabel, model.AlertNameLabel}, tree.GroupBy) | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,8 +7,10 @@ import ( | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 
 | 
 | ||||||
| 	"github.com/prometheus/alertmanager/pkg/labels" | 	"github.com/prometheus/alertmanager/pkg/labels" | ||||||
|  | 	"github.com/prometheus/common/model" | ||||||
| 
 | 
 | ||||||
| 	"github.com/grafana/grafana/pkg/components/simplejson" | 	"github.com/grafana/grafana/pkg/components/simplejson" | ||||||
|  | 	ngModels "github.com/grafana/grafana/pkg/services/ngalert/models" | ||||||
| 	"github.com/grafana/grafana/pkg/util" | 	"github.com/grafana/grafana/pkg/util" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -229,8 +231,9 @@ func (m *migration) createDefaultRouteAndReceiver(defaultChannels []*notificatio | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	defaultRoute := &Route{ | 	defaultRoute := &Route{ | ||||||
| 		Receiver: defaultReceiverName, | 		Receiver:   defaultReceiverName, | ||||||
| 		Routes:   make([]*Route, 0), | 		Routes:     make([]*Route, 0), | ||||||
|  | 		GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, // To keep parity with pre-migration notifications.
 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return defaultReceiver, defaultRoute, nil | 	return defaultReceiver, defaultRoute, nil | ||||||
|  | @ -438,10 +441,11 @@ type PostableApiAlertingConfig struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Route struct { | type Route struct { | ||||||
| 	Receiver string   `yaml:"receiver,omitempty" json:"receiver,omitempty"` | 	Receiver   string   `yaml:"receiver,omitempty" json:"receiver,omitempty"` | ||||||
| 	Matchers Matchers `yaml:"matchers,omitempty" json:"matchers,omitempty"` | 	Matchers   Matchers `yaml:"matchers,omitempty" json:"matchers,omitempty"` | ||||||
| 	Routes   []*Route `yaml:"routes,omitempty" json:"routes,omitempty"` | 	Routes     []*Route `yaml:"routes,omitempty" json:"routes,omitempty"` | ||||||
| 	Continue bool     `yaml:"continue,omitempty" json:"continue,omitempty"` | 	Continue   bool     `yaml:"continue,omitempty" json:"continue,omitempty"` | ||||||
|  | 	GroupByStr []string `yaml:"group_by,omitempty" json:"group_by,omitempty"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Matchers labels.Matchers | type Matchers labels.Matchers | ||||||
|  |  | ||||||
|  | @ -3,9 +3,11 @@ package ualert | ||||||
| import ( | import ( | ||||||
| 	"testing" | 	"testing" | ||||||
| 
 | 
 | ||||||
|  | 	"github.com/prometheus/common/model" | ||||||
| 	"github.com/stretchr/testify/require" | 	"github.com/stretchr/testify/require" | ||||||
| 
 | 
 | ||||||
| 	"github.com/grafana/grafana/pkg/components/simplejson" | 	"github.com/grafana/grafana/pkg/components/simplejson" | ||||||
|  | 	ngModels "github.com/grafana/grafana/pkg/services/ngalert/models" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func TestFilterReceiversForAlert(t *testing.T) { | func TestFilterReceiversForAlert(t *testing.T) { | ||||||
|  | @ -144,10 +146,11 @@ func TestCreateRoute(t *testing.T) { | ||||||
| 				"recv1": struct{}{}, | 				"recv1": struct{}{}, | ||||||
| 			}, | 			}, | ||||||
| 			expected: &Route{ | 			expected: &Route{ | ||||||
| 				Receiver: "recv1", | 				Receiver:   "recv1", | ||||||
| 				Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}}, | 				Matchers:   Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}}, | ||||||
| 				Routes:   nil, | 				Routes:     nil, | ||||||
| 				Continue: false, | 				Continue:   false, | ||||||
|  | 				GroupByStr: nil, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
|  | @ -162,19 +165,22 @@ func TestCreateRoute(t *testing.T) { | ||||||
| 				Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}}, | 				Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}}, | ||||||
| 				Routes: []*Route{ | 				Routes: []*Route{ | ||||||
| 					{ | 					{ | ||||||
| 						Receiver: "recv1", | 						Receiver:   "recv1", | ||||||
| 						Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}}, | 						Matchers:   Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}}, | ||||||
| 						Routes:   nil, | 						Routes:     nil, | ||||||
| 						Continue: true, | 						Continue:   true, | ||||||
|  | 						GroupByStr: nil, | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
| 						Receiver: "recv2", | 						Receiver:   "recv2", | ||||||
| 						Matchers: Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}}, | 						Matchers:   Matchers{{Type: 0, Name: "rule_uid", Value: "r_uid1"}}, | ||||||
| 						Routes:   nil, | 						Routes:     nil, | ||||||
| 						Continue: true, | 						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"}}, | 				GrafanaManagedReceivers: []*PostableGrafanaReceiver{{Name: "name1"}, {Name: "name2"}}, | ||||||
| 			}, | 			}, | ||||||
| 			expRoute: &Route{ | 			expRoute: &Route{ | ||||||
| 				Receiver: "autogen-contact-point-default", | 				Receiver:   "autogen-contact-point-default", | ||||||
| 				Routes:   make([]*Route, 0), | 				Routes:     make([]*Route, 0), | ||||||
|  | 				GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
|  | @ -306,8 +313,9 @@ func TestCreateDefaultRouteAndReceiver(t *testing.T) { | ||||||
| 				GrafanaManagedReceivers: []*PostableGrafanaReceiver{}, | 				GrafanaManagedReceivers: []*PostableGrafanaReceiver{}, | ||||||
| 			}, | 			}, | ||||||
| 			expRoute: &Route{ | 			expRoute: &Route{ | ||||||
| 				Receiver: "autogen-contact-point-default", | 				Receiver:   "autogen-contact-point-default", | ||||||
| 				Routes:   make([]*Route, 0), | 				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")}, | 			defaultChannels: []*notificationChannel{createNotChannel(t, "uid1", int64(1), "name1")}, | ||||||
| 			expRecv:         nil, | 			expRecv:         nil, | ||||||
| 			expRoute: &Route{ | 			expRoute: &Route{ | ||||||
| 				Receiver: "name1", | 				Receiver:   "name1", | ||||||
| 				Routes:   make([]*Route, 0), | 				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" | ||||||
| 	"github.com/google/go-cmp/cmp/cmpopts" | 	"github.com/google/go-cmp/cmp/cmpopts" | ||||||
| 	"github.com/prometheus/alertmanager/pkg/labels" | 	"github.com/prometheus/alertmanager/pkg/labels" | ||||||
|  | 	"github.com/prometheus/common/model" | ||||||
| 	"github.com/stretchr/testify/require" | 	"github.com/stretchr/testify/require" | ||||||
| 	"xorm.io/xorm" | 	"xorm.io/xorm" | ||||||
| 
 | 
 | ||||||
| 	"github.com/grafana/grafana/pkg/components/simplejson" | 	"github.com/grafana/grafana/pkg/components/simplejson" | ||||||
| 	"github.com/grafana/grafana/pkg/models" | 	"github.com/grafana/grafana/pkg/models" | ||||||
| 	"github.com/grafana/grafana/pkg/services/datasources" | 	"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" | ||||||
| 	"github.com/grafana/grafana/pkg/services/sqlstore/migrations/ualert" | 	"github.com/grafana/grafana/pkg/services/sqlstore/migrations/ualert" | ||||||
| 	"github.com/grafana/grafana/pkg/services/sqlstore/migrator" | 	"github.com/grafana/grafana/pkg/services/sqlstore/migrator" | ||||||
|  | @ -156,7 +158,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "autogen-contact-point-default", | 							Receiver:   "autogen-contact-point-default", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 							Routes: []*ualert.Route{ | 							Routes: []*ualert.Route{ | ||||||
| 								{Receiver: "notifier1", Matchers: createAlertNameMatchers("alert1")}, // These Matchers are temporary and will be replaced below with generated rule_uid.
 | 								{Receiver: "notifier1", Matchers: createAlertNameMatchers("alert1")}, // These Matchers are temporary and will be replaced below with generated rule_uid.
 | ||||||
| 								{Matchers: createAlertNameMatchers("alert2"), Routes: []*ualert.Route{ | 								{Matchers: createAlertNameMatchers("alert2"), Routes: []*ualert.Route{ | ||||||
|  | @ -177,7 +180,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(2): { | 				int64(2): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "notifier6", | 							Receiver:   "notifier6", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 							Routes: []*ualert.Route{ | 							Routes: []*ualert.Route{ | ||||||
| 								{Matchers: createAlertNameMatchers("alert4"), Routes: []*ualert.Route{ | 								{Matchers: createAlertNameMatchers("alert4"), Routes: []*ualert.Route{ | ||||||
| 									{Receiver: "notifier4", Matchers: createAlertNameMatchers("alert4"), Continue: true}, | 									{Receiver: "notifier4", Matchers: createAlertNameMatchers("alert4"), Continue: true}, | ||||||
|  | @ -209,7 +213,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "autogen-contact-point-default", | 							Receiver:   "autogen-contact-point-default", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 						}, | 						}, | ||||||
| 						Receivers: []*ualert.PostableApiReceiver{ | 						Receivers: []*ualert.PostableApiReceiver{ | ||||||
| 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | ||||||
|  | @ -229,7 +234,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "notifier1", | 							Receiver:   "notifier1", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 						}, | 						}, | ||||||
| 						Receivers: []*ualert.PostableApiReceiver{ | 						Receivers: []*ualert.PostableApiReceiver{ | ||||||
| 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | ||||||
|  | @ -249,7 +255,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "autogen-contact-point-default", | 							Receiver:   "autogen-contact-point-default", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 						}, | 						}, | ||||||
| 						Receivers: []*ualert.PostableApiReceiver{ | 						Receivers: []*ualert.PostableApiReceiver{ | ||||||
| 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | ||||||
|  | @ -272,7 +279,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "autogen-contact-point-default", | 							Receiver:   "autogen-contact-point-default", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 						}, | 						}, | ||||||
| 						Receivers: []*ualert.PostableApiReceiver{ | 						Receivers: []*ualert.PostableApiReceiver{ | ||||||
| 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | ||||||
|  | @ -297,7 +305,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "autogen-contact-point-default", | 							Receiver:   "autogen-contact-point-default", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 						}, | 						}, | ||||||
| 						Receivers: []*ualert.PostableApiReceiver{ | 						Receivers: []*ualert.PostableApiReceiver{ | ||||||
| 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | ||||||
|  | @ -322,7 +331,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "autogen-contact-point-default", | 							Receiver:   "autogen-contact-point-default", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 							Routes: []*ualert.Route{ | 							Routes: []*ualert.Route{ | ||||||
| 								{Receiver: "notifier1", Matchers: createAlertNameMatchers("alert1")}, | 								{Receiver: "notifier1", Matchers: createAlertNameMatchers("alert1")}, | ||||||
| 								{Matchers: createAlertNameMatchers("alert2"), Routes: []*ualert.Route{ | 								{Matchers: createAlertNameMatchers("alert2"), Routes: []*ualert.Route{ | ||||||
|  | @ -350,7 +360,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "autogen-contact-point-default", | 							Receiver:   "autogen-contact-point-default", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 						}, | 						}, | ||||||
| 						Receivers: []*ualert.PostableApiReceiver{ | 						Receivers: []*ualert.PostableApiReceiver{ | ||||||
| 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | ||||||
|  | @ -372,7 +383,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "autogen-contact-point-default", | 							Receiver:   "autogen-contact-point-default", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 						}, | 						}, | ||||||
| 						Receivers: []*ualert.PostableApiReceiver{ | 						Receivers: []*ualert.PostableApiReceiver{ | ||||||
| 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | 							{Name: "notifier1", GrafanaManagedReceivers: []*ualert.PostableGrafanaReceiver{{Name: "notifier1", Type: "email"}}}, | ||||||
|  | @ -395,7 +407,8 @@ func TestDashAlertMigration(t *testing.T) { | ||||||
| 				int64(1): { | 				int64(1): { | ||||||
| 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | 					AlertmanagerConfig: ualert.PostableApiAlertingConfig{ | ||||||
| 						Route: &ualert.Route{ | 						Route: &ualert.Route{ | ||||||
| 							Receiver: "autogen-contact-point-default", | 							Receiver:   "autogen-contact-point-default", | ||||||
|  | 							GroupByStr: []string{ngModels.FolderTitleLabel, model.AlertNameLabel}, | ||||||
| 							Routes: []*ualert.Route{ | 							Routes: []*ualert.Route{ | ||||||
| 								{Receiver: "notifier1", Matchers: createAlertNameMatchers("alert1")}, | 								{Receiver: "notifier1", Matchers: createAlertNameMatchers("alert1")}, | ||||||
| 							}, | 							}, | ||||||
|  |  | ||||||
|  | @ -26,7 +26,8 @@ const ( | ||||||
| 	alertmanagerDefaultConfiguration = `{ | 	alertmanagerDefaultConfiguration = `{ | ||||||
| 	"alertmanager_config": { | 	"alertmanager_config": { | ||||||
| 		"route": { | 		"route": { | ||||||
| 			"receiver": "grafana-default-email" | 			"receiver": "grafana-default-email", | ||||||
|  | 			"group_by": ["grafana_folder", "alertname"] | ||||||
| 		}, | 		}, | ||||||
| 		"receivers": [{ | 		"receivers": [{ | ||||||
| 			"name": "grafana-default-email", | 			"name": "grafana-default-email", | ||||||
|  |  | ||||||
|  | @ -1832,7 +1832,8 @@ func TestAlertmanagerStatus(t *testing.T) { | ||||||
| 	}, | 	}, | ||||||
| 	"config": { | 	"config": { | ||||||
| 		"route": { | 		"route": { | ||||||
| 			"receiver": "grafana-default-email" | 			"receiver": "grafana-default-email", | ||||||
|  | 			"group_by": ["grafana_folder", "alertname"] | ||||||
| 		}, | 		}, | ||||||
| 		"templates": null, | 		"templates": null, | ||||||
| 		"receivers": [{ | 		"receivers": [{ | ||||||
|  |  | ||||||
|  | @ -25,7 +25,8 @@ const defaultAlertmanagerConfigJSON = ` | ||||||
| 	"template_files": null, | 	"template_files": null, | ||||||
| 	"alertmanager_config": { | 	"alertmanager_config": { | ||||||
| 		"route": { | 		"route": { | ||||||
| 			"receiver": "grafana-default-email" | 			"receiver": "grafana-default-email", | ||||||
|  | 			"group_by": ["grafana_folder", "alertname"] | ||||||
| 		}, | 		}, | ||||||
| 		"templates": null, | 		"templates": null, | ||||||
| 		"receivers": [{ | 		"receivers": [{ | ||||||
|  |  | ||||||
|  | @ -21,6 +21,7 @@ import { AccessControlAction } from 'app/types'; | ||||||
| import AmRoutes from './AmRoutes'; | import AmRoutes from './AmRoutes'; | ||||||
| import { fetchAlertManagerConfig, fetchStatus, updateAlertManagerConfig } from './api/alertmanager'; | import { fetchAlertManagerConfig, fetchStatus, updateAlertManagerConfig } from './api/alertmanager'; | ||||||
| import { mockDataSource, MockDataSourceSrv, someCloudAlertManagerConfig, someCloudAlertManagerStatus } from './mocks'; | import { mockDataSource, MockDataSourceSrv, someCloudAlertManagerConfig, someCloudAlertManagerStatus } from './mocks'; | ||||||
|  | import { defaultGroupBy } from './utils/amroutes'; | ||||||
| import { getAllDataSources } from './utils/config'; | import { getAllDataSources } from './utils/config'; | ||||||
| import { ALERTMANAGER_NAME_QUERY_KEY } from './utils/constants'; | import { ALERTMANAGER_NAME_QUERY_KEY } from './utils/constants'; | ||||||
| import { DataSourceType, GRAFANA_RULES_SOURCE_NAME } from './utils/datasource'; | import { DataSourceType, GRAFANA_RULES_SOURCE_NAME } from './utils/datasource'; | ||||||
|  | @ -363,7 +364,7 @@ describe('AmRoutes', () => { | ||||||
|         receivers: [{ name: 'default' }], |         receivers: [{ name: 'default' }], | ||||||
|         route: { |         route: { | ||||||
|           continue: false, |           continue: false, | ||||||
|           group_by: ['severity', 'namespace'], |           group_by: defaultGroupBy.concat(['severity', 'namespace']), | ||||||
|           receiver: 'default', |           receiver: 'default', | ||||||
|           routes: [], |           routes: [], | ||||||
|           mute_time_intervals: [], |           mute_time_intervals: [], | ||||||
|  |  | ||||||
|  | @ -10,6 +10,7 @@ import { | ||||||
|   optionalPositiveInteger, |   optionalPositiveInteger, | ||||||
|   stringToSelectableValue, |   stringToSelectableValue, | ||||||
|   stringsToSelectableValues, |   stringsToSelectableValues, | ||||||
|  |   commonGroupByOptions, | ||||||
| } from '../../utils/amroutes'; | } from '../../utils/amroutes'; | ||||||
| import { makeAMLink } from '../../utils/misc'; | import { makeAMLink } from '../../utils/misc'; | ||||||
| import { timeOptions } from '../../utils/time'; | import { timeOptions } from '../../utils/time'; | ||||||
|  | @ -86,7 +87,7 @@ export const AmRootRouteForm: FC<AmRootRouteFormProps> = ({ | ||||||
|                     setValue('groupBy', [...field.value, opt]); |                     setValue('groupBy', [...field.value, opt]); | ||||||
|                   }} |                   }} | ||||||
|                   onChange={(value) => onChange(mapMultiSelectValueToStrings(value))} |                   onChange={(value) => onChange(mapMultiSelectValueToStrings(value))} | ||||||
|                   options={groupByOptions} |                   options={[...commonGroupByOptions, groupByOptions]} | ||||||
|                 /> |                 /> | ||||||
|               )} |               )} | ||||||
|               control={control} |               control={control} | ||||||
|  |  | ||||||
|  | @ -29,6 +29,7 @@ import { | ||||||
|   optionalPositiveInteger, |   optionalPositiveInteger, | ||||||
|   stringToSelectableValue, |   stringToSelectableValue, | ||||||
|   stringsToSelectableValues, |   stringsToSelectableValues, | ||||||
|  |   commonGroupByOptions, | ||||||
| } from '../../utils/amroutes'; | } from '../../utils/amroutes'; | ||||||
| import { timeOptions } from '../../utils/time'; | import { timeOptions } from '../../utils/time'; | ||||||
| 
 | 
 | ||||||
|  | @ -179,7 +180,7 @@ export const AmRoutesExpandedForm: FC<AmRoutesExpandedFormProps> = ({ onCancel, | ||||||
|                       setValue('groupBy', [...field.value, opt]); |                       setValue('groupBy', [...field.value, opt]); | ||||||
|                     }} |                     }} | ||||||
|                     onChange={(value) => onChange(mapMultiSelectValueToStrings(value))} |                     onChange={(value) => onChange(mapMultiSelectValueToStrings(value))} | ||||||
|                     options={groupByOptions} |                     options={[...commonGroupByOptions, groupByOptions]} | ||||||
|                   /> |                   /> | ||||||
|                 )} |                 )} | ||||||
|                 control={control} |                 control={control} | ||||||
|  |  | ||||||
|  | @ -59,10 +59,20 @@ export const emptyArrayFieldMatcher: MatcherFieldValue = { | ||||||
|   operator: MatcherOperator.equal, |   operator: MatcherOperator.equal, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | // Default route group_by labels for newly created routes.
 | ||||||
|  | export const defaultGroupBy = ['grafana_folder', 'alertname']; | ||||||
|  | 
 | ||||||
|  | // Common route group_by options for multiselect drop-down
 | ||||||
|  | export const commonGroupByOptions = [ | ||||||
|  |   { label: 'grafana_folder', value: 'grafana_folder' }, | ||||||
|  |   { label: 'alertname', value: 'alertname' }, | ||||||
|  |   { label: 'Disable (...)', value: '...' }, | ||||||
|  | ]; | ||||||
|  | 
 | ||||||
| export const emptyRoute: FormAmRoute = { | export const emptyRoute: FormAmRoute = { | ||||||
|   id: '', |   id: '', | ||||||
|   overrideGrouping: false, |   overrideGrouping: false, | ||||||
|   groupBy: [], |   groupBy: defaultGroupBy, | ||||||
|   object_matchers: [], |   object_matchers: [], | ||||||
|   routes: [], |   routes: [], | ||||||
|   continue: false, |   continue: false, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue