Skip to content

Commit

Permalink
Allow change of default KV store. (#120)
Browse files Browse the repository at this point in the history
* Allow change of default KV store.

* CHANGELOG.md
  • Loading branch information
pstibrany committed Jan 28, 2022
1 parent 0bff37e commit 7436a77
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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
* [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 == "" {
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)
}

0 comments on commit 7436a77

Please sign in to comment.