AlertingMigration: Separate info into multiple annos (#33641)

This commit is contained in:
Kyle Brandt 2021-05-03 11:42:31 -04:00 committed by GitHub
parent 6b0417207d
commit 57d46ea991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -72,18 +72,25 @@ func (a *alertRule) makeVersion() *alertRuleVersion {
}
}
func getMigrationInfo(da dashAlert) string {
func addMigrationInfo(da *dashAlert) map[string]string {
annotations := da.ParsedSettings.AlertRuleTags
if annotations == nil {
annotations = make(map[string]string, 3)
}
annotations["__dashboardUid__"] = da.DashboardUID
annotations["__panelId__"] = fmt.Sprintf("%v", da.PanelId)
annotations["__alertId__"] = fmt.Sprintf("%v", da.Id)
return annotations
}
func getMigrationString(da dashAlert) string {
return fmt.Sprintf(`{"dashboardUid": "%v", "panelId": %v, "alertId": %v}`, da.DashboardUID, da.PanelId, da.Id)
}
func (m *migration) makeAlertRule(cond condition, da dashAlert, folderUID string) (*alertRule, error) {
migAnnotation := getMigrationInfo(da)
annotations := da.ParsedSettings.AlertRuleTags
if annotations == nil {
annotations = make(map[string]string, 1)
}
annotations["__migration__info__"] = migAnnotation
annotations := addMigrationInfo(&da)
ar := &alertRule{
OrgId: da.OrgId,

View File

@ -113,7 +113,7 @@ func (m *migration) Exec(sess *xorm.Session, mg *migrator.Migrator) error {
switch {
case dash.HasAcl:
// create folder and assign the permissions of the dashboard (included default and inherited)
ptr, err := m.createFolder(dash.OrgId, fmt.Sprintf(DASHBOARD_FOLDER, getMigrationInfo(da)))
ptr, err := m.createFolder(dash.OrgId, fmt.Sprintf(DASHBOARD_FOLDER, getMigrationString(da)))
if err != nil {
return MigrationError{
Err: fmt.Errorf("failed to create folder: %w", err),