mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 01:23:32 -06:00
Alerting: Move alertmanager default config to UnifiedAlertingSettings (#39597)
This commit is contained in:
parent
01deae2105
commit
05eb30e323
@ -55,29 +55,6 @@ const (
|
||||
defaultResolveTimeout = 5 * time.Minute
|
||||
// memoryAlertsGCInterval is the interval at which we'll remove resolved alerts from memory.
|
||||
memoryAlertsGCInterval = 30 * time.Minute
|
||||
// To start, the alertmanager needs at least one route defined.
|
||||
// TODO: we should move this to Grafana settings and define this as the default.
|
||||
alertmanagerDefaultConfiguration = `
|
||||
{
|
||||
"alertmanager_config": {
|
||||
"route": {
|
||||
"receiver": "grafana-default-email"
|
||||
},
|
||||
"receivers": [{
|
||||
"name": "grafana-default-email",
|
||||
"grafana_managed_receiver_configs": [{
|
||||
"uid": "",
|
||||
"name": "email receiver",
|
||||
"type": "email",
|
||||
"isDefault": true,
|
||||
"settings": {
|
||||
"addresses": "<example@email.com>"
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
`
|
||||
)
|
||||
|
||||
type ClusterPeer interface {
|
||||
@ -252,19 +229,19 @@ func (am *Alertmanager) SaveAndApplyDefaultConfig() error {
|
||||
defer am.reloadConfigMtx.Unlock()
|
||||
|
||||
cmd := &ngmodels.SaveAlertmanagerConfigurationCmd{
|
||||
AlertmanagerConfiguration: alertmanagerDefaultConfiguration,
|
||||
AlertmanagerConfiguration: am.Settings.UnifiedAlerting.DefaultConfiguration,
|
||||
Default: true,
|
||||
ConfigurationVersion: fmt.Sprintf("v%d", ngmodels.AlertConfigurationVersion),
|
||||
OrgID: am.orgID,
|
||||
}
|
||||
|
||||
cfg, err := Load([]byte(alertmanagerDefaultConfiguration))
|
||||
cfg, err := Load([]byte(am.Settings.UnifiedAlerting.DefaultConfiguration))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = am.Store.SaveAlertmanagerConfigurationWithCallback(cmd, func() error {
|
||||
if err := am.applyConfig(cfg, []byte(alertmanagerDefaultConfiguration)); err != nil {
|
||||
if err := am.applyConfig(cfg, []byte(am.Settings.UnifiedAlerting.DefaultConfiguration)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -33,7 +33,7 @@ func TestMultiOrgAlertmanager_SyncAlertmanagersForOrgs(t *testing.T) {
|
||||
m := metrics.NewNGAlert(reg)
|
||||
cfg := &setting.Cfg{
|
||||
DataPath: tmpDir,
|
||||
UnifiedAlerting: setting.UnifiedAlertingSettings{AlertmanagerConfigPollInterval: 3 * time.Minute}, // do not poll in tests.
|
||||
UnifiedAlerting: setting.UnifiedAlertingSettings{AlertmanagerConfigPollInterval: 3 * time.Minute, DefaultConfiguration: setting.AlertmanagerDefaultConfiguration}, // do not poll in tests.
|
||||
}
|
||||
mam, err := NewMultiOrgAlertmanager(cfg, configStore, orgStore, kvStore, m.GetMultiOrgAlertmanagerMetrics(), log.New("testlogger"))
|
||||
require.NoError(t, err)
|
||||
@ -95,7 +95,7 @@ func TestMultiOrgAlertmanager_AlertmanagerFor(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
cfg := &setting.Cfg{
|
||||
DataPath: tmpDir,
|
||||
UnifiedAlerting: setting.UnifiedAlertingSettings{AlertmanagerConfigPollInterval: 3 * time.Minute}, // do not poll in tests.
|
||||
UnifiedAlerting: setting.UnifiedAlertingSettings{AlertmanagerConfigPollInterval: 3 * time.Minute, DefaultConfiguration: setting.AlertmanagerDefaultConfiguration}, // do not poll in tests.
|
||||
}
|
||||
kvStore := newFakeKVStore(t)
|
||||
reg := prometheus.NewPedanticRegistry()
|
||||
|
@ -17,6 +17,28 @@ const (
|
||||
AlertmanagerDefaultPushPullInterval = cluster.DefaultPushPullInterval
|
||||
SchedulerDefaultAdminConfigPollInterval = 60 * time.Second
|
||||
AlertmanagerDefaultConfigPollInterval = 60 * time.Second
|
||||
// To start, the alertmanager needs at least one route defined.
|
||||
// TODO: we should move this to Grafana settings and define this as the default.
|
||||
AlertmanagerDefaultConfiguration = `{
|
||||
"alertmanager_config": {
|
||||
"route": {
|
||||
"receiver": "grafana-default-email"
|
||||
},
|
||||
"receivers": [{
|
||||
"name": "grafana-default-email",
|
||||
"grafana_managed_receiver_configs": [{
|
||||
"uid": "",
|
||||
"name": "email receiver",
|
||||
"type": "email",
|
||||
"isDefault": true,
|
||||
"settings": {
|
||||
"addresses": "<example@email.com>"
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
`
|
||||
)
|
||||
|
||||
type UnifiedAlertingSettings struct {
|
||||
@ -28,6 +50,7 @@ type UnifiedAlertingSettings struct {
|
||||
HAPeerTimeout time.Duration
|
||||
HAGossipInterval time.Duration
|
||||
HAPushPullInterval time.Duration
|
||||
DefaultConfiguration string
|
||||
}
|
||||
|
||||
func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error {
|
||||
@ -64,6 +87,8 @@ func (cfg *Cfg) ReadUnifiedAlertingSettings(iniFile *ini.File) error {
|
||||
uaCfg.HAPeers = append(uaCfg.HAPeers, peer)
|
||||
}
|
||||
}
|
||||
// TODO load from ini file
|
||||
uaCfg.DefaultConfiguration = AlertmanagerDefaultConfiguration
|
||||
cfg.UnifiedAlerting = uaCfg
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user