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

Allow change of default KV store. #120

Merged
merged 2 commits into from
Jan 28, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [CHANGE] grpcutil.Resolver.Resolve: Take a service parameter. #102
* [CHANGE] grpcutil.Update: Remove gRPC LB related metadata. #102
* [CHANGE] concurrency.ForEach: deprecated and reimplemented by new `concurrency.ForEachJob`. #113
* [CHANGE] ring/client: It's now possible to set different value than `consul` as default KV store. #120
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really a breaking change?

* [ENHANCEMENT] Add middleware package. #38
* [ENHANCEMENT] Add the ring package #45
* [ENHANCEMENT] Add limiter package. #41
Expand Down
8 changes: 7 additions & 1 deletion kv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ func (cfg *Config) RegisterFlagsWithPrefix(flagsPrefix, defaultPrefix string, f
if flagsPrefix == "" {
flagsPrefix = "ring."
}

// Allow clients to override default store by setting it before calling this method.
if cfg.Store == "" {
replay marked this conversation as resolved.
Show resolved Hide resolved
cfg.Store = "consul"
}

f.StringVar(&cfg.Prefix, flagsPrefix+"prefix", defaultPrefix, "The prefix for the keys in the store. Should end with a /.")
f.StringVar(&cfg.Store, flagsPrefix+"store", "consul", "Backend storage to use for the ring. Supported values are: consul, etcd, inmemory, memberlist, multi.")
f.StringVar(&cfg.Store, flagsPrefix+"store", cfg.Store, "Backend storage to use for the ring. Supported values are: consul, etcd, inmemory, memberlist, multi.")
}

// Client is a high-level client for key-value stores (such as Etcd and
Expand Down
13 changes: 13 additions & 0 deletions kv/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package kv

import (
"context"
"flag"
"testing"
"time"

"github.com/gogo/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"

Expand Down Expand Up @@ -157,3 +159,14 @@ type testLogger struct {
func (l testLogger) Log(keyvals ...interface{}) error {
return nil
}

func TestDefaultStoreValue(t *testing.T) {
cfg1 := Config{}
cfg1.RegisterFlagsWithPrefix("", "", flag.NewFlagSet("test", flag.PanicOnError))
assert.Equal(t, "consul", cfg1.Store)

cfg2 := Config{}
cfg2.Store = "memberlist"
cfg2.RegisterFlagsWithPrefix("", "", flag.NewFlagSet("test", flag.PanicOnError))
assert.Equal(t, "memberlist", cfg2.Store)
}