mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix alert migration RefID generation (#35667)
* Alerting: Fix alert migration RefID generation if the alert has more than 26 conditions * Remove TODO comment * Make similar change under pkg/expr
This commit is contained in:
parent
7f882eea05
commit
c997f646cc
@ -13,6 +13,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/eval"
|
||||
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
// DashboardAlertConditions turns dashboard alerting conditions into server side expression queries and a
|
||||
@ -279,10 +280,6 @@ const alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
// getNewRefID finds first capital letter in the alphabet not in use
|
||||
// to use for a new RefID. It errors if it runs out of letters.
|
||||
//
|
||||
// TODO: Research if there is a limit. If so enforce is by
|
||||
// number of queries not letters. If no limit generate more types
|
||||
// of refIDs.
|
||||
func getNewRefID(refIDs map[string][]int) (string, error) {
|
||||
for _, r := range alpha {
|
||||
sR := string(r)
|
||||
@ -291,7 +288,14 @@ func getNewRefID(refIDs map[string][]int) (string, error) {
|
||||
}
|
||||
return sR, nil
|
||||
}
|
||||
return "", fmt.Errorf("ran out of letters when creating expression")
|
||||
for i := 0; i < 20; i++ {
|
||||
sR := util.GenerateShortUID()
|
||||
if _, ok := refIDs[sR]; ok {
|
||||
continue
|
||||
}
|
||||
return sR, nil
|
||||
}
|
||||
return "", fmt.Errorf("failed to generate unique RefID")
|
||||
}
|
||||
|
||||
// getRelativeDuration turns the alerting durations for dashboard conditions
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func transConditions(set dashAlertSettings, orgID int64, dsUIDMap dsUIDLookup) (*condition, error) {
|
||||
@ -211,10 +213,6 @@ const alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
// getNewRefID finds first capital letter in the alphabet not in use
|
||||
// to use for a new RefID. It errors if it runs out of letters.
|
||||
//
|
||||
// TODO: Research if there is a limit. If so enforce is by
|
||||
// number of queries not letters. If no limit generate more types
|
||||
// of refIDs.
|
||||
func getNewRefID(refIDs map[string][]int) (string, error) {
|
||||
for _, r := range alpha {
|
||||
sR := string(r)
|
||||
@ -223,7 +221,14 @@ func getNewRefID(refIDs map[string][]int) (string, error) {
|
||||
}
|
||||
return sR, nil
|
||||
}
|
||||
return "", fmt.Errorf("ran out of letters when creating expression")
|
||||
for i := 0; i < 20; i++ {
|
||||
sR := util.GenerateShortUID()
|
||||
if _, ok := refIDs[sR]; ok {
|
||||
continue
|
||||
}
|
||||
return sR, nil
|
||||
}
|
||||
return "", fmt.Errorf("failed to generate unique RefID")
|
||||
}
|
||||
|
||||
// getRelativeDuration turns the alerting durations for dashboard conditions
|
||||
|
Loading…
Reference in New Issue
Block a user