Alerting: declare constants for __dashboardUid__ and __panelId__ literals (#39976)

This commit is contained in:
Yuriy Tseretyan
2021-10-07 17:30:06 -04:00
committed by GitHub
parent c8651c46d0
commit 5836def6c2
6 changed files with 28 additions and 20 deletions
@@ -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
}