Alerting: declare constants for __dashboardUid__ and __panelId__ literals (#39976)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
@@ -79,8 +80,8 @@ func addMigrationInfo(da *dashAlert) (map[string]string, map[string]string) {
|
||||
}
|
||||
|
||||
annotations := make(map[string]string, 3)
|
||||
annotations["__dashboardUid__"] = da.DashboardUID
|
||||
annotations["__panelId__"] = fmt.Sprintf("%v", da.PanelId)
|
||||
annotations[ngmodels.DashboardUIDAnnotation] = da.DashboardUID
|
||||
annotations[ngmodels.PanelIDAnnotation] = fmt.Sprintf("%v", da.PanelId)
|
||||
annotations["__alertId__"] = fmt.Sprintf("%v", da.Id)
|
||||
|
||||
return lbls, annotations
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
|
||||
pb "github.com/prometheus/alertmanager/silence/silencepb"
|
||||
"xorm.io/xorm"
|
||||
|
||||
@@ -148,13 +150,13 @@ func (m *updateDashboardUIDPanelIDMigration) Exec(sess *xorm.Session, mg *migrat
|
||||
dashboardUID *string
|
||||
panelID *int64
|
||||
)
|
||||
if s, ok := next.Annotations["__dashboardUid__"]; ok {
|
||||
if s, ok := next.Annotations[ngmodels.DashboardUIDAnnotation]; ok {
|
||||
dashboardUID = &s
|
||||
}
|
||||
if s, ok := next.Annotations["__panelId__"]; ok {
|
||||
if s, ok := next.Annotations[ngmodels.PanelIDAnnotation]; ok {
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the __panelId__ annotation does not contain a valid Panel ID: %w", err)
|
||||
return fmt.Errorf("the %s annotation does not contain a valid Panel ID: %w", ngmodels.PanelIDAnnotation, err)
|
||||
}
|
||||
panelID = &i
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user