Added socket keep alive option to Cassandra plugin. (#6201)

This commit is contained in:
Andrej van der Zee 2019-02-11 00:34:50 +01:00 committed by Jeff Mitchell
parent e0e4ec1cac
commit 604e8dd0f0
2 changed files with 31 additions and 17 deletions

View File

@ -30,12 +30,14 @@ type cassandraConnectionProducer struct {
InsecureTLS bool `json:"insecure_tls" structs:"insecure_tls" mapstructure:"insecure_tls"`
ProtocolVersion int `json:"protocol_version" structs:"protocol_version" mapstructure:"protocol_version"`
ConnectTimeoutRaw interface{} `json:"connect_timeout" structs:"connect_timeout" mapstructure:"connect_timeout"`
SocketKeepAliveRaw interface{} `json:"socket_keep_alive" structs:"socket_keep_alive" mapstructure:"socket_keep_alive"`
TLSMinVersion string `json:"tls_min_version" structs:"tls_min_version" mapstructure:"tls_min_version"`
Consistency string `json:"consistency" structs:"consistency" mapstructure:"consistency"`
PemBundle string `json:"pem_bundle" structs:"pem_bundle" mapstructure:"pem_bundle"`
PemJSON string `json:"pem_json" structs:"pem_json" mapstructure:"pem_json"`
connectTimeout time.Duration
socketKeepAlive time.Duration
certificate string
privateKey string
issuingCA string
@ -71,6 +73,14 @@ func (c *cassandraConnectionProducer) Init(ctx context.Context, conf map[string]
return nil, errwrap.Wrapf("invalid connect_timeout: {{err}}", err)
}
if c.SocketKeepAliveRaw == nil {
c.SocketKeepAliveRaw = "0s"
}
c.socketKeepAlive, err = parseutil.ParseDurationSecond(c.SocketKeepAliveRaw)
if err != nil {
return nil, errwrap.Wrapf("invalid socket_keep_alive: {{err}}", err)
}
switch {
case len(c.Hosts) == 0:
return nil, fmt.Errorf("hosts cannot be empty")
@ -178,6 +188,7 @@ func (c *cassandraConnectionProducer) createSession() (*gocql.Session, error) {
}
clusterConfig.Timeout = c.connectTimeout
clusterConfig.SocketKeepalive = c.socketKeepAlive
if c.TLS {
var tlsConfig *tls.Config
if len(c.certificate) > 0 || len(c.issuingCA) > 0 {

View File

@ -56,6 +56,9 @@ has a number of parameters to further configure a connection.
- `connect_timeout` `(string: "5s")` Specifies the connection timeout to use.
- `socket_keep_alive` `(string: "0s")` the keep-alive period for an active
network connection. If zero, keep-alives are not enabled.
TLS works as follows:
- If `tls` is set to true, the connection will use TLS; this happens