Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement peering with pubsub #1215

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@ func (w *countingWriterSender) waitForCount(t testing.TB, target int) {
}
}

type testPeers struct {
peers []string
}

func (p *testPeers) GetPeers() ([]string, error) {
return p.peers, nil
}

func (p *testPeers) RegisterUpdatedPeersCallback(callback func()) {
}

func newStartedApp(
t testing.TB,
libhoneyT transmission.Sender,
Expand Down Expand Up @@ -331,8 +320,8 @@ func TestPeerRouting(t *testing.T) {
// Parallel integration tests need different ports!
t.Parallel()

peers := &testPeers{
peers: []string{
peers := &peer.MockPeers{
Peers: []string{
"http://localhost:11001",
"http://localhost:11003",
},
Expand Down Expand Up @@ -464,8 +453,8 @@ func TestHostMetadataSpanAdditions(t *testing.T) {
func TestEventsEndpoint(t *testing.T) {
t.Parallel()

peers := &testPeers{
peers: []string{
peers := &peer.MockPeers{
Peers: []string{
"http://localhost:13001",
"http://localhost:13003",
},
Expand Down Expand Up @@ -580,8 +569,8 @@ func TestEventsEndpoint(t *testing.T) {
func TestEventsEndpointWithNonLegacyKey(t *testing.T) {
t.Parallel()

peers := &testPeers{
peers: []string{
peers := &peer.MockPeers{
Peers: []string{
"http://localhost:15001",
"http://localhost:15003",
},
Expand Down Expand Up @@ -843,8 +832,8 @@ func BenchmarkDistributedTraces(b *testing.B) {
},
}

peers := &testPeers{
peers: []string{
peers := &peer.MockPeers{
Peers: []string{
"http://localhost:12001",
"http://localhost:12003",
"http://localhost:12005",
Expand Down
8 changes: 8 additions & 0 deletions internal/peer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ func (p *filePeers) RegisterUpdatedPeersCallback(callback func()) {
// otherwise do nothing since they never change
callback()
}

func (p *filePeers) Start() error {
return nil
}

func (p *filePeers) Stop() error {
return nil
}
12 changes: 12 additions & 0 deletions internal/peer/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ type MockPeers struct {
Peers []string
}

// ensure that MockPeers implements the Peers interface
var _ Peers = (*MockPeers)(nil)

func (p *MockPeers) GetPeers() ([]string, error) {
return p.Peers, nil
}

func (p *MockPeers) RegisterUpdatedPeersCallback(callback func()) {
callback()
}

func (p *MockPeers) Start() error {
return nil
}

func (p *MockPeers) Stop() error {
return nil
}
7 changes: 6 additions & 1 deletion internal/peer/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"context"
"errors"

"github.com/facebookgo/startstop"
"github.com/honeycombio/refinery/config"
)

// Peers holds the collection of peers for the cluster
type Peers interface {
GetPeers() ([]string, error)

RegisterUpdatedPeersCallback(callback func())
// make it injectable
startstop.Starter
startstop.Stopper
}

func NewPeers(ctx context.Context, c config.Config, done chan struct{}) (Peers, error) {
Expand All @@ -26,6 +29,8 @@ func NewPeers(ctx context.Context, c config.Config, done chan struct{}) (Peers,
return newFilePeers(c), nil
case "redis":
return newRedisPeers(ctx, c, done)
case "pubsub":
return newPubsubPeers(c)
default:
return nil, errors.New("invalid config option 'PeerManagement.Type'")
}
Expand Down
28 changes: 20 additions & 8 deletions internal/peer/peers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"time"

"github.com/honeycombio/refinery/config"
"github.com/honeycombio/refinery/pubsub"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewPeers(t *testing.T) {
func TestNewPeersFile(t *testing.T) {
c := &config.MockConfig{
PeerManagementType: "file",
PeerTimeout: 5 * time.Second,
Expand All @@ -30,21 +31,32 @@ func TestNewPeers(t *testing.T) {
default:
t.Errorf("received %T expected %T", i, &filePeers{})
}
}

c = &config.MockConfig{
GetPeerListenAddrVal: "0.0.0.0:8081",
PeerManagementType: "redis",
PeerTimeout: 5 * time.Second,
func TestNewPeersPubSub(t *testing.T) {
c := &config.MockConfig{
GetPeerListenAddrVal: "0.0.0.0:8081",
PeerManagementType: "pubsub",
PeerTimeout: 5 * time.Second,
IdentifierInterfaceName: "eth0",
}

p, err = NewPeers(context.Background(), c, done)
pubsub := pubsub.LocalPubSub{}
pubsub.Start()

done := make(chan struct{})
defer close(done)
p, err := NewPeers(context.Background(), c, done)
assert.NoError(t, err)
require.NotNil(t, p)
p.(*pubsubPeers).PubSub = &pubsub
p.Start()
defer p.Stop()

switch i := p.(type) {
case *redisPeers:
case *pubsubPeers:
default:
t.Errorf("received %T expected %T", i, &redisPeers{})
t.Errorf("received %T expected %T", i, &pubsubPeers{})
}
}

Expand Down
Loading
Loading