Skip to content

Commit

Permalink
etcdctl/ctlv3: add "--max-send-bytes","--max-recv-bytes" flags
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Dec 20, 2017
1 parent a331bd1 commit 433c3ef
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
4 changes: 3 additions & 1 deletion etcdctl/ctlv3/command/ep_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) {
ka := keepAliveTimeFromCmd(cmd)
kat := keepAliveTimeoutFromCmd(cmd)
auth := authCfgFromCmd(cmd)
maxCallSendMsgSize := maxSendBytesFromCmd(cmd)
maxCallRecvMsgSize := maxRecvBytesFromCmd(cmd)
cfgs := []*v3.Config{}
for _, ep := range endpointsFromCluster(cmd) {
cfg, err := newClientCfg([]string{ep}, dt, ka, kat, sec, auth)
cfg, err := newClientCfg([]string{ep}, dt, ka, kat, sec, auth, maxCallSendMsgSize, maxCallRecvMsgSize)
if err != nil {
ExitWithError(ExitBadArgs, err)
}
Expand Down
41 changes: 33 additions & 8 deletions etcdctl/ctlv3/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type GlobalFlags struct {
KeepAliveTime time.Duration
KeepAliveTimeout time.Duration

MaxCallSendMsgSize int
MaxCallRecvMsgSize int

TLS transport.TLSInfo

OutputFormat string
Expand Down Expand Up @@ -93,12 +96,14 @@ func initDisplayFromCmd(cmd *cobra.Command) {
}

type clientConfig struct {
endpoints []string
dialTimeout time.Duration
keepAliveTime time.Duration
keepAliveTimeout time.Duration
scfg *secureCfg
acfg *authCfg
endpoints []string
dialTimeout time.Duration
keepAliveTime time.Duration
keepAliveTimeout time.Duration
maxCallSendMsgSize int
maxCallRecvMsgSize int
scfg *secureCfg
acfg *authCfg
}

func clientConfigFromCmd(cmd *cobra.Command) *clientConfig {
Expand Down Expand Up @@ -127,6 +132,8 @@ func clientConfigFromCmd(cmd *cobra.Command) *clientConfig {
cfg.dialTimeout = dialTimeoutFromCmd(cmd)
cfg.keepAliveTime = keepAliveTimeFromCmd(cmd)
cfg.keepAliveTimeout = keepAliveTimeoutFromCmd(cmd)
cfg.maxCallSendMsgSize = maxSendBytesFromCmd(cmd)
cfg.maxCallRecvMsgSize = maxRecvBytesFromCmd(cmd)

cfg.scfg = secureCfgFromCmd(cmd)
cfg.acfg = authCfgFromCmd(cmd)
Expand All @@ -141,7 +148,7 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
}

func (cc *clientConfig) mustClient() *clientv3.Client {
cfg, err := newClientCfg(cc.endpoints, cc.dialTimeout, cc.keepAliveTime, cc.keepAliveTimeout, cc.scfg, cc.acfg)
cfg, err := newClientCfg(cc.endpoints, cc.dialTimeout, cc.keepAliveTime, cc.keepAliveTimeout, cc.scfg, cc.acfg, cc.maxCallSendMsgSize, cc.maxCallRecvMsgSize)
if err != nil {
ExitWithError(ExitBadArgs, err)
}
Expand All @@ -154,7 +161,7 @@ func (cc *clientConfig) mustClient() *clientv3.Client {
return client
}

func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *secureCfg, acfg *authCfg) (*clientv3.Config, error) {
func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *secureCfg, acfg *authCfg, maxCallSendMsgSize int, maxCallRecvMsgSize int) (*clientv3.Config, error) {
// set tls if any one tls option set
var cfgtls *transport.TLSInfo
tlsinfo := transport.TLSInfo{}
Expand Down Expand Up @@ -183,6 +190,8 @@ func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeo
DialTimeout: dialTimeout,
DialKeepAliveTime: keepAliveTime,
DialKeepAliveTimeout: keepAliveTimeout,
MaxCallSendMsgSize: maxCallSendMsgSize,
MaxCallRecvMsgSize: maxCallRecvMsgSize,
}

if cfgtls != nil {
Expand Down Expand Up @@ -249,6 +258,22 @@ func keepAliveTimeoutFromCmd(cmd *cobra.Command) time.Duration {
return keepAliveTimeout
}

func maxSendBytesFromCmd(cmd *cobra.Command) int {
maxSendBytes, err := cmd.Flags().GetInt("max-send-bytes")
if err != nil {
ExitWithError(ExitError, err)
}
return maxSendBytes
}

func maxRecvBytesFromCmd(cmd *cobra.Command) int {
maxRecvBytes, err := cmd.Flags().GetInt("max-recv-bytes")
if err != nil {
ExitWithError(ExitError, err)
}
return maxRecvBytes
}

func secureCfgFromCmd(cmd *cobra.Command) *secureCfg {
cert, key, cacert := keyAndCertFromCmd(cmd)
insecureTr := insecureTransportFromCmd(cmd)
Expand Down
3 changes: 3 additions & 0 deletions etcdctl/ctlv3/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package ctlv3

import (
"math"
"time"

"github.com/coreos/etcd/etcdctl/ctlv3/command"
Expand Down Expand Up @@ -55,6 +56,8 @@ func init() {
rootCmd.PersistentFlags().DurationVar(&globalFlags.CommandTimeOut, "command-timeout", defaultCommandTimeOut, "timeout for short running command (excluding dial timeout)")
rootCmd.PersistentFlags().DurationVar(&globalFlags.KeepAliveTime, "keepalive-time", defaultKeepAliveTime, "keepalive time for client connections")
rootCmd.PersistentFlags().DurationVar(&globalFlags.KeepAliveTimeout, "keepalive-timeout", defaultKeepAliveTimeOut, "keepalive timeout for client connections")
rootCmd.PersistentFlags().IntVar(&globalFlags.MaxCallSendMsgSize, "max-send-bytes", 1.5*1024*1024, "client-side message send limits in bytes (default value is 1.5 MiB)")
rootCmd.PersistentFlags().IntVar(&globalFlags.MaxCallRecvMsgSize, "max-recv-bytes", math.MaxInt32, "client-side message receive limits in bytes (default value is math.MaxInt32)")

// TODO: secure by default when etcd enables secure gRPC by default.
rootCmd.PersistentFlags().BoolVar(&globalFlags.Insecure, "insecure-transport", true, "disable transport security for client connections")
Expand Down

0 comments on commit 433c3ef

Please sign in to comment.