Chore: Remove result fields from ngalert (#65410)

* remove result fields from ngalert

* remove duplicate imports
This commit is contained in:
Serge Zaitsev
2023-03-28 10:34:35 +02:00
committed by GitHub
parent 42b58fbca6
commit 0beb768427
34 changed files with 307 additions and 317 deletions
+4 -3
View File
@@ -40,7 +40,8 @@ func NewCrypto(secrets secrets.Service, configs configurationStore, log log.Logg
func (c *alertmanagerCrypto) LoadSecureSettings(ctx context.Context, orgId int64, receivers []*definitions.PostableApiReceiver) error {
// Get the last known working configuration.
query := models.GetLatestAlertmanagerConfigurationQuery{OrgID: orgId}
if err := c.configs.GetLatestAlertmanagerConfiguration(ctx, &query); err != nil {
amConfig, err := c.configs.GetLatestAlertmanagerConfiguration(ctx, &query)
if err != nil {
// If we don't have a configuration there's nothing for us to know and we should just continue saving the new one.
if !errors.Is(err, store.ErrNoAlertmanagerConfiguration) {
return fmt.Errorf("failed to get latest configuration: %w", err)
@@ -48,8 +49,8 @@ func (c *alertmanagerCrypto) LoadSecureSettings(ctx context.Context, orgId int64
}
currentReceiverMap := make(map[string]*definitions.PostableGrafanaReceiver)
if query.Result != nil {
currentConfig, err := Load([]byte(query.Result.AlertmanagerConfiguration))
if amConfig != nil {
currentConfig, err := Load([]byte(amConfig.AlertmanagerConfiguration))
// If the current config is un-loadable, treat it as if it never existed. Providing a new, valid config should be able to "fix" this state.
if err != nil {
c.log.Warn("last known alertmanager configuration was invalid. Overwriting...")