Skip to content

Commit

Permalink
feat: extend kv.client storeconfig to support memberlist flags
Browse files Browse the repository at this point in the history
  • Loading branch information
NickAnge committed Nov 19, 2024
1 parent f2a7eb3 commit 0a9539c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions kv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ var (
// Consul, Etcd, Memberlist or MultiClient. It was extracted from Config to keep
// single-client config separate from final client-config (with all the wrappers)
type StoreConfig struct {
Consul consul.Config `yaml:"consul"`
Etcd etcd.Config `yaml:"etcd"`
Multi MultiConfig `yaml:"multi"`
Consul consul.Config `yaml:"consul"`
Etcd etcd.Config `yaml:"etcd"`
MemberlistKVConfig memberlist.KVConfig `yaml:"memberlist"`
Multi MultiConfig `yaml:"multi"`

// Function that returns memberlist.KV store to use. By using a function, we can delay
// initialization of memberlist.KV until it is actually required.
Expand Down Expand Up @@ -74,6 +75,7 @@ func (cfg *Config) RegisterFlagsWithPrefix(flagsPrefix, defaultPrefix string, f
cfg.Consul.RegisterFlags(f, flagsPrefix)
cfg.Etcd.RegisterFlagsWithPrefix(f, flagsPrefix)
cfg.Multi.RegisterFlagsWithPrefix(f, flagsPrefix)
cfg.MemberlistKVConfig.RegisterFlagsWithPrefix(f, flagsPrefix)

if flagsPrefix == "" {
flagsPrefix = "ring."
Expand Down
7 changes: 7 additions & 0 deletions kv/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ consul:
host: "consul:8500"
consistentreads: true
prefix: "test/"
memberlist:
node_name: "testNode"
randomize_node_name: false
stream_timeout: 3s
multi:
primary: consul
secondary: etcd
Expand All @@ -35,6 +39,9 @@ multi:
require.Equal(t, "consul", cfg.Store)
require.Equal(t, "test/", cfg.Prefix)
require.Equal(t, "consul:8500", cfg.Consul.Host)
require.Equal(t, "testNode", cfg.MemberlistKVConfig.NodeName)
require.Equal(t, false, cfg.MemberlistKVConfig.RandomizeNodeName)
require.Equal(t, 3, cfg.MemberlistKVConfig.StreamTimeout)
require.Equal(t, "consul", cfg.Multi.Primary)
require.Equal(t, "etcd", cfg.Multi.Secondary)
}
Expand Down

0 comments on commit 0a9539c

Please sign in to comment.