Alerting: add collision safe update function for alertmanager configurations (#46692)
* Alerting: add collision safe update function for alertmanager configurations * fix typo * use bootstrap func for tests * move hash calculation to store * remove icons lol * remove removed field
This commit is contained in:
@@ -2,6 +2,9 @@ package notifier
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -67,6 +70,20 @@ func (f *FakeConfigStore) SaveAlertmanagerConfigurationWithCallback(_ context.Co
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *FakeConfigStore) UpdateAlertManagerConfiguration(cmd *models.SaveAlertmanagerConfigurationCmd) error {
|
||||
if config, exists := f.configs[cmd.OrgID]; exists && config.ConfigurationHash == cmd.FetchedConfigurationHash {
|
||||
f.configs[cmd.OrgID] = &models.AlertConfiguration{
|
||||
AlertmanagerConfiguration: cmd.AlertmanagerConfiguration,
|
||||
OrgID: cmd.OrgID,
|
||||
ConfigurationHash: fmt.Sprintf("%x", md5.Sum([]byte(cmd.AlertmanagerConfiguration))),
|
||||
ConfigurationVersion: "v1",
|
||||
Default: cmd.Default,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return errors.New("config not found or hash not valid")
|
||||
}
|
||||
|
||||
type FakeOrgStore struct {
|
||||
orgs []int64
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user