Chore: use any rather than interface{} (#74066)
This commit is contained in:
@@ -54,8 +54,8 @@ func (m *actionNameMigrator) migrateActionNames() error {
|
||||
"alert.rules:update": accesscontrol.ActionAlertingRuleUpdate,
|
||||
}
|
||||
|
||||
oldActionNames := make([]interface{}, 0, len(actionNameMapping))
|
||||
newActionNames := make([]interface{}, 0, len(actionNameMapping))
|
||||
oldActionNames := make([]any, 0, len(actionNameMapping))
|
||||
newActionNames := make([]any, 0, len(actionNameMapping))
|
||||
for oldName, newName := range actionNameMapping {
|
||||
oldActionNames = append(oldActionNames, oldName)
|
||||
newActionNames = append(newActionNames, newName)
|
||||
|
||||
@@ -87,7 +87,7 @@ func (m *adminOnlyMigrator) Exec(sess *xorm.Session, mg *migrator.Migrator) erro
|
||||
|
||||
// Remove managed permission for editors and viewers if there was any
|
||||
removeSQL := `DELETE FROM permission WHERE scope = ? AND role_id IN(?` + strings.Repeat(", ?", len(roleIDS)-1) + `) `
|
||||
params := []interface{}{removeSQL, scope}
|
||||
params := []any{removeSQL, scope}
|
||||
for _, id := range roleIDS {
|
||||
params = append(params, id)
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ func (m *managedFolderAlertActionsMigrator) SQL(dialect migrator.Dialect) string
|
||||
}
|
||||
|
||||
func (m *managedFolderAlertActionsMigrator) Exec(sess *xorm.Session, mg *migrator.Migrator) error {
|
||||
var ids []interface{}
|
||||
var ids []any
|
||||
if err := sess.SQL("SELECT id FROM role WHERE name LIKE 'managed:%'").Find(&ids); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -457,7 +457,7 @@ func (m *managedFolderAlertActionsRepeatMigrator) SQL(dialect migrator.Dialect)
|
||||
}
|
||||
|
||||
func (m *managedFolderAlertActionsRepeatMigrator) Exec(sess *xorm.Session, mg *migrator.Migrator) error {
|
||||
var ids []interface{}
|
||||
var ids []any
|
||||
if err := sess.SQL("SELECT id FROM role WHERE name LIKE 'managed:%'").Find(&ids); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func (m *DisabledMigrator) Exec(sess *xorm.Session, mg *migrator.Migrator) error
|
||||
return fmt.Errorf("failed to remove managed rbac roles: %w", err)
|
||||
}
|
||||
|
||||
params := []interface{}{"DELETE FROM migration_log WHERE migration_id IN (?, ?, ?, ?, ?, ?, ?, ?)"}
|
||||
params := []any{"DELETE FROM migration_log WHERE migration_id IN (?, ?, ?, ?, ?, ?, ?, ?)"}
|
||||
for _, m := range migrations {
|
||||
params = append(params, m)
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func (m *permissionMigrator) createRoles(roles []*accesscontrol.Role) ([]*access
|
||||
ts := time.Now()
|
||||
createdRoles := make([]*accesscontrol.Role, 0, len(roles))
|
||||
valueStrings := make([]string, len(roles))
|
||||
args := make([]interface{}, 0, len(roles)*5)
|
||||
args := make([]any, 0, len(roles)*5)
|
||||
|
||||
for i, r := range roles {
|
||||
uid, err := GenerateManagedRoleUID(r.OrgID, r.Name)
|
||||
@@ -160,7 +160,7 @@ func (m *permissionMigrator) createRolesMySQL(roles []*accesscontrol.Role) ([]*a
|
||||
createdRoles := make([]*accesscontrol.Role, 0, len(roles))
|
||||
|
||||
where := make([]string, len(roles))
|
||||
args := make([]interface{}, 0, len(roles)*2)
|
||||
args := make([]any, 0, len(roles)*2)
|
||||
|
||||
for i := range roles {
|
||||
uid, err := GenerateManagedRoleUID(roles[i].OrgID, roles[i].Name)
|
||||
|
||||
@@ -64,7 +64,7 @@ func (e externalAlertmanagerToDatasources) Exec(sess *xorm.Session, mg *migrator
|
||||
Updated: time.Unix(result.UpdatedAt, 0),
|
||||
UID: uid,
|
||||
Version: 1,
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
JsonData: simplejson.NewFromAny(map[string]any{
|
||||
"handleGrafanaManagedAlerts": true,
|
||||
"implementation": "prometheus",
|
||||
}),
|
||||
|
||||
@@ -309,7 +309,7 @@ func (d duration) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (d *duration) UnmarshalJSON(b []byte) error {
|
||||
var v interface{}
|
||||
var v any
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,22 +22,22 @@ func TestMigrateAlertRuleQueries(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "when a query has a sub query - it is extracted",
|
||||
input: simplejson.NewFromAny(map[string]interface{}{"targetFull": "thisisafullquery", "target": "ahalfquery"}),
|
||||
input: simplejson.NewFromAny(map[string]any{"targetFull": "thisisafullquery", "target": "ahalfquery"}),
|
||||
expected: `{"target":"thisisafullquery"}`,
|
||||
},
|
||||
{
|
||||
name: "when a query does not have a sub query - it no-ops",
|
||||
input: simplejson.NewFromAny(map[string]interface{}{"target": "ahalfquery"}),
|
||||
input: simplejson.NewFromAny(map[string]any{"target": "ahalfquery"}),
|
||||
expected: `{"target":"ahalfquery"}`,
|
||||
},
|
||||
{
|
||||
name: "when query was hidden, it removes the flag",
|
||||
input: simplejson.NewFromAny(map[string]interface{}{"hide": true}),
|
||||
input: simplejson.NewFromAny(map[string]any{"hide": true}),
|
||||
expected: `{}`,
|
||||
},
|
||||
{
|
||||
name: "when prometheus both type query, convert to range",
|
||||
input: simplejson.NewFromAny(map[string]interface{}{
|
||||
input: simplejson.NewFromAny(map[string]any{
|
||||
"datasource": map[string]string{
|
||||
"type": "prometheus",
|
||||
},
|
||||
@@ -48,7 +48,7 @@ func TestMigrateAlertRuleQueries(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "when prometheus instant type query, do nothing",
|
||||
input: simplejson.NewFromAny(map[string]interface{}{
|
||||
input: simplejson.NewFromAny(map[string]any{
|
||||
"datasource": map[string]string{
|
||||
"type": "prometheus",
|
||||
},
|
||||
@@ -58,7 +58,7 @@ func TestMigrateAlertRuleQueries(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "when non-prometheus with instant and range, do nothing",
|
||||
input: simplejson.NewFromAny(map[string]interface{}{
|
||||
input: simplejson.NewFromAny(map[string]any{
|
||||
"datasource": map[string]string{
|
||||
"type": "something",
|
||||
},
|
||||
|
||||
@@ -43,7 +43,7 @@ type channelsPerOrg map[int64][]*notificationChannel
|
||||
type defaultChannelsPerOrg map[int64][]*notificationChannel
|
||||
|
||||
// uidOrID for both uid and ID, primarily used for mapping legacy channel to migrated receiver.
|
||||
type uidOrID interface{}
|
||||
type uidOrID any
|
||||
|
||||
// channelReceiver is a convenience struct that contains a notificationChannel and its corresponding migrated PostableApiReceiver.
|
||||
type channelReceiver struct {
|
||||
@@ -130,7 +130,7 @@ func (m *migration) setupAlertmanagerConfigs(rulesPerOrg map[int64]map[*alertRul
|
||||
}
|
||||
|
||||
// contactListToString creates a sorted string representation of a given map (set) of receiver names. Each name will be comma-separated and double-quoted. Names should not contain double quotes.
|
||||
func contactListToString(m map[string]interface{}) string {
|
||||
func contactListToString(m map[string]any) string {
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
keys = append(keys, quote(k))
|
||||
@@ -338,14 +338,14 @@ func createRoute(cr channelReceiver) (*Route, error) {
|
||||
}
|
||||
|
||||
// Filter receivers to select those that were associated to the given rule as channels.
|
||||
func (m *migration) filterReceiversForAlert(name string, channelIDs []uidOrID, receivers map[uidOrID]*PostableApiReceiver, defaultReceivers map[string]struct{}) map[string]interface{} {
|
||||
func (m *migration) filterReceiversForAlert(name string, channelIDs []uidOrID, receivers map[uidOrID]*PostableApiReceiver, defaultReceivers map[string]struct{}) map[string]any {
|
||||
if len(channelIDs) == 0 {
|
||||
// If there are no channels associated, we use the default route.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Filter receiver names.
|
||||
filteredReceiverNames := make(map[string]interface{})
|
||||
filteredReceiverNames := make(map[string]any)
|
||||
for _, uidOrId := range channelIDs {
|
||||
recv, ok := receivers[uidOrId]
|
||||
if ok {
|
||||
@@ -355,7 +355,7 @@ func (m *migration) filterReceiversForAlert(name string, channelIDs []uidOrID, r
|
||||
}
|
||||
}
|
||||
|
||||
coveredByDefault := func(names map[string]interface{}) bool {
|
||||
coveredByDefault := func(names map[string]any) bool {
|
||||
// Check if all receivers are also default ones and if so, just use the default route.
|
||||
for n := range names {
|
||||
if _, ok := defaultReceivers[n]; !ok {
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestFilterReceiversForAlert(t *testing.T) {
|
||||
channelIds []uidOrID
|
||||
receivers map[uidOrID]*PostableApiReceiver
|
||||
defaultReceivers map[string]struct{}
|
||||
expected map[string]interface{}
|
||||
expected map[string]any
|
||||
}{
|
||||
{
|
||||
name: "when an alert has multiple channels, each should filter for the correct receiver",
|
||||
@@ -40,7 +40,7 @@ func TestFilterReceiversForAlert(t *testing.T) {
|
||||
},
|
||||
},
|
||||
defaultReceivers: map[string]struct{}{},
|
||||
expected: map[string]interface{}{
|
||||
expected: map[string]any{
|
||||
"recv1": struct{}{},
|
||||
"recv2": struct{}{},
|
||||
},
|
||||
@@ -65,7 +65,7 @@ func TestFilterReceiversForAlert(t *testing.T) {
|
||||
defaultReceivers: map[string]struct{}{
|
||||
"recv2": {},
|
||||
},
|
||||
expected: map[string]interface{}{
|
||||
expected: map[string]any{
|
||||
"recv1": struct{}{}, // From alert
|
||||
"recv2": struct{}{}, // From default
|
||||
},
|
||||
@@ -80,7 +80,7 @@ func TestFilterReceiversForAlert(t *testing.T) {
|
||||
},
|
||||
},
|
||||
defaultReceivers: map[string]struct{}{},
|
||||
expected: map[string]interface{}{
|
||||
expected: map[string]any{
|
||||
"recv1": struct{}{},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -110,7 +110,7 @@ func transConditions(set dashAlertSettings, orgID int64, dsUIDMap dsUIDLookup) (
|
||||
continue
|
||||
}
|
||||
|
||||
var queryObj map[string]interface{} // copy the model
|
||||
var queryObj map[string]any // copy the model
|
||||
err := json.Unmarshal(set.Conditions[condIdx].Query.Model, &queryObj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -308,7 +308,7 @@ type classicConditionJSON struct {
|
||||
} `json:"query"`
|
||||
|
||||
Reducer struct {
|
||||
// Params []interface{} `json:"params"` (Unused)
|
||||
// Params []any `json:"params"` (Unused)
|
||||
Type string `json:"type"`
|
||||
} `json:"reducer"`
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ type dashAlertSettings struct {
|
||||
NoDataState string `json:"noDataState"`
|
||||
ExecutionErrorState string `json:"executionErrorState"`
|
||||
Conditions []dashAlertCondition `json:"conditions"`
|
||||
AlertRuleTags interface{} `json:"alertRuleTags"`
|
||||
AlertRuleTags any `json:"alertRuleTags"`
|
||||
Notifications []dashAlertNot `json:"notifications"`
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ type dashAlertCondition struct {
|
||||
} `json:"query"`
|
||||
|
||||
Reducer struct {
|
||||
// Params []interface{} `json:"params"` (Unused)
|
||||
// Params []any `json:"params"` (Unused)
|
||||
Type string `json:"type"`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func (m *folderHelper) createFolder(orgID int64, title string) (*dashboard, erro
|
||||
OrgId: orgID,
|
||||
FolderId: 0,
|
||||
IsFolder: true,
|
||||
Dashboard: simplejson.NewFromAny(map[string]interface{}{
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"title": title,
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -682,7 +682,7 @@ func (u *upgradeNgAlerting) updateAlertConfigurations(sess *xorm.Session, migrat
|
||||
// Otherwise, it deletes those files.
|
||||
// pre-8.2 version put all configuration files into the root of alerting directory. Since 8.2 configuration files are put in organization specific directory
|
||||
func (u *upgradeNgAlerting) updateAlertmanagerFiles(orgId int64, migrator *migrator.Migrator) {
|
||||
knownFiles := map[string]interface{}{"__default__.tmpl": nil, "silences": nil, "notifications": nil}
|
||||
knownFiles := map[string]any{"__default__.tmpl": nil, "silences": nil, "notifications": nil}
|
||||
alertingDir := filepath.Join(migrator.Cfg.DataPath, "alerting")
|
||||
|
||||
// do not fail if something goes wrong because these files are not used anymore. the worst that can happen is that we leave some leftovers behind
|
||||
@@ -858,7 +858,7 @@ func (c updateRulesOrderInGroup) Exec(sess *xorm.Session, migrator *migrator.Mig
|
||||
}
|
||||
|
||||
updated := time.Now()
|
||||
versions := make([]interface{}, 0, len(toUpdate))
|
||||
versions := make([]any, 0, len(toUpdate))
|
||||
|
||||
for _, rule := range toUpdate {
|
||||
rule.Updated = updated
|
||||
|
||||
Reference in New Issue
Block a user