Skip to content

Commit ae20309

Browse files
author
Max
committed
*: Add configurable store timeout
Add a command line option to set the store timeout.
1 parent ca4fbe6 commit ae20309

19 files changed

+45
-22
lines changed

cmd/common.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"os"
2020
"path/filepath"
21+
"time"
2122

2223
"github.com/prometheus/client_golang/prometheus"
2324
"github.com/sorintlab/stolon/internal/cluster"
@@ -50,12 +51,14 @@ type CommonConfig struct {
5051
KubeConfig string
5152
KubeContext string
5253
KubeNamespace string
54+
StoreTimeout time.Duration
5355
}
5456

5557
func AddCommonFlags(cmd *cobra.Command, cfg *CommonConfig) {
5658
cmd.PersistentFlags().StringVar(&cfg.ClusterName, "cluster-name", "", "cluster name")
5759
cmd.PersistentFlags().StringVar(&cfg.StoreBackend, "store-backend", "", "store backend type (etcdv2/etcd, etcdv3, consul or kubernetes)")
5860
cmd.PersistentFlags().StringVar(&cfg.StoreEndpoints, "store-endpoints", "", "a comma-delimited list of store endpoints (use https scheme for tls communication) (defaults: http://127.0.0.1:2379 for etcd, http://127.0.0.1:8500 for consul)")
61+
cmd.PersistentFlags().DurationVar(&cfg.StoreTimeout, "store-timeout", cluster.DefaultStoreTimeout, "store request timeout")
5962
cmd.PersistentFlags().StringVar(&cfg.StorePrefix, "store-prefix", common.StorePrefix, "the store base prefix")
6063
cmd.PersistentFlags().StringVar(&cfg.StoreCertFile, "store-cert-file", "", "certificate file for client identification to the store")
6164
cmd.PersistentFlags().StringVar(&cfg.StoreKeyFile, "store-key", "", "private key file for client identification to the store")
@@ -143,6 +146,7 @@ func NewKVStore(cfg *CommonConfig) (store.KVStore, error) {
143146
return store.NewKVStore(store.Config{
144147
Backend: store.Backend(cfg.StoreBackend),
145148
Endpoints: cfg.StoreEndpoints,
149+
Timeout: cfg.StoreTimeout,
146150
CertFile: cfg.StoreCertFile,
147151
KeyFile: cfg.StoreKeyFile,
148152
CAFile: cfg.StoreCAFile,
@@ -195,7 +199,7 @@ func NewElection(cfg *CommonConfig, uid string) (store.Election, error) {
195199
if err != nil {
196200
return nil, fmt.Errorf("cannot create kv store: %v", err)
197201
}
198-
election = store.NewKVBackedElection(kvstore, filepath.Join(storePath, common.SentinelLeaderKey), uid)
202+
election = store.NewKVBackedElection(kvstore, filepath.Join(storePath, common.SentinelLeaderKey), uid, cfg.StoreTimeout)
199203
case "kubernetes":
200204
kubecli, podName, namespace, err := getKubeValues(cfg)
201205
if err != nil {
@@ -216,7 +220,7 @@ func getKubeValues(cfg *CommonConfig) (*kubernetes.Clientset, string, string, er
216220
if err != nil {
217221
return nil, "", "", err
218222
}
219-
kubecfg.Timeout = cluster.DefaultStoreTimeout
223+
kubecfg.Timeout = cfg.StoreTimeout
220224
kubecli, err := kubernetes.NewForConfig(kubecfg)
221225
if err != nil {
222226
return nil, "", "", fmt.Errorf("cannot create kubernetes client: %v", err)

doc/commands/stolon-keeper.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ stolon-keeper [flags]
4040
--store-key string private key file for client identification to the store
4141
--store-prefix string the store base prefix (default "stolon/cluster")
4242
--store-skip-tls-verify skip store certificate verification (insecure!!!)
43+
--store-timeout duration store request timeout (default 5s)
4344
--uid string keeper uid (must be unique in the cluster and can contain only lower-case letters, numbers and the underscore character). If not provided a random uid will be generated.
4445
```
4546

46-
###### Auto generated by spf13/cobra on 28-Jan-2020
47+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolon-proxy.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ stolon-proxy [flags]
2929
--store-key string private key file for client identification to the store
3030
--store-prefix string the store base prefix (default "stolon/cluster")
3131
--store-skip-tls-verify skip store certificate verification (insecure!!!)
32+
--store-timeout duration store request timeout (default 5s)
3233
--tcp-keepalive-count int set tcp keepalive probe count number
3334
--tcp-keepalive-idle int set tcp keepalive idle (seconds)
3435
--tcp-keepalive-interval int set tcp keepalive interval (seconds)
3536
```
3637

37-
###### Auto generated by spf13/cobra on 28-Jan-2020
38+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolon-sentinel.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ stolon-sentinel [flags]
2727
--store-key string private key file for client identification to the store
2828
--store-prefix string the store base prefix (default "stolon/cluster")
2929
--store-skip-tls-verify skip store certificate verification (insecure!!!)
30+
--store-timeout duration store request timeout (default 5s)
3031
```
3132

32-
###### Auto generated by spf13/cobra on 28-Jan-2020
33+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ stolonctl [flags]
2828
--store-key string private key file for client identification to the store
2929
--store-prefix string the store base prefix (default "stolon/cluster")
3030
--store-skip-tls-verify skip store certificate verification (insecure!!!)
31+
--store-timeout duration store request timeout (default 5s)
3132
```
3233

3334
### SEE ALSO
@@ -43,4 +44,4 @@ stolonctl [flags]
4344
* [stolonctl update](stolonctl_update.md) - Update a cluster specification
4445
* [stolonctl version](stolonctl_version.md) - Display the version
4546

46-
###### Auto generated by spf13/cobra on 28-Jan-2020
47+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_clusterdata.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Manage current cluster data
2929
--store-key string private key file for client identification to the store
3030
--store-prefix string the store base prefix (default "stolon/cluster")
3131
--store-skip-tls-verify skip store certificate verification (insecure!!!)
32+
--store-timeout duration store request timeout (default 5s)
3233
```
3334

3435
### SEE ALSO
@@ -37,4 +38,4 @@ Manage current cluster data
3738
* [stolonctl clusterdata read](stolonctl_clusterdata_read.md) - Retrieve the current cluster data
3839
* [stolonctl clusterdata write](stolonctl_clusterdata_write.md) - Write cluster data
3940

40-
###### Auto generated by spf13/cobra on 28-Jan-2020
41+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_clusterdata_read.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ stolonctl clusterdata read [flags]
3434
--store-key string private key file for client identification to the store
3535
--store-prefix string the store base prefix (default "stolon/cluster")
3636
--store-skip-tls-verify skip store certificate verification (insecure!!!)
37+
--store-timeout duration store request timeout (default 5s)
3738
```
3839

3940
### SEE ALSO
4041

4142
* [stolonctl clusterdata](stolonctl_clusterdata.md) - Manage current cluster data
4243

43-
###### Auto generated by spf13/cobra on 28-Jan-2020
44+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_clusterdata_write.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ stolonctl clusterdata write [flags]
3535
--store-key string private key file for client identification to the store
3636
--store-prefix string the store base prefix (default "stolon/cluster")
3737
--store-skip-tls-verify skip store certificate verification (insecure!!!)
38+
--store-timeout duration store request timeout (default 5s)
3839
```
3940

4041
### SEE ALSO
4142

4243
* [stolonctl clusterdata](stolonctl_clusterdata.md) - Manage current cluster data
4344

44-
###### Auto generated by spf13/cobra on 28-Jan-2020
45+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_failkeeper.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ stolonctl failkeeper [keeper uid] [flags]
3333
--store-key string private key file for client identification to the store
3434
--store-prefix string the store base prefix (default "stolon/cluster")
3535
--store-skip-tls-verify skip store certificate verification (insecure!!!)
36+
--store-timeout duration store request timeout (default 5s)
3637
```
3738

3839
### SEE ALSO
3940

4041
* [stolonctl](stolonctl.md) - stolon command line client
4142

42-
###### Auto generated by spf13/cobra on 28-Jan-2020
43+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_init.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ stolonctl init [flags]
3535
--store-key string private key file for client identification to the store
3636
--store-prefix string the store base prefix (default "stolon/cluster")
3737
--store-skip-tls-verify skip store certificate verification (insecure!!!)
38+
--store-timeout duration store request timeout (default 5s)
3839
```
3940

4041
### SEE ALSO
4142

4243
* [stolonctl](stolonctl.md) - stolon command line client
4344

44-
###### Auto generated by spf13/cobra on 28-Jan-2020
45+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_promote.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ stolonctl promote [flags]
3434
--store-key string private key file for client identification to the store
3535
--store-prefix string the store base prefix (default "stolon/cluster")
3636
--store-skip-tls-verify skip store certificate verification (insecure!!!)
37+
--store-timeout duration store request timeout (default 5s)
3738
```
3839

3940
### SEE ALSO
4041

4142
* [stolonctl](stolonctl.md) - stolon command line client
4243

43-
###### Auto generated by spf13/cobra on 28-Jan-2020
44+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_register.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ stolonctl register [flags]
4444
--store-key string private key file for client identification to the store
4545
--store-prefix string the store base prefix (default "stolon/cluster")
4646
--store-skip-tls-verify skip store certificate verification (insecure!!!)
47+
--store-timeout duration store request timeout (default 5s)
4748
```
4849

4950
### SEE ALSO
5051

5152
* [stolonctl](stolonctl.md) - stolon command line client
5253

53-
###### Auto generated by spf13/cobra on 28-Jan-2020
54+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_removekeeper.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ stolonctl removekeeper [keeper uid] [flags]
3333
--store-key string private key file for client identification to the store
3434
--store-prefix string the store base prefix (default "stolon/cluster")
3535
--store-skip-tls-verify skip store certificate verification (insecure!!!)
36+
--store-timeout duration store request timeout (default 5s)
3637
```
3738

3839
### SEE ALSO
3940

4041
* [stolonctl](stolonctl.md) - stolon command line client
4142

42-
###### Auto generated by spf13/cobra on 28-Jan-2020
43+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_spec.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ stolonctl spec [flags]
3434
--store-key string private key file for client identification to the store
3535
--store-prefix string the store base prefix (default "stolon/cluster")
3636
--store-skip-tls-verify skip store certificate verification (insecure!!!)
37+
--store-timeout duration store request timeout (default 5s)
3738
```
3839

3940
### SEE ALSO
4041

4142
* [stolonctl](stolonctl.md) - stolon command line client
4243

43-
###### Auto generated by spf13/cobra on 28-Jan-2020
44+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_status.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ stolonctl status [flags]
3434
--store-key string private key file for client identification to the store
3535
--store-prefix string the store base prefix (default "stolon/cluster")
3636
--store-skip-tls-verify skip store certificate verification (insecure!!!)
37+
--store-timeout duration store request timeout (default 5s)
3738
```
3839

3940
### SEE ALSO
4041

4142
* [stolonctl](stolonctl.md) - stolon command line client
4243

43-
###### Auto generated by spf13/cobra on 28-Jan-2020
44+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_update.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ stolonctl update [flags]
3535
--store-key string private key file for client identification to the store
3636
--store-prefix string the store base prefix (default "stolon/cluster")
3737
--store-skip-tls-verify skip store certificate verification (insecure!!!)
38+
--store-timeout duration store request timeout (default 5s)
3839
```
3940

4041
### SEE ALSO
4142

4243
* [stolonctl](stolonctl.md) - stolon command line client
4344

44-
###### Auto generated by spf13/cobra on 28-Jan-2020
45+
###### Auto generated by spf13/cobra on 6-Mar-2020

doc/commands/stolonctl_version.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ stolonctl version [flags]
3333
--store-key string private key file for client identification to the store
3434
--store-prefix string the store base prefix (default "stolon/cluster")
3535
--store-skip-tls-verify skip store certificate verification (insecure!!!)
36+
--store-timeout duration store request timeout (default 5s)
3637
```
3738

3839
### SEE ALSO
3940

4041
* [stolonctl](stolonctl.md) - stolon command line client
4142

42-
###### Auto generated by spf13/cobra on 28-Jan-2020
43+
###### Auto generated by spf13/cobra on 6-Mar-2020

internal/store/kvbacked.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ var URLSchemeRegexp = regexp.MustCompile(`^([a-zA-Z][a-zA-Z0-9+-.]*)://`)
6565
type Config struct {
6666
Backend Backend
6767
Endpoints string
68+
Timeout time.Duration
6869
BasePath string
6970
CertFile string
7071
KeyFile string
@@ -172,7 +173,7 @@ func NewKVStore(cfg Config) (KVStore, error) {
172173
case CONSUL, ETCDV2:
173174
config := &libkvstore.Config{
174175
TLS: tlsConfig,
175-
ConnectionTimeout: cluster.DefaultStoreTimeout,
176+
ConnectionTimeout: cfg.Timeout,
176177
}
177178

178179
store, err := libkv.NewStore(kvBackend, addrs, config)
@@ -190,7 +191,7 @@ func NewKVStore(cfg Config) (KVStore, error) {
190191
if err != nil {
191192
return nil, err
192193
}
193-
return &etcdV3Store{c: c, requestTimeout: cluster.DefaultStoreTimeout}, nil
194+
return &etcdV3Store{c: c, requestTimeout: cfg.Timeout}, nil
194195
default:
195196
return nil, fmt.Errorf("Unknown store backend: %q", cfg.Backend)
196197
}
@@ -344,7 +345,7 @@ func (s *KVBackedStore) GetProxiesInfo(ctx context.Context) (cluster.ProxiesInfo
344345
return psi, nil
345346
}
346347

347-
func NewKVBackedElection(kvStore KVStore, path, candidateUID string) Election {
348+
func NewKVBackedElection(kvStore KVStore, path, candidateUID string, timeout time.Duration) Election {
348349
switch kvStore := kvStore.(type) {
349350
case *libKVStore:
350351
s := kvStore
@@ -357,7 +358,7 @@ func NewKVBackedElection(kvStore KVStore, path, candidateUID string) Election {
357358
path: path,
358359
candidateUID: candidateUID,
359360
ttl: MinTTL,
360-
requestTimeout: cluster.DefaultStoreTimeout,
361+
requestTimeout: timeout,
361362
}
362363
default:
363364
panic("unknown kvstore")

tests/integration/utils.go

+2
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ func NewTestEtcd(t *testing.T, dir string, backend store.Backend, a ...string) (
960960
storeConfig := store.Config{
961961
Backend: store.Backend(backend),
962962
Endpoints: storeEndpoints,
963+
Timeout: defaultStoreTimeout,
963964
}
964965
kvstore, err := store.NewKVStore(storeConfig)
965966
if err != nil {
@@ -1043,6 +1044,7 @@ func NewTestConsul(t *testing.T, dir string, a ...string) (*TestStore, error) {
10431044
storeConfig := store.Config{
10441045
Backend: store.CONSUL,
10451046
Endpoints: storeEndpoints,
1047+
Timeout: defaultStoreTimeout,
10461048
}
10471049
kvstore, err := store.NewKVStore(storeConfig)
10481050
if err != nil {

0 commit comments

Comments
 (0)