mirror of
				https://github.com/grafana/grafana.git
				synced 2025-02-25 18:55:37 -06:00 
			
		
		
		
	Alerting: Enable remote primary mode using feature toggles (#88976)
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user