Files
grafana/pkg/services/ngalert/models/alertmanager.go
Moustafa Baiou b820fd6bef 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
2025-01-29 23:00:45 +02:00

50 lines
1.7 KiB
Go

package models
const AlertConfigurationVersion = 1
// AlertConfiguration represents a single version of the Alerting Engine Configuration.
type AlertConfiguration struct {
ID int64 `xorm:"pk autoincr 'id'"`
AlertmanagerConfiguration string
ConfigurationHash string
ConfigurationVersion string
CreatedAt int64 `xorm:"created_at"`
Default bool
OrgID int64 `xorm:"org_id"`
}
// HistoricAlertConfiguration represents a previously used alerting configuration.
type HistoricAlertConfiguration struct {
ID int64 `xorm:"pk autoincr 'id'"`
AlertConfiguration `xorm:"extends"`
// LastApplied a timestamp indicating the most recent time at which the configuration was applied to an Alertmanager, or 0 otherwise.
// Only set this field if the configuration has been applied by the caller.
LastApplied int64 `xorm:"last_applied"`
}
// SaveAlertmanagerConfigurationCmd is the command to save an alertmanager configuration.
type SaveAlertmanagerConfigurationCmd struct {
AlertmanagerConfiguration string
FetchedConfigurationHash string
ConfigurationVersion string
Default bool
OrgID int64
LastApplied int64
}
// MarkConfigurationAsAppliedCmd is the command for marking a previously saved configuration as successfully applied.
type MarkConfigurationAsAppliedCmd struct {
OrgID int64
ConfigurationHash string
}
func HistoricConfigFromAlertConfig(config AlertConfiguration) HistoricAlertConfiguration {
// Reset the ID so it can be generated by the DB.
config.ID = 0
return HistoricAlertConfiguration{
AlertConfiguration: config,
}
}