Skip to content

Commit

Permalink
Pass context to WaitReady of alertmanager Peer interface. (cortexproj…
Browse files Browse the repository at this point in the history
…ect#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>
  • Loading branch information
stevesg authored and harry671003 committed Mar 11, 2021
1 parent eab7ed8 commit 863df8d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
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
9 changes: 7 additions & 2 deletions vendor/github.com/prometheus/alertmanager/cluster/cluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions vendor/github.com/prometheus/alertmanager/notify/notify.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 863df8d

Please sign in to comment.