Skip to content

Commit

Permalink
Pass context to WaitReady of alertmanager Peer interface.
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Simpson <steve.simpson@grafana.com>
  • Loading branch information
stevesg committed Mar 10, 2021
1 parent cea93a0 commit 9d318af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions pkg/alertmanager/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{}
}
Expand Down
12 changes: 9 additions & 3 deletions pkg/alertmanager/state_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9d318af

Please sign in to comment.