Skip to content
Open
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
33 changes: 29 additions & 4 deletions cluster/clusterproviders/etcd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ package etcd

import (
clientv3 "go.etcd.io/etcd/client/v3"
"time"
)

const (
DefaultEtcdKeepAliveTtl = 3 * time.Second
DefaultRetryInterval = 1 * time.Second
)

// RoleChangedListener receives notifications when the node role changes.
Expand Down Expand Up @@ -34,12 +40,31 @@ func WithRoleChangedListener(l RoleChangedListener) Option {
}
}

// WithKeepAliveTTL sets the grant TTL for node leases.
func WithKeepAliveTTL(ttl time.Duration) Option {
return func(o *config) {
o.KeepAliveTTL = ttl
}
}

// WithRetryInterval sets the interval between retries for etcd operations.
func WithRetryInterval(interval time.Duration) Option {
return func(o *config) {
o.RetryInterval = interval
}
}

type config struct {
BaseKey string
cfg clientv3.Config
RoleChanged RoleChangedListener
BaseKey string
cfg clientv3.Config
RoleChanged RoleChangedListener
KeepAliveTTL time.Duration
RetryInterval time.Duration
}

func defaultConfig() *config {
return &config{}
return &config{
KeepAliveTTL: DefaultEtcdKeepAliveTtl,
RetryInterval: DefaultRetryInterval,
}
}
4 changes: 2 additions & 2 deletions cluster/clusterproviders/etcd/etcd_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func NewWithConfig(baseKey string, cfg clientv3.Config, opts ...Option) (*Provid
}
p := &Provider{
client: client,
keepAliveTTL: 3 * time.Second,
retryInterval: 1 * time.Second,
keepAliveTTL: c.KeepAliveTTL,
retryInterval: c.RetryInterval,
baseKey: c.BaseKey,
members: map[string]*Node{},
cancelWatchCh: make(chan bool),
Expand Down