Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Cassandra reconnect interval #934

Merged
Merged
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
5 changes: 5 additions & 0 deletions pkg/cassandra/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Configuration struct {
Keyspace string `validate:"nonzero"`
ConnectionsPerHost int `validate:"min=1" yaml:"connections_per_host"`
Timeout time.Duration `validate:"min=500"`
ReconnectInterval time.Duration `validate:"min=500" yaml:"reconnect_interval"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that the minimum of 500ns is a good value. Could you elaborate on how this was chosen?

(I think we need to revisit the Timeout as well separately)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I really understand the validate:"min=500" section. It seems that it wasn't actually enforced in my tests. (As in, I would not pass any value, resulting in 0, which is less than 500 and it would pass validation. Unless that's a special case?)

I copied Timeout value for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, it looks like these validations would only be applied if this configuration file was validated with something like https://github.com/go-validator/validator

I'll make a separate ticket to address this

SocketKeepAlive time.Duration `validate:"min=0" yaml:"socket_keep_alive"`
MaxRetryAttempts int `validate:"min=0" yaml:"max_retry_attempt"`
ProtoVersion int `yaml:"proto_version"`
Expand Down Expand Up @@ -74,6 +75,9 @@ func (c *Configuration) ApplyDefaults(source *Configuration) {
if c.Timeout == 0 {
c.Timeout = source.Timeout
}
if c.ReconnectInterval == 0 {
c.ReconnectInterval = source.ReconnectInterval
}
if c.Port == 0 {
c.Port = source.Port
}
Expand Down Expand Up @@ -109,6 +113,7 @@ func (c *Configuration) NewCluster() *gocql.ClusterConfig {
cluster.Keyspace = c.Keyspace
cluster.NumConns = c.ConnectionsPerHost
cluster.Timeout = c.Timeout
cluster.ReconnectInterval = c.ReconnectInterval
cluster.SocketKeepalive = c.SocketKeepAlive
if c.ProtoVersion > 0 {
cluster.ProtoVersion = c.ProtoVersion
Expand Down
43 changes: 25 additions & 18 deletions plugin/storage/cassandra/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,25 @@ import (

const (
// session settings
suffixEnabled = ".enabled"
suffixConnPerHost = ".connections-per-host"
suffixMaxRetryAttempts = ".max-retry-attempts"
suffixTimeout = ".timeout"
suffixServers = ".servers"
suffixPort = ".port"
suffixKeyspace = ".keyspace"
suffixConsistency = ".consistency"
suffixProtoVer = ".proto-version"
suffixSocketKeepAlive = ".socket-keep-alive"
suffixUsername = ".username"
suffixPassword = ".password"
suffixTLS = ".tls"
suffixCert = ".tls.cert"
suffixKey = ".tls.key"
suffixCA = ".tls.ca"
suffixServerName = ".tls.server-name"
suffixVerifyHost = ".tls.verify-host"
suffixEnabled = ".enabled"
suffixConnPerHost = ".connections-per-host"
suffixMaxRetryAttempts = ".max-retry-attempts"
suffixTimeout = ".timeout"
suffixReconnectInterval = ".reconnect-interval"
suffixServers = ".servers"
suffixPort = ".port"
suffixKeyspace = ".keyspace"
suffixConsistency = ".consistency"
suffixProtoVer = ".proto-version"
suffixSocketKeepAlive = ".socket-keep-alive"
suffixUsername = ".username"
suffixPassword = ".password"
suffixTLS = ".tls"
suffixCert = ".tls.cert"
suffixKey = ".tls.key"
suffixCA = ".tls.ca"
suffixServerName = ".tls.server-name"
suffixVerifyHost = ".tls.verify-host"

// common storage settings
suffixSpanStoreWriteCacheTTL = ".span-store-write-cache-ttl"
Expand Down Expand Up @@ -83,6 +84,7 @@ func NewOptions(primaryNamespace string, otherNamespaces ...string) *Options {
Keyspace: "jaeger_v1_test",
ProtoVersion: 4,
ConnectionsPerHost: 2,
ReconnectInterval: 60 * time.Second,
},
servers: "127.0.0.1",
namespace: primaryNamespace,
Expand Down Expand Up @@ -130,6 +132,10 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
nsConfig.namespace+suffixTimeout,
nsConfig.Timeout,
"Timeout used for queries")
flagSet.Duration(
nsConfig.namespace+suffixReconnectInterval,
nsConfig.ReconnectInterval,
"Reconnect interval to retry connecting to downed hosts")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: what would be the behavior if this is set to 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current (master) jaeger behavior is equivalent to setting to 0. If hosts are marked as down, gocql will not try to reconnect without this set.

flagSet.String(
nsConfig.namespace+suffixServers,
nsConfig.servers,
Expand Down Expand Up @@ -204,6 +210,7 @@ func (cfg *namespaceConfig) initFromViper(v *viper.Viper) {
cfg.ConnectionsPerHost = v.GetInt(cfg.namespace + suffixConnPerHost)
cfg.MaxRetryAttempts = v.GetInt(cfg.namespace + suffixMaxRetryAttempts)
cfg.Timeout = v.GetDuration(cfg.namespace + suffixTimeout)
cfg.ReconnectInterval = v.GetDuration(cfg.namespace + suffixReconnectInterval)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test

cfg.servers = v.GetString(cfg.namespace + suffixServers)
cfg.Port = v.GetInt(cfg.namespace + suffixPort)
cfg.Keyspace = v.GetString(cfg.namespace + suffixKeyspace)
Expand Down
3 changes: 3 additions & 0 deletions plugin/storage/cassandra/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestOptions(t *testing.T) {
assert.Equal(t, primary.Keyspace, aux.Keyspace)
assert.Equal(t, primary.Servers, aux.Servers)
assert.Equal(t, primary.ConnectionsPerHost, aux.ConnectionsPerHost)
assert.Equal(t, primary.ReconnectInterval, aux.ReconnectInterval)
}

func TestOptionsWithFlags(t *testing.T) {
Expand All @@ -50,6 +51,7 @@ func TestOptionsWithFlags(t *testing.T) {
"--cas.keyspace=jaeger",
"--cas.servers=1.1.1.1,2.2.2.2",
"--cas.connections-per-host=42",
"--cas.reconnect-interval=42s",
"--cas.max-retry-attempts=42",
"--cas.timeout=42s",
"--cas.port=4242",
Expand All @@ -75,6 +77,7 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, 42, aux.ConnectionsPerHost)
assert.Equal(t, 42, aux.MaxRetryAttempts)
assert.Equal(t, 42*time.Second, aux.Timeout)
assert.Equal(t, 42*time.Second, aux.ReconnectInterval)
assert.Equal(t, 4242, aux.Port)
assert.Equal(t, "", aux.Consistency, "aux storage does not inherit consistency from primary")
assert.Equal(t, 3, aux.ProtoVersion)
Expand Down