-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: peer management on pubsub via callbacks (#1220)
## Which problem is this PR solving? - Implement the current peers system using a pubsub model for peers - Uses the current pubsub system that uses callbacks ## Short description of the changes - Add start/stop to pubsub so it can become injectable - Fix the mock and existing implementations - Implement pubsub peers using the new pubsub system and generic.SetWithTTL - Add a few tests - Update config metadata - delete legacy redis peering - make it more idiomatically injectable - do all the things to make injection work everywhere closes #1201 --------- Co-authored-by: Yingrong Zhao <22300958+VinozzZ@users.noreply.github.com>
- Loading branch information
Showing
13 changed files
with
456 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,14 @@ | ||
package peer | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/honeycombio/refinery/config" | ||
"github.com/facebookgo/startstop" | ||
) | ||
|
||
// Peers holds the collection of peers for the cluster | ||
type Peers interface { | ||
GetPeers() ([]string, error) | ||
|
||
RegisterUpdatedPeersCallback(callback func()) | ||
} | ||
|
||
func NewPeers(ctx context.Context, c config.Config, done chan struct{}) (Peers, error) { | ||
t, err := c.GetPeerManagementType() | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
switch t { | ||
case "file": | ||
return newFilePeers(c), nil | ||
case "redis": | ||
return newRedisPeers(ctx, c, done) | ||
default: | ||
return nil, errors.New("invalid config option 'PeerManagement.Type'") | ||
} | ||
// make it injectable | ||
startstop.Starter | ||
startstop.Stopper | ||
} |
Oops, something went wrong.