Alerting: Enable remote primary mode using feature toggles (#88976)

pull/88988/head
Santiago 12 months ago committed by GitHub
parent db25886f9c
commit 5f4d07bb75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 37
      pkg/services/ngalert/ngalert.go
  2. 3
      pkg/services/ngalert/remote/alertmanager.go

@ -203,9 +203,40 @@ func (ng *AlertNG) init() error {
overrides = append(overrides, override)
case remotePrimary:
ng.Log.Warn("Only remote secondary mode is supported at the moment, falling back to remote secondary")
// TODO: Skip setting up clustering with ng.Cfg.UnifiedAlerting.SkipClustering = true
fallthrough
ng.Log.Debug("Starting Grafana with remote primary mode enabled")
m := ng.Metrics.GetRemoteAlertmanagerMetrics()
m.Info.WithLabelValues(metrics.ModeRemotePrimary).Set(1)
ng.Cfg.UnifiedAlerting.SkipClustering = true
// This function will be used by the MOA to create new Alertmanagers.
override := notifier.WithAlertmanagerOverride(func(factoryFn notifier.OrgAlertmanagerFactory) notifier.OrgAlertmanagerFactory {
return func(ctx context.Context, orgID int64) (notifier.Alertmanager, error) {
// Create internal Alertmanager.
internalAM, err := factoryFn(ctx, orgID)
if err != nil {
return nil, err
}
// Create remote Alertmanager.
cfg := remote.AlertmanagerConfig{
BasicAuthPassword: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.Password,
DefaultConfig: ng.Cfg.UnifiedAlerting.DefaultConfiguration,
OrgID: orgID,
PromoteConfig: true,
TenantID: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.TenantID,
URL: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.URL,
}
remoteAM, err := createRemoteAlertmanager(cfg, ng.KVStore, ng.SecretsService.Decrypt, m)
if err != nil {
moaLogger.Error("Failed to create remote Alertmanager, falling back to using only the internal one", "err", err)
return internalAM, nil
}
// Use both Alertmanager implementations in the forked Alertmanager.
return remote.NewRemotePrimaryForkedAlertmanager(log.New("ngalert.forked-alertmanager.remote-primary"), internalAM, remoteAM), nil
}
})
overrides = append(overrides, override)
case remoteSecondary:
ng.Log.Debug("Starting Grafana with remote secondary mode enabled")

@ -466,6 +466,9 @@ func (am *Alertmanager) GetReceivers(ctx context.Context) ([]apimodels.Receiver,
var rcvs []apimodels.Receiver
for _, rcv := range res.Payload {
if rcv.Integrations == nil {
rcv.Integrations = []*apimodels.Integration{}
}
rcvs = append(rcvs, *rcv)
}
return rcvs, nil

Loading…
Cancel
Save