Store 'alertmanager_configuration' as JSON string instead of raw bytes (#42443) (#42602)

(cherry picked from commit 5183cc4dc4)

Co-authored-by: Joan López de la Franca Beltran <5459617+joanlopez@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2021-12-09 11:44:16 +01:00
committed by GitHub
co-authored by Joan López de la Franca Beltran
parent a1d4846f7f
commit e8f1d6db44
@@ -123,7 +123,7 @@ type alertingSecret struct{}
func (s alertingSecret) reencrypt(secretsSrv *manager.SecretsService, sess *xorm.Session) error {
var results []struct {
Id int
AlertmanagerConfiguration []byte
AlertmanagerConfiguration string
}
selectSQL := "SELECT id, alertmanager_configuration FROM alert_configuration"
@@ -133,7 +133,7 @@ func (s alertingSecret) reencrypt(secretsSrv *manager.SecretsService, sess *xorm
for _, result := range results {
result := result
postableUserConfig, err := notifier.Load(result.AlertmanagerConfiguration)
postableUserConfig, err := notifier.Load([]byte(result.AlertmanagerConfiguration))
if err != nil {
return err
}
@@ -161,11 +161,12 @@ func (s alertingSecret) reencrypt(secretsSrv *manager.SecretsService, sess *xorm
}
}
result.AlertmanagerConfiguration, err = json.Marshal(postableUserConfig)
marshalled, err := json.Marshal(postableUserConfig)
if err != nil {
return err
}
result.AlertmanagerConfiguration = string(marshalled)
if _, err := sess.Table("alert_configuration").Where("id = ?", result.Id).Update(&result); err != nil {
return err
}