Use an interface for the Channel too

Signed-off-by: gotjosh <josue@grafana.com>
This commit is contained in:
gotjosh 2021-02-25 16:00:49 +00:00
parent 40279b7fa4
commit f3a4f77021
No known key found for this signature in database
GPG Key ID: 731A782929412860
1 changed files with 6 additions and 1 deletions

View File

@ -51,6 +51,11 @@ type ClusterMember interface {
Address() string Address() string
} }
// ClusterChannel supports state broadcasting across peers.
type ClusterChannel interface {
Broadcast([]byte)
}
// Peer is a single peer in a gossip cluster. // Peer is a single peer in a gossip cluster.
type Peer struct { type Peer struct {
mlist *memberlist.Memberlist mlist *memberlist.Memberlist
@ -530,7 +535,7 @@ func (p *Peer) peerUpdate(n *memberlist.Node) {
// AddState adds a new state that will be gossiped. It returns a channel to which // AddState adds a new state that will be gossiped. It returns a channel to which
// broadcast messages for the state can be sent. // broadcast messages for the state can be sent.
func (p *Peer) AddState(key string, s State, reg prometheus.Registerer) *Channel { func (p *Peer) AddState(key string, s State, reg prometheus.Registerer) ClusterChannel {
p.states[key] = s p.states[key] = s
send := func(b []byte) { send := func(b []byte) {
p.delegate.bcast.QueueBroadcast(simpleBroadcast(b)) p.delegate.bcast.QueueBroadcast(simpleBroadcast(b))