Skip to content

Commit

Permalink
clientv3: configure keep-alive parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Gyu-Ho Lee <[email protected]>
  • Loading branch information
gyuho committed Jul 15, 2017
1 parent 2e8d0d4 commit 0be8a68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
17 changes: 8 additions & 9 deletions clientv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sync"
"time"

kp "github.com/coreos/etcd/etcdserver/api/v3rpc/keepalive"
"github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes"

"golang.org/x/net/context"
Expand Down Expand Up @@ -216,16 +217,14 @@ func (c *Client) dialSetupOpts(endpoint string, dopts ...grpc.DialOption) (opts
if c.cfg.DialTimeout > 0 {
opts = []grpc.DialOption{grpc.WithTimeout(c.cfg.DialTimeout)}
}
if c.cfg.DialKeepAliveTime > 0 {
params := keepalive.ClientParameters{
Time: c.cfg.DialKeepAliveTime,
}
// Only relevant when KeepAliveTime is non-zero
if c.cfg.DialKeepAliveTimeout > 0 {
params.Timeout = c.cfg.DialKeepAliveTimeout
}
opts = append(opts, grpc.WithKeepaliveParams(params))

params := keepalive.ClientParameters{
Time: kp.Policy.MinTime,
}
if c.cfg.DialKeepAliveTimeout > 0 {
params.Timeout = c.cfg.DialKeepAliveTimeout
}
opts = append(opts, grpc.WithKeepaliveParams(params))
opts = append(opts, dopts...)

f := func(host string, t time.Duration) (net.Conn, error) {
Expand Down
4 changes: 0 additions & 4 deletions clientv3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ type Config struct {
// DialTimeout is the timeout for failing to establish a connection.
DialTimeout time.Duration `json:"dial-timeout"`

// DialKeepAliveTime is the time in seconds after which client pings the server to see if
// transport is alive.
DialKeepAliveTime time.Duration `json:"dial-keep-alive-time"`

// DialKeepAliveTimeout is the time in seconds that the client waits for a response for the
// keep-alive probe. If the response is not received in this time, the connection is closed.
DialKeepAliveTimeout time.Duration `json:"dial-keep-alive-timeout"`
Expand Down

0 comments on commit 0be8a68

Please sign in to comment.