Alerting: fix the migrated silence file content (#39557)

This commit is contained in:
Sofia Papagiannaki 2021-09-23 12:17:38 +03:00 committed by GitHub
parent 4aed940738
commit 81e82ebbbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -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
}

View File

@ -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.
}