mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Wire up alertmanagerRemoteOnly feature toggle. (#88329)
* Alerting: Wire up alertmanagerRemoteOnly feature toggle. Though the mode isn't feature complete yet, it will be useful to have the feature toggle wired up in order to start testing. * Apply suggestions from code review Co-authored-by: Santiago <santiagohernandez.1997@gmail.com> * Formatting --------- Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>
This commit is contained in:
parent
aac6e6dfd9
commit
08b18113d2
@ -164,7 +164,7 @@ func (ng *AlertNG) init() error {
|
|||||||
// If enabled, configure the remote Alertmanager.
|
// If enabled, configure the remote Alertmanager.
|
||||||
// - If several toggles are enabled, the order of precedence is RemoteOnly, RemotePrimary, RemoteSecondary
|
// - If several toggles are enabled, the order of precedence is RemoteOnly, RemotePrimary, RemoteSecondary
|
||||||
// - If no toggles are enabled, we default to using only the internal Alertmanager
|
// - If no toggles are enabled, we default to using only the internal Alertmanager
|
||||||
// We currently support only remote secondary mode, so in case other toggles are enabled we fall back to remote secondary.
|
// We currently do not support remote primary mode, so we fall back to remote secondary.
|
||||||
var overrides []notifier.Option
|
var overrides []notifier.Option
|
||||||
moaLogger := log.New("ngalert.multiorg.alertmanager")
|
moaLogger := log.New("ngalert.multiorg.alertmanager")
|
||||||
remoteOnly := ng.FeatureToggles.IsEnabled(initCtx, featuremgmt.FlagAlertmanagerRemoteOnly)
|
remoteOnly := ng.FeatureToggles.IsEnabled(initCtx, featuremgmt.FlagAlertmanagerRemoteOnly)
|
||||||
@ -172,7 +172,35 @@ func (ng *AlertNG) init() error {
|
|||||||
remoteSecondary := ng.FeatureToggles.IsEnabled(initCtx, featuremgmt.FlagAlertmanagerRemoteSecondary)
|
remoteSecondary := ng.FeatureToggles.IsEnabled(initCtx, featuremgmt.FlagAlertmanagerRemoteSecondary)
|
||||||
if ng.Cfg.UnifiedAlerting.RemoteAlertmanager.Enable {
|
if ng.Cfg.UnifiedAlerting.RemoteAlertmanager.Enable {
|
||||||
switch {
|
switch {
|
||||||
case remoteOnly, remotePrimary:
|
case remoteOnly:
|
||||||
|
ng.Log.Debug("Starting Grafana with remote only mode enabled")
|
||||||
|
m := ng.Metrics.GetRemoteAlertmanagerMetrics()
|
||||||
|
m.Info.WithLabelValues(metrics.ModeRemoteOnly).Set(1)
|
||||||
|
|
||||||
|
// This function will be used by the MOA to create new Alertmanagers.
|
||||||
|
override := notifier.WithAlertmanagerOverride(func(_ notifier.OrgAlertmanagerFactory) notifier.OrgAlertmanagerFactory {
|
||||||
|
return func(ctx context.Context, orgID int64) (notifier.Alertmanager, error) {
|
||||||
|
// Create remote Alertmanager.
|
||||||
|
cfg := remote.AlertmanagerConfig{
|
||||||
|
BasicAuthPassword: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.Password,
|
||||||
|
DefaultConfig: ng.Cfg.UnifiedAlerting.DefaultConfiguration,
|
||||||
|
OrgID: orgID,
|
||||||
|
TenantID: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.TenantID,
|
||||||
|
URL: ng.Cfg.UnifiedAlerting.RemoteAlertmanager.URL,
|
||||||
|
PromoteConfig: true,
|
||||||
|
}
|
||||||
|
remoteAM, err := createRemoteAlertmanager(cfg, ng.KVStore, ng.SecretsService.Decrypt, m)
|
||||||
|
if err != nil {
|
||||||
|
moaLogger.Error("Failed to create remote Alertmanager", "err", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return remoteAM, nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
overrides = append(overrides, override)
|
||||||
|
|
||||||
|
case remotePrimary:
|
||||||
ng.Log.Warn("Only remote secondary mode is supported at the moment, falling back to remote secondary")
|
ng.Log.Warn("Only remote secondary mode is supported at the moment, falling back to remote secondary")
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user