diff --git a/go.mod b/go.mod index 5717dfb24e..c4c55efa5f 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( github.com/opentracing-contrib/go-stdlib v1.0.0 github.com/opentracing/opentracing-go v1.2.0 github.com/pkg/errors v0.9.1 - github.com/prometheus/alertmanager v0.21.1-0.20210303154452-7866b9bb0927 + github.com/prometheus/alertmanager v0.21.1-0.20210310093010-0f9cab6991e6 github.com/prometheus/client_golang v1.9.0 github.com/prometheus/client_model v0.2.0 github.com/prometheus/common v0.18.0 diff --git a/go.sum b/go.sum index 29bc01465e..f4b3381e06 100644 --- a/go.sum +++ b/go.sum @@ -1037,8 +1037,8 @@ github.com/prometheus/alertmanager v0.21.0/go.mod h1:h7tJ81NA0VLWvWEayi1QltevFkL github.com/prometheus/alertmanager v0.21.1-0.20200911160112-1fdff6b3f939/go.mod h1:imXRHOP6QTsE0fFsIsAV/cXimS32m7gVZOiUj11m6Ig= github.com/prometheus/alertmanager v0.21.1-0.20201106142418-c39b78780054 h1:NgCRBfzDpyIhX6Pjh7XSWPHUC8T5dA1yVuK/gwXM7Jw= github.com/prometheus/alertmanager v0.21.1-0.20201106142418-c39b78780054/go.mod h1:imXRHOP6QTsE0fFsIsAV/cXimS32m7gVZOiUj11m6Ig= -github.com/prometheus/alertmanager v0.21.1-0.20210303154452-7866b9bb0927 h1:BLdqq8kRvpCWghcXjU32mi4pzJlyo8InM5hfmIqFyoc= -github.com/prometheus/alertmanager v0.21.1-0.20210303154452-7866b9bb0927/go.mod h1:MTqVn+vIupE0dzdgo+sMcNCp37SCAi8vPrvKTTnTz9g= +github.com/prometheus/alertmanager v0.21.1-0.20210310093010-0f9cab6991e6 h1:WeazuhFA+g8Xce5wgqskDP+b48oQKk7smH72dxO2beA= +github.com/prometheus/alertmanager v0.21.1-0.20210310093010-0f9cab6991e6/go.mod h1:MTqVn+vIupE0dzdgo+sMcNCp37SCAi8vPrvKTTnTz9g= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= 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 { diff --git a/vendor/github.com/prometheus/alertmanager/cluster/cluster.go b/vendor/github.com/prometheus/alertmanager/cluster/cluster.go index 04e66789bc..a12beb9575 100644 --- a/vendor/github.com/prometheus/alertmanager/cluster/cluster.go +++ b/vendor/github.com/prometheus/alertmanager/cluster/cluster.go @@ -584,8 +584,13 @@ func (p *Peer) Ready() bool { } // Wait until Settle() has finished. -func (p *Peer) WaitReady() { - <-p.readyc +func (p *Peer) WaitReady(ctx context.Context) error { + select { + case <-ctx.Done(): + return ctx.Err() + case <-p.readyc: + return nil + } } // Return a status string representing the peer state. diff --git a/vendor/github.com/prometheus/alertmanager/notify/notify.go b/vendor/github.com/prometheus/alertmanager/notify/notify.go index 3dcc30f6ec..2f2205c9e8 100644 --- a/vendor/github.com/prometheus/alertmanager/notify/notify.go +++ b/vendor/github.com/prometheus/alertmanager/notify/notify.go @@ -44,7 +44,7 @@ type ResolvedSender interface { // Peer represents the cluster node from where we are the sending the notification. type Peer interface { // WaitReady waits until the node silences and notifications have settled before attempting to send a notification. - WaitReady() + WaitReady(context.Context) error } // MinTimeout is the minimum timeout that is set for the context of a call @@ -430,7 +430,9 @@ func NewGossipSettleStage(p Peer) *GossipSettleStage { func (n *GossipSettleStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error) { if n.peer != nil { - n.peer.WaitReady() + if err := n.peer.WaitReady(ctx); err != nil { + return ctx, nil, err + } } return ctx, alerts, nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index c68c041cf9..2245ca4bae 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -400,7 +400,7 @@ github.com/opentracing/opentracing-go/log github.com/pkg/errors # github.com/pmezard/go-difflib v1.0.0 github.com/pmezard/go-difflib/difflib -# github.com/prometheus/alertmanager v0.21.1-0.20210303154452-7866b9bb0927 +# github.com/prometheus/alertmanager v0.21.1-0.20210310093010-0f9cab6991e6 ## explicit github.com/prometheus/alertmanager/api github.com/prometheus/alertmanager/api/metrics