Skip to content

Commit

Permalink
Modify routing labels to start with the same prefix __legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobsonMT committed Nov 27, 2023
1 parent 437ec12 commit 8e41dd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pkg/services/ngalert/migration/channel.go
Expand Up @@ -141,9 +141,9 @@ func createRoute(channel *legacymodels.AlertNotification, receiverName string) (
//
// For example, if an alert needs to send to channel1 and channel2 it will have one label to route to the nested
// policy and two channel-specific labels to route to the correct contact points:
// - __use_legacy_channels__="true"
// - __contact_channel1__="true"
// - __contact_channel2__="true"
// - __legacy_use_channels__="true"
// - __legacy_c_channel1__="true"
// - __legacy_c_channel2__="true"
//
// If an alert needs to send to channel1 and the default channel, it will have one label to route to the nested
// policy and one channel-specific label to route to channel1, and a catch-all policy will ensure it also routes to
Expand Down Expand Up @@ -175,7 +175,7 @@ func createRoute(channel *legacymodels.AlertNotification, receiverName string) (

// contactLabel creates a label matcher key used to route alerts to a contact point.
func contactLabel(name string) string {
return fmt.Sprintf(ngmodels.MigratedContactLabelTemplate, name)
return ngmodels.MigratedContactLabelPrefix + name + "__"
}

var secureKeysToMigrate = map[string][]string{
Expand Down
8 changes: 5 additions & 3 deletions pkg/services/ngalert/models/alert_rule.go
Expand Up @@ -106,10 +106,12 @@ const (
// StateReasonAnnotation is the name of the annotation that explains the difference between evaluation state and alert state (i.e. changing state when NoData or Error).
StateReasonAnnotation = GrafanaReservedLabelPrefix + "state_reason"

// MigratedLabelPrefix is a label prefix for all labels created during legacy migration.
MigratedLabelPrefix = "__legacy_"
// MigratedUseLegacyChannelsLabel is created during legacy migration to route to separate nested policies for migrated channels.
MigratedUseLegacyChannelsLabel = "__use_legacy_channels__"
// MigratedContactLabelTemplate is created during legacy migration to route a migrated alert rule to a specific migrated channel.
MigratedContactLabelTemplate = "__contacts_%s__"
MigratedUseLegacyChannelsLabel = MigratedLabelPrefix + "use_channels__"
// MigratedContactLabelPrefix is created during legacy migration to route a migrated alert rule to a specific migrated channel.
MigratedContactLabelPrefix = MigratedLabelPrefix + "c_"
// MigratedAlertIdAnnotation is created during legacy migration to store the ID of the migrated legacy alert rule.
MigratedAlertIdAnnotation = "__alertId__"
// MigratedMessageAnnotation is created during legacy migration to store the migrated alert message.
Expand Down

0 comments on commit 8e41dd9

Please sign in to comment.