mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Refactor migration to return pairs of legacy and upgraded structs (#79719)
Some refactoring that will simplify next changes for dry-run PRs. This should be no-op as far as the created ngalert resources and database state, though it does change some logs. The key change here is to modify migrateOrg to return pairs of legacy struct + ngalert struct instead of actually persisting the alerts and alertmanager config. This will allow us to capture error information during dry-run migration. It also moves most persistence-related operations such as title deduplication and folder creation to the right before we persist. This will simplify eventual partial migrations (individual alerts, dashboards, channels, ...). Additionally it changes channel code to deal with PostableGrafanaReceiver instead of PostableApiReceiver (integration instead of contact point).
This commit is contained in:
@@ -26,12 +26,25 @@ func NewAlertmanager() *Alertmanager {
|
||||
|
||||
// AddRoute adds a route to the alertmanager config.
|
||||
func (am *Alertmanager) AddRoute(route *apiModels.Route) {
|
||||
if route == nil {
|
||||
return
|
||||
}
|
||||
am.legacyRoute.Routes = append(am.legacyRoute.Routes, route)
|
||||
}
|
||||
|
||||
// AddReceiver adds a receiver to the alertmanager config.
|
||||
func (am *Alertmanager) AddReceiver(recv *apiModels.PostableApiReceiver) {
|
||||
am.Config.AlertmanagerConfig.Receivers = append(am.Config.AlertmanagerConfig.Receivers, recv)
|
||||
func (am *Alertmanager) AddReceiver(recv *apiModels.PostableGrafanaReceiver) {
|
||||
if recv == nil {
|
||||
return
|
||||
}
|
||||
am.Config.AlertmanagerConfig.Receivers = append(am.Config.AlertmanagerConfig.Receivers, &apiModels.PostableApiReceiver{
|
||||
Receiver: config.Receiver{
|
||||
Name: recv.Name, // Channel name is unique within an Org.
|
||||
},
|
||||
PostableGrafanaReceivers: apiModels.PostableGrafanaReceivers{
|
||||
GrafanaManagedReceivers: []*apiModels.PostableGrafanaReceiver{recv},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// createBaseConfig creates an alertmanager config with the root-level route, default receiver, and nested route
|
||||
|
Reference in New Issue
Block a user