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

fix: join peer list only after refinery is ready to accept traffic #1309

Merged
merged 2 commits into from
Sep 4, 2024
Merged
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
8 changes: 8 additions & 0 deletions cmd/refinery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ func main() {
os.Exit(1)
}

// Now that all components are started, we can notify our peers that we are ready
// to receive data.
err = peers.Ready()
if err != nil {
fmt.Printf("failed to start peer management: %v\n", err)
os.Exit(1)
}

// these have to be done after the injection (of metrics)
// these are the metrics that libhoney will emit; we preregister them so that they always appear
libhoneyMetricsName := map[string]string{
Expand Down
4 changes: 4 additions & 0 deletions internal/peer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (p *FilePeers) Start() (err error) {
return nil
}

func (p *FilePeers) Ready() error {
return nil
}

func (p *FilePeers) publicAddr() (string, error) {
addr := p.Cfg.GetPeerListenAddr()
host, port, err := net.SplitHostPort(addr)
Expand Down
4 changes: 4 additions & 0 deletions internal/peer/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ func (p *MockPeers) Start() error {
return nil
}

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

func (p *MockPeers) stop() {}
1 change: 1 addition & 0 deletions internal/peer/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Peers interface {
GetPeers() ([]string, error)
GetInstanceID() (string, error)
RegisterUpdatedPeersCallback(callback func())
Ready() error
// make it injectable
startstop.Starter
}
9 changes: 9 additions & 0 deletions internal/peer/pubsub_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,15 @@ func (p *RedisPubsubPeers) Start() error {
if err != nil {
return err
}
p.peers.Add(myaddr)
return nil
}

func (p *RedisPubsubPeers) Ready() error {
myaddr, err := p.publicAddr()
if err != nil {
return err
}
// periodically refresh our presence in the list of peers, and update peers as they come in
go func() {
// we want our refresh cache interval to vary from peer to peer so they
Expand All @@ -164,6 +172,7 @@ func (p *RedisPubsubPeers) Start() error {
p.stop()
return
case <-ticker.Chan():

// publish our presence periodically
ctx, cancel := context.WithTimeout(context.Background(), p.Config.GetPeerTimeout())
err := p.PubSub.Publish(ctx, "peers", newPeerCommand(Register, myaddr).marshal())
Expand Down
Loading