diff --git a/pkg/alertmanager/alertmanager.go b/pkg/alertmanager/alertmanager.go index e352b89b77..475a5f4fc4 100644 --- a/pkg/alertmanager/alertmanager.go +++ b/pkg/alertmanager/alertmanager.go @@ -113,7 +113,7 @@ func init() { type State interface { AddState(string, cluster.State, prometheus.Registerer) cluster.ClusterChannel Position() int - WaitReady() + WaitReady(context.Context) error } // New creates a new Alertmanager. @@ -426,11 +426,11 @@ func md5HashAsMetricValue(data []byte) float64 { // In a multi-tenant environment, we choose not to expose these to tenants and thus are not implemented. type NilPeer struct{} -func (p *NilPeer) Name() string { return "" } -func (p *NilPeer) Status() string { return "ready" } -func (p *NilPeer) Peers() []cluster.ClusterMember { return nil } -func (p *NilPeer) Position() int { return 0 } -func (p *NilPeer) WaitReady() {} +func (p *NilPeer) Name() string { return "" } +func (p *NilPeer) Status() string { return "ready" } +func (p *NilPeer) Peers() []cluster.ClusterMember { return nil } +func (p *NilPeer) Position() int { return 0 } +func (p *NilPeer) WaitReady(context.Context) error { return nil } func (p *NilPeer) AddState(string, cluster.State, prometheus.Registerer) cluster.ClusterChannel { return &NilChannel{} } diff --git a/pkg/alertmanager/state_replication.go b/pkg/alertmanager/state_replication.go index d5f3e4f60b..eeca98d785 100644 --- a/pkg/alertmanager/state_replication.go +++ b/pkg/alertmanager/state_replication.go @@ -129,11 +129,17 @@ func (s *state) Settle(ctx context.Context, _ time.Duration) { } // WaitReady is needed for the pipeline builder to know whenever we've settled and the state is up to date. -func (s *state) WaitReady() { +func (s *state) WaitReady(ctx context.Context) error { //TODO: At the moment, we settle in a separate go-routine (see multitenant.go as we create the Peer) we should // mimic that behaviour here once we have full state replication. - s.Settle(context.Background(), time.Second) - <-s.readyc + s.Settle(ctx, time.Second) + + select { + case <-ctx.Done(): + return ctx.Err() + case <-s.readyc: + return nil + } } func (s *state) Ready() bool {