Skip to content

Commit 863df8d

Browse files
stevesgharry671003
authored andcommitted
Pass context to WaitReady of alertmanager Peer interface. (cortexproject#3931)
* Update alertmanager. Signed-off-by: Steve Simpson <steve.simpson@grafana.com> * Pass context to WaitReady of alertmanager Peer interface. Signed-off-by: Steve Simpson <steve.simpson@grafana.com>
1 parent eab7ed8 commit 863df8d

File tree

7 files changed

+30
-17
lines changed

7 files changed

+30
-17
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ require (
4343
github.com/opentracing-contrib/go-stdlib v1.0.0
4444
github.com/opentracing/opentracing-go v1.2.0
4545
github.com/pkg/errors v0.9.1
46-
github.com/prometheus/alertmanager v0.21.1-0.20210303154452-7866b9bb0927
46+
github.com/prometheus/alertmanager v0.21.1-0.20210310093010-0f9cab6991e6
4747
github.com/prometheus/client_golang v1.9.0
4848
github.com/prometheus/client_model v0.2.0
4949
github.com/prometheus/common v0.18.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,8 @@ github.com/prometheus/alertmanager v0.21.0/go.mod h1:h7tJ81NA0VLWvWEayi1QltevFkL
10371037
github.com/prometheus/alertmanager v0.21.1-0.20200911160112-1fdff6b3f939/go.mod h1:imXRHOP6QTsE0fFsIsAV/cXimS32m7gVZOiUj11m6Ig=
10381038
github.com/prometheus/alertmanager v0.21.1-0.20201106142418-c39b78780054 h1:NgCRBfzDpyIhX6Pjh7XSWPHUC8T5dA1yVuK/gwXM7Jw=
10391039
github.com/prometheus/alertmanager v0.21.1-0.20201106142418-c39b78780054/go.mod h1:imXRHOP6QTsE0fFsIsAV/cXimS32m7gVZOiUj11m6Ig=
1040-
github.com/prometheus/alertmanager v0.21.1-0.20210303154452-7866b9bb0927 h1:BLdqq8kRvpCWghcXjU32mi4pzJlyo8InM5hfmIqFyoc=
1041-
github.com/prometheus/alertmanager v0.21.1-0.20210303154452-7866b9bb0927/go.mod h1:MTqVn+vIupE0dzdgo+sMcNCp37SCAi8vPrvKTTnTz9g=
1040+
github.com/prometheus/alertmanager v0.21.1-0.20210310093010-0f9cab6991e6 h1:WeazuhFA+g8Xce5wgqskDP+b48oQKk7smH72dxO2beA=
1041+
github.com/prometheus/alertmanager v0.21.1-0.20210310093010-0f9cab6991e6/go.mod h1:MTqVn+vIupE0dzdgo+sMcNCp37SCAi8vPrvKTTnTz9g=
10421042
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
10431043
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
10441044
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=

pkg/alertmanager/alertmanager.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func init() {
113113
type State interface {
114114
AddState(string, cluster.State, prometheus.Registerer) cluster.ClusterChannel
115115
Position() int
116-
WaitReady()
116+
WaitReady(context.Context) error
117117
}
118118

119119
// New creates a new Alertmanager.
@@ -426,11 +426,11 @@ func md5HashAsMetricValue(data []byte) float64 {
426426
// In a multi-tenant environment, we choose not to expose these to tenants and thus are not implemented.
427427
type NilPeer struct{}
428428

429-
func (p *NilPeer) Name() string { return "" }
430-
func (p *NilPeer) Status() string { return "ready" }
431-
func (p *NilPeer) Peers() []cluster.ClusterMember { return nil }
432-
func (p *NilPeer) Position() int { return 0 }
433-
func (p *NilPeer) WaitReady() {}
429+
func (p *NilPeer) Name() string { return "" }
430+
func (p *NilPeer) Status() string { return "ready" }
431+
func (p *NilPeer) Peers() []cluster.ClusterMember { return nil }
432+
func (p *NilPeer) Position() int { return 0 }
433+
func (p *NilPeer) WaitReady(context.Context) error { return nil }
434434
func (p *NilPeer) AddState(string, cluster.State, prometheus.Registerer) cluster.ClusterChannel {
435435
return &NilChannel{}
436436
}

pkg/alertmanager/state_replication.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,17 @@ func (s *state) Settle(ctx context.Context, _ time.Duration) {
129129
}
130130

131131
// WaitReady is needed for the pipeline builder to know whenever we've settled and the state is up to date.
132-
func (s *state) WaitReady() {
132+
func (s *state) WaitReady(ctx context.Context) error {
133133
//TODO: At the moment, we settle in a separate go-routine (see multitenant.go as we create the Peer) we should
134134
// mimic that behaviour here once we have full state replication.
135-
s.Settle(context.Background(), time.Second)
136-
<-s.readyc
135+
s.Settle(ctx, time.Second)
136+
137+
select {
138+
case <-ctx.Done():
139+
return ctx.Err()
140+
case <-s.readyc:
141+
return nil
142+
}
137143
}
138144

139145
func (s *state) Ready() bool {

vendor/github.com/prometheus/alertmanager/cluster/cluster.go

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/alertmanager/notify/notify.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)