From ddb85ad6adfed39352980cb7cc003734f3731e2f Mon Sep 17 00:00:00 2001 From: gotjosh Date: Thu, 12 Jan 2023 14:47:22 -0400 Subject: [PATCH] Use the `ClusterPeer` interface from grafana/alerting (#61409) * Use the Cluster interface from grafana/alerting --- pkg/services/ngalert/notifier/alertmanager.go | 12 ++---------- .../ngalert/notifier/multiorg_alertmanager.go | 10 +++++----- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/pkg/services/ngalert/notifier/alertmanager.go b/pkg/services/ngalert/notifier/alertmanager.go index 6cb1b328617..a3cbf7c64aa 100644 --- a/pkg/services/ngalert/notifier/alertmanager.go +++ b/pkg/services/ngalert/notifier/alertmanager.go @@ -18,7 +18,6 @@ import ( "github.com/grafana/alerting/alerting" "github.com/grafana/alerting/alerting/notifier/channels" amv2 "github.com/prometheus/alertmanager/api/v2/models" - "github.com/prometheus/alertmanager/cluster" "github.com/prometheus/alertmanager/config" "github.com/prometheus/alertmanager/dispatch" "github.com/prometheus/alertmanager/inhibit" @@ -31,7 +30,6 @@ import ( "github.com/prometheus/alertmanager/template" "github.com/prometheus/alertmanager/timeinterval" "github.com/prometheus/alertmanager/types" - "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" alertingModels "github.com/grafana/alerting/alerting/models" @@ -82,12 +80,6 @@ func init() { } } -type ClusterPeer interface { - AddState(string, cluster.State, prometheus.Registerer) cluster.ClusterChannel - Position() int - WaitReady(context.Context) error -} - type AlertingStore interface { store.AlertingStore store.ImageStore @@ -106,7 +98,7 @@ type Alertmanager struct { marker types.Marker alerts *mem.Alerts route *dispatch.Route - peer ClusterPeer + peer alerting.ClusterPeer peerTimeout time.Duration dispatcher *dispatch.Dispatcher @@ -163,7 +155,7 @@ func (m maintenanceOptions) MaintenanceFunc(state alerting.State) (int64, error) } func newAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store AlertingStore, kvStore kvstore.KVStore, - peer ClusterPeer, decryptFn channels.GetDecryptedValueFn, ns notifications.Service, m *metrics.Alertmanager) (*Alertmanager, error) { + peer alerting.ClusterPeer, decryptFn channels.GetDecryptedValueFn, ns notifications.Service, m *metrics.Alertmanager) (*Alertmanager, error) { am := &Alertmanager{ Settings: cfg, stopc: make(chan struct{}), diff --git a/pkg/services/ngalert/notifier/multiorg_alertmanager.go b/pkg/services/ngalert/notifier/multiorg_alertmanager.go index 88a37763dd9..ef427321718 100644 --- a/pkg/services/ngalert/notifier/multiorg_alertmanager.go +++ b/pkg/services/ngalert/notifier/multiorg_alertmanager.go @@ -9,10 +9,7 @@ import ( "sync" "time" - "github.com/grafana/grafana/pkg/services/ngalert/provisioning" - "github.com/grafana/grafana/pkg/services/notifications" - "github.com/grafana/grafana/pkg/services/secrets" - + "github.com/grafana/alerting/alerting" "github.com/grafana/alerting/alerting/notifier/channels" "github.com/prometheus/alertmanager/cluster" "github.com/prometheus/client_golang/prometheus" @@ -21,7 +18,10 @@ import ( "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/services/ngalert/metrics" "github.com/grafana/grafana/pkg/services/ngalert/models" + "github.com/grafana/grafana/pkg/services/ngalert/provisioning" "github.com/grafana/grafana/pkg/services/ngalert/store" + "github.com/grafana/grafana/pkg/services/notifications" + "github.com/grafana/grafana/pkg/services/secrets" "github.com/grafana/grafana/pkg/setting" ) @@ -41,7 +41,7 @@ type MultiOrgAlertmanager struct { logger log.Logger // clusterPeer represents the clustering peers of Alertmanagers between Grafana instances. - peer ClusterPeer + peer alerting.ClusterPeer settleCancel context.CancelFunc configStore AlertingStore