Alerting: Fix Alertmanager configuration updates (#99610)

* Alerting: Fix Alertmanager configuration updates

Alertmanager configuration updates would behave inconsistently when performing no-op updates with `mysql` as the store.

In particular this bug manifested as a failure to reload the provisioned alertmanager configuration components with no changes to the configuration itself. This would result in a 500 error with mysql store only.

The core issue is that we were relying on the number of rows affected by the update query to determine if the configuration was found in the db or not.
While this behavior works for certain sql dialects, mysql does not return the number of rows matched by the update query but rather the number of rows actually updated.

Also discovered and fixed the mismatched `xorm` tag for the `CreatedAt` field to match the actual column name in the db.

References: https://dev.mysql.com/doc/refman/8.4/en/update.html
This commit is contained in:
Moustafa Baiou
2025-01-29 23:00:45 +02:00
committed by GitHub
parent 83d4f6e868
commit b820fd6bef
4 changed files with 57 additions and 2 deletions
@@ -903,6 +903,9 @@ func TestIntegrationExportFileProvision(t *testing.T) {
require.Len(t, export.MuteTimings, 1)
require.YAMLEq(t, expectedYaml, exportRaw)
})
t.Run("reloading provisioning should not fail", func(t *testing.T) {
apiClient.ReloadAlertingFileProvisioning(t)
})
})
}
@@ -1004,6 +1007,17 @@ func TestIntegrationExportFileProvisionContactPoints(t *testing.T) {
var export definitions.AlertingFileExport
require.NoError(t, yaml.Unmarshal([]byte(exportRaw), &export))
// verify the file exported matches the file provisioned thing
require.Len(t, export.ContactPoints, 1)
require.YAMLEq(t, string(expectedYaml), exportRaw)
})
t.Run("reloading provisioning should not change things", func(t *testing.T) {
apiClient.ReloadAlertingFileProvisioning(t)
exportRaw := apiClient.ExportReceiver(t, "cp_1_$escaped", "yaml", true)
var export definitions.AlertingFileExport
require.NoError(t, yaml.Unmarshal([]byte(exportRaw), &export))
// verify the file exported matches the file provisioned thing
require.Len(t, export.ContactPoints, 1)
require.YAMLEq(t, string(expectedYaml), exportRaw)