mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
Alerting: fix the migrated silence file content (#39557)
This commit is contained in:
parent
4aed940738
commit
81e82ebbbd
@ -47,13 +47,22 @@ func (m *migration) addSilence(da dashAlert, rule *alertRule) error {
|
||||
ExpiresAt: time.Now().Add(365 * 20 * time.Hour), // 1 year.
|
||||
}
|
||||
|
||||
m.silences = append(m.silences, s)
|
||||
_, ok := m.silences[da.OrgId]
|
||||
if !ok {
|
||||
m.silences[da.OrgId] = make([]*pb.MeshSilence, 0)
|
||||
}
|
||||
m.silences[da.OrgId] = append(m.silences[da.OrgId], s)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *migration) writeSilencesFile(orgID int64) error {
|
||||
var buf bytes.Buffer
|
||||
for _, e := range m.silences {
|
||||
orgSilences, ok := m.silences[orgID]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, e := range orgSilences {
|
||||
if _, err := pbutil.WriteDelimited(&buf, e); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ func AddDashAlertMigration(mg *migrator.Migrator) {
|
||||
seenChannelUIDs: make(map[string]struct{}),
|
||||
migratedChannelsPerOrg: make(map[int64]map[*notificationChannel]struct{}),
|
||||
portedChannelGroupsPerOrg: make(map[int64]map[string]string),
|
||||
silences: make(map[int64][]*pb.MeshSilence),
|
||||
})
|
||||
case !ngEnabled && migrationRun:
|
||||
// Remove the migration entry that creates unified alerting data. This is so when the feature
|
||||
@ -101,6 +102,7 @@ func RerunDashAlertMigration(mg *migrator.Migrator) {
|
||||
seenChannelUIDs: make(map[string]struct{}),
|
||||
migratedChannelsPerOrg: make(map[int64]map[*notificationChannel]struct{}),
|
||||
portedChannelGroupsPerOrg: make(map[int64]map[string]string),
|
||||
silences: make(map[int64][]*pb.MeshSilence),
|
||||
})
|
||||
|
||||
case !ngEnabled && migrationRun:
|
||||
@ -150,7 +152,7 @@ type migration struct {
|
||||
|
||||
seenChannelUIDs map[string]struct{}
|
||||
migratedChannelsPerOrg map[int64]map[*notificationChannel]struct{}
|
||||
silences []*pb.MeshSilence
|
||||
silences map[int64][]*pb.MeshSilence
|
||||
portedChannelGroupsPerOrg map[int64]map[string]string // Org -> Channel group key -> receiver name.
|
||||
lastReceiverID int // For the auto generated receivers.
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user