From a05f9bbf220cb75af938619e7451efe03176ae5d Mon Sep 17 00:00:00 2001 From: guscarreon Date: Mon, 7 Nov 2022 17:30:22 -0500 Subject: [PATCH 1/4] Make Aerospike connection idle timeout configurable --- .swp | Bin 0 -> 12288 bytes backends/.aerospike.go.swp | Bin 0 -> 16384 bytes backends/aerospike.go | 7 +++++++ config/backends.go | 31 +++++++++++++++++++------------ config/backends_test.go | 20 +++++++++++++++++++- config/config.go | 1 + 6 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 .swp create mode 100644 backends/.aerospike.go.swp diff --git a/.swp b/.swp new file mode 100644 index 0000000000000000000000000000000000000000..465ad6ef64f6ad84fdef8c41beed3b6c547d3e21 GIT binary patch literal 12288 zcmeI%u};G<5C&iuCKfP%ZhCF4CU&r$s%7B;VdqVlacC<_ zN0x&0TXHT=Y~T6YqVyV%w;gK5i3n}Ky3E_zM2KN3t!1N!rB@v8o|iAz;-t_~vk@g1 z?WlbfUAAI9%ad3Zh30AL;?(483owKL1U4YB(>+g`jVkfU@ev)=yBnwhDIov>2tWV= z5P$##AOL|)3HYKWUPAJ%MFHE3SX+yWAp!&-009U<00Izz00bZa0SG_<0{>7z_J#P^ z72Ull%_b>+y0uX=z1Rwwb2tWV=5P$##An?ZojAk+e@*}2e zw#F4|%%_ghOtJPbv_+X^WcjIN=N;v8%#Q9Y_f(&5WE$%ChI&l0S8Zjg^#e65Et8XB%KQjA WoFNvX6Bd6TcO})&LY7-pTZ&J{Y>7_* literal 0 HcmV?d00001 diff --git a/backends/.aerospike.go.swp b/backends/.aerospike.go.swp new file mode 100644 index 0000000000000000000000000000000000000000..b6609ca30176b02616f1d93887051c7d5c37d86b GIT binary patch literal 16384 zcmeHOU2Gjk6&^}TF(rkAOViw&Uau1;fyBtr_@`i%*p6c-jY4AP?#{j5dhhPl z&aQuIg#^NnP*whRIfP(sfcqm1E2r9fF1Qk*Q5)w$2P-sel@662Z-Rs=A z4(&sQ*2<^5J3BLb&Uen7opW~6*mrX37(eU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|}{I=#iCI@avi_#|Z~RnsyzIX*Ktu{in2)QR~M zRA#f~uqal}l%i5uo!^g?CEu#*!5ec@p^7~od8jmJTRi9C$Y~a2YIz!1 z$gh#i*%FvdxNklSNU-;%3QNCKRw$i7BVACnkLYq`Uc@whV3NMcH6K;Uqq?9)=5h+v zczUZbxz_Pb5~^Q;P%VR}NX8BfSCb?#^)*#PPm@AtG!+tJn3;sIr67|9Z)91_h#g+2~)F#cj&3}2KciU z!>O9lwXN?s9q~Q7{~q2*@jsvwB+!NX=o5-Gx=-C)BsW35n<_HuOy-GaU*$e1|6>fw zBvu8S@X`FW00mWRO5$WY3%BdQn5z3iA#-0UP-xEvW3OrU*Liu6T(7b`P*pOv>#ZnJ t;SpxA#nxCqB~T#mSp_|j{uWjNm8AaHRZur|u6Aq|LB3-3oFWL=e*rgp*!Tbd literal 0 HcmV?d00001 diff --git a/backends/aerospike.go b/backends/aerospike.go index 9b37c4d4..03819b31 100644 --- a/backends/aerospike.go +++ b/backends/aerospike.go @@ -3,6 +3,7 @@ package backends import ( "context" "errors" + "time" as "github.com/aerospike/aerospike-client-go/v6" as_types "github.com/aerospike/aerospike-client-go/v6/types" @@ -61,6 +62,12 @@ func NewAerospikeBackend(cfg config.Aerospike, metrics *metrics.Metrics) *Aerosp clientPolicy.User = cfg.User clientPolicy.Password = cfg.Password + // Aerospike's connection idle deadline default is 55 seconds. If greater than zero, this + // value will override + if cfg.ConnectionIdleTimeout > 0 { + clientPolicy.IdleTimeout = time.Duration(cfg.ConnectionIdleTimeout) * time.Second + } + if len(cfg.Host) > 1 { hosts = append(hosts, as.NewHost(cfg.Host, cfg.Port)) log.Info("config.backend.aerospike.host is being deprecated in favor of config.backend.aerospike.hosts") diff --git a/config/backends.go b/config/backends.go index b7969029..79985b97 100644 --- a/config/backends.go +++ b/config/backends.go @@ -45,15 +45,16 @@ const ( ) type Aerospike struct { - DefaultTTL int `mapstructure:"default_ttl_seconds"` - Host string `mapstructure:"host"` - Hosts []string `mapstructure:"hosts"` - Port int `mapstructure:"port"` - Namespace string `mapstructure:"namespace"` - User string `mapstructure:"user"` - Password string `mapstructure:"password"` - MaxReadRetries int `mapstructure:"max_read_retries"` - MaxWriteRetries int `mapstructure:"max_write_retries"` + DefaultTTL int `mapstructure:"default_ttl_seconds"` + Host string `mapstructure:"host"` + Hosts []string `mapstructure:"hosts"` + Port int `mapstructure:"port"` + Namespace string `mapstructure:"namespace"` + User string `mapstructure:"user"` + Password string `mapstructure:"password"` + MaxReadRetries int `mapstructure:"max_read_retries"` + MaxWriteRetries int `mapstructure:"max_write_retries"` + ConnectionIdleTimeout int `mapstructure:"connection_idle_timeout"` } func (cfg *Aerospike) validateAndLog() error { @@ -64,15 +65,21 @@ func (cfg *Aerospike) validateAndLog() error { if cfg.Port <= 0 { return fmt.Errorf("Cannot connect to Aerospike host at port %d", cfg.Port) } - if cfg.DefaultTTL > 0 { - log.Infof("config.backend.aerospike.default_ttl_seconds: %d. Note that this configuration option is being deprecated in favor of config.request_limits.max_ttl_seconds", cfg.DefaultTTL) - } + log.Infof("config.backend.aerospike.host: %s", cfg.Host) log.Infof("config.backend.aerospike.hosts: %v", cfg.Hosts) log.Infof("config.backend.aerospike.port: %d", cfg.Port) log.Infof("config.backend.aerospike.namespace: %s", cfg.Namespace) log.Infof("config.backend.aerospike.user: %s", cfg.User) + if cfg.DefaultTTL > 0 { + log.Infof("config.backend.aerospike.default_ttl_seconds: %d. Note that this configuration option is being deprecated in favor of config.request_limits.max_ttl_seconds", cfg.DefaultTTL) + } + + if cfg.ConnectionIdleTimeout > 0 { + log.Infof("config.backend.aerospike.connection_idle_timeout: %d. Will substitute Aerospike's default 55 seconds.", cfg.ConnectionIdleTimeout) + } + if cfg.MaxReadRetries < 2 { log.Infof("config.backend.aerospike.max_read_retries value will default to 2") cfg.MaxReadRetries = 2 diff --git a/config/backends_test.go b/config/backends_test.go index 57c1b3ba..bdb26dd2 100644 --- a/config/backends_test.go +++ b/config/backends_test.go @@ -107,12 +107,12 @@ func TestAerospikeValidateAndLog(t *testing.T) { }, hasError: false, logEntries: []logComponents{ - {msg: "config.backend.aerospike.default_ttl_seconds: 3600. Note that this configuration option is being deprecated in favor of config.request_limits.max_ttl_seconds", lvl: logrus.InfoLevel}, {msg: "config.backend.aerospike.host: foo.com", lvl: logrus.InfoLevel}, {msg: fmt.Sprintf("config.backend.aerospike.hosts: %v", []string{"foo.com", "bat.com"}), lvl: logrus.InfoLevel}, {msg: "config.backend.aerospike.port: 8888", lvl: logrus.InfoLevel}, {msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel}, {msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel}, + {msg: "config.backend.aerospike.default_ttl_seconds: 3600. Note that this configuration option is being deprecated in favor of config.request_limits.max_ttl_seconds", lvl: logrus.InfoLevel}, {msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel}, }, }, @@ -186,6 +186,24 @@ func TestAerospikeValidateAndLog(t *testing.T) { {msg: "config.backend.aerospike.max_write_retries: 1.", lvl: logrus.InfoLevel}, }, }, + { + desc: "aerospike.connection_idle_timeout value found in config", + inCfg: Aerospike{ + Host: "foo.com", + Port: 8888, + ConnectionIdleTimeout: 1, + }, + hasError: false, + logEntries: []logComponents{ + {msg: "config.backend.aerospike.host: foo.com", lvl: logrus.InfoLevel}, + {msg: fmt.Sprintf("config.backend.aerospike.hosts: %v", []string{}), lvl: logrus.InfoLevel}, + {msg: "config.backend.aerospike.port: 8888", lvl: logrus.InfoLevel}, + {msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel}, + {msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel}, + {msg: "config.backend.aerospike.connection_idle_timeout: 1. Will substitute Aerospike's default 55 seconds.", lvl: logrus.InfoLevel}, + {msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel}, + }, + }, }, }, { diff --git a/config/config.go b/config/config.go index 9ac095e2..69ac5d46 100644 --- a/config/config.go +++ b/config/config.go @@ -55,6 +55,7 @@ func setConfigDefaults(v *viper.Viper) { v.SetDefault("backend.aerospike.default_ttl_seconds", 0) v.SetDefault("backend.aerospike.max_read_retries", 2) v.SetDefault("backend.aerospike.max_write_retries", 0) + v.SetDefault("backend.aerospike.connection_idle_timeout", 0) v.SetDefault("backend.cassandra.hosts", "") v.SetDefault("backend.cassandra.keyspace", "") v.SetDefault("backend.cassandra.default_ttl_seconds", utils.CASSANDRA_DEFAULT_TTL_SECONDS) From ffa103b1fb08e43e4be0889fe2e9033df678ce39 Mon Sep 17 00:00:00 2001 From: guscarreon Date: Mon, 7 Nov 2022 17:47:41 -0500 Subject: [PATCH 2/4] Removed vim's .swp files --- .swp | Bin 12288 -> 0 bytes backends/.aerospike.go.swp | Bin 16384 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .swp delete mode 100644 backends/.aerospike.go.swp diff --git a/.swp b/.swp deleted file mode 100644 index 465ad6ef64f6ad84fdef8c41beed3b6c547d3e21..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI%u};G<5C&iuCKfP%ZhCF4CU&r$s%7B;VdqVlacC<_ zN0x&0TXHT=Y~T6YqVyV%w;gK5i3n}Ky3E_zM2KN3t!1N!rB@v8o|iAz;-t_~vk@g1 z?WlbfUAAI9%ad3Zh30AL;?(483owKL1U4YB(>+g`jVkfU@ev)=yBnwhDIov>2tWV= z5P$##AOL|)3HYKWUPAJ%MFHE3SX+yWAp!&-009U<00Izz00bZa0SG_<0{>7z_J#P^ z72Ull%_b>+y0uX=z1Rwwb2tWV=5P$##An?ZojAk+e@*}2e zw#F4|%%_ghOtJPbv_+X^WcjIN=N;v8%#Q9Y_f(&5WE$%ChI&l0S8Zjg^#e65Et8XB%KQjA WoFNvX6Bd6TcO})&LY7-pTZ&J{Y>7_* diff --git a/backends/.aerospike.go.swp b/backends/.aerospike.go.swp deleted file mode 100644 index b6609ca30176b02616f1d93887051c7d5c37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p9X#aTmmivi@-Fn8>j$x1Aj&C{ukiSz%PIw z1DAk{zy;tOFb&)d+y(3e{)N2$I`9(kE#L_7Jo5SP0#5)-fCN0?LEt{%I`a760KW#V z08auPpbZ4Tr-5_8S-=6_4=~^=a{aFX=YZ3|9l&p)^A+GZ;91~lfOxnJlz$}yB?Bb` zB?Bb`B?E6r2D-@`wmhc1f~EmoCK|}{I=#iCI@avi_#|Z~RnsyzIX*Ktu{in2)QR~M zRA#f~uqal}l%i5uo!^g?CEu#*!5ec@p^7~od8jmJTRi9C$Y~a2YIz!1 z$gh#i*%FvdxNklSNU-;%3QNCKRw$i7BVACnkLYq`Uc@whV3NMcH6K;Uqq?9)=5h+v zczUZbxz_Pb5~^Q;P%VR}NX8BfSCb?#^)*#PPm@AtG!+tJn3;sIr67|9Z)91_h#g+2~)F#cj&3}2KciU z!>O9lwXN?s9q~Q7{~q2*@jsvwB+!NX=o5-Gx=-C)BsW35n<_HuOy-GaU*$e1|6>fw zBvu8S@X`FW00mWRO5$WY3%BdQn5z3iA#-0UP-xEvW3OrU*Liu6T(7b`P*pOv>#ZnJ t;SpxA#nxCqB~T#mSp_|j{uWjNm8AaHRZur|u6Aq|LB3-3oFWL=e*rgp*!Tbd From 4ee257d8f57260a0a54017477f4e3be464f1eff5 Mon Sep 17 00:00:00 2001 From: guscarreon Date: Tue, 8 Nov 2022 14:43:48 -0500 Subject: [PATCH 3/4] Mansi's review --- config/backends.go | 27 ++++++++++++++++----------- config/backends_test.go | 4 ++-- config/config.go | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/config/backends.go b/config/backends.go index 79985b97..a137d9b8 100644 --- a/config/backends.go +++ b/config/backends.go @@ -45,16 +45,21 @@ const ( ) type Aerospike struct { - DefaultTTL int `mapstructure:"default_ttl_seconds"` - Host string `mapstructure:"host"` - Hosts []string `mapstructure:"hosts"` - Port int `mapstructure:"port"` - Namespace string `mapstructure:"namespace"` - User string `mapstructure:"user"` - Password string `mapstructure:"password"` - MaxReadRetries int `mapstructure:"max_read_retries"` - MaxWriteRetries int `mapstructure:"max_write_retries"` - ConnectionIdleTimeout int `mapstructure:"connection_idle_timeout"` + DefaultTTL int `mapstructure:"default_ttl_seconds"` + Host string `mapstructure:"host"` + Hosts []string `mapstructure:"hosts"` + Port int `mapstructure:"port"` + Namespace string `mapstructure:"namespace"` + User string `mapstructure:"user"` + Password string `mapstructure:"password"` + MaxReadRetries int `mapstructure:"max_read_retries"` + MaxWriteRetries int `mapstructure:"max_write_retries"` + // Please set this to a value lower than the `proto-fd-idle-ms` (converted + // to seconds) value set in your Aerospike Server. This is to avoid having + // race conditions where the server closes the connection but the client still + // tries to use it. If set to a value less than or equal to 0, Aerospike + // Client's default value will be used which is 55 seconds. + ConnectionIdleTimeout int `mapstructure:"connection_idle_timeout_seconds"` } func (cfg *Aerospike) validateAndLog() error { @@ -77,7 +82,7 @@ func (cfg *Aerospike) validateAndLog() error { } if cfg.ConnectionIdleTimeout > 0 { - log.Infof("config.backend.aerospike.connection_idle_timeout: %d. Will substitute Aerospike's default 55 seconds.", cfg.ConnectionIdleTimeout) + log.Infof("config.backend.aerospike.connection_idle_timeout_seconds: %d.", cfg.ConnectionIdleTimeout) } if cfg.MaxReadRetries < 2 { diff --git a/config/backends_test.go b/config/backends_test.go index bdb26dd2..0646b5e9 100644 --- a/config/backends_test.go +++ b/config/backends_test.go @@ -187,7 +187,7 @@ func TestAerospikeValidateAndLog(t *testing.T) { }, }, { - desc: "aerospike.connection_idle_timeout value found in config", + desc: "aerospike.connection_idle_timeout_seconds value found in config", inCfg: Aerospike{ Host: "foo.com", Port: 8888, @@ -200,7 +200,7 @@ func TestAerospikeValidateAndLog(t *testing.T) { {msg: "config.backend.aerospike.port: 8888", lvl: logrus.InfoLevel}, {msg: "config.backend.aerospike.namespace: ", lvl: logrus.InfoLevel}, {msg: "config.backend.aerospike.user: ", lvl: logrus.InfoLevel}, - {msg: "config.backend.aerospike.connection_idle_timeout: 1. Will substitute Aerospike's default 55 seconds.", lvl: logrus.InfoLevel}, + {msg: "config.backend.aerospike.connection_idle_timeout_seconds: 1.", lvl: logrus.InfoLevel}, {msg: "config.backend.aerospike.max_read_retries value will default to 2", lvl: logrus.InfoLevel}, }, }, diff --git a/config/config.go b/config/config.go index 69ac5d46..95d64a76 100644 --- a/config/config.go +++ b/config/config.go @@ -55,7 +55,7 @@ func setConfigDefaults(v *viper.Viper) { v.SetDefault("backend.aerospike.default_ttl_seconds", 0) v.SetDefault("backend.aerospike.max_read_retries", 2) v.SetDefault("backend.aerospike.max_write_retries", 0) - v.SetDefault("backend.aerospike.connection_idle_timeout", 0) + v.SetDefault("backend.aerospike.connection_idle_timeout_seconds", 0) v.SetDefault("backend.cassandra.hosts", "") v.SetDefault("backend.cassandra.keyspace", "") v.SetDefault("backend.cassandra.default_ttl_seconds", utils.CASSANDRA_DEFAULT_TTL_SECONDS) From 97b500678f655d86954cbafbe22d770d75bf0806 Mon Sep 17 00:00:00 2001 From: guscarreon Date: Wed, 9 Nov 2022 14:39:28 -0500 Subject: [PATCH 4/4] Renamed to DefaultTTLSecs and ConnIdleTimeoutSecs --- backends/aerospike.go | 4 ++-- backends/config/config.go | 4 ++-- backends/config/config_test.go | 6 +++--- config/backends.go | 12 ++++++------ config/backends_test.go | 14 +++++++------- config/config_test.go | 17 +++++++++-------- config/configtest/sample_full_config.yaml | 1 + 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/backends/aerospike.go b/backends/aerospike.go index 03819b31..00468459 100644 --- a/backends/aerospike.go +++ b/backends/aerospike.go @@ -64,8 +64,8 @@ func NewAerospikeBackend(cfg config.Aerospike, metrics *metrics.Metrics) *Aerosp // Aerospike's connection idle deadline default is 55 seconds. If greater than zero, this // value will override - if cfg.ConnectionIdleTimeout > 0 { - clientPolicy.IdleTimeout = time.Duration(cfg.ConnectionIdleTimeout) * time.Second + if cfg.ConnIdleTimeoutSecs > 0 { + clientPolicy.IdleTimeout = time.Duration(cfg.ConnIdleTimeoutSecs) * time.Second } if len(cfg.Host) > 1 { diff --git a/backends/config/config.go b/backends/config/config.go index 7d9cf47d..8bcf20bd 100644 --- a/backends/config/config.go +++ b/backends/config/config.go @@ -84,8 +84,8 @@ func getMaxTTLSeconds(cfg config.Configuration) int { case config.BackendAerospike: // If both config.request_limits.max_ttl_seconds and config.backend.aerospike.default_ttl_seconds // were defined, the smallest value takes preference - if cfg.Backend.Aerospike.DefaultTTL > 0 && maxTTLSeconds > cfg.Backend.Aerospike.DefaultTTL { - maxTTLSeconds = cfg.Backend.Aerospike.DefaultTTL + if cfg.Backend.Aerospike.DefaultTTLSecs > 0 && maxTTLSeconds > cfg.Backend.Aerospike.DefaultTTLSecs { + maxTTLSeconds = cfg.Backend.Aerospike.DefaultTTLSecs } case config.BackendRedis: // If both config.request_limits.max_ttl_seconds and backend.redis.expiration diff --git a/backends/config/config_test.go b/backends/config/config_test.go index bab2f919..e058bb7a 100644 --- a/backends/config/config_test.go +++ b/backends/config/config_test.go @@ -233,7 +233,7 @@ func TestGetMaxTTLSeconds(t *testing.T) { Backend: config.Backend{ Type: config.BackendAerospike, Aerospike: config.Aerospike{ - DefaultTTL: 0, + DefaultTTLSecs: 0, }, }, RequestLimits: config.RequestLimits{ @@ -248,7 +248,7 @@ func TestGetMaxTTLSeconds(t *testing.T) { Backend: config.Backend{ Type: config.BackendAerospike, Aerospike: config.Aerospike{ - DefaultTTL: 100, + DefaultTTLSecs: 100, }, }, RequestLimits: config.RequestLimits{ @@ -263,7 +263,7 @@ func TestGetMaxTTLSeconds(t *testing.T) { Backend: config.Backend{ Type: config.BackendAerospike, Aerospike: config.Aerospike{ - DefaultTTL: 1, + DefaultTTLSecs: 1, }, }, RequestLimits: config.RequestLimits{ diff --git a/config/backends.go b/config/backends.go index a137d9b8..93718976 100644 --- a/config/backends.go +++ b/config/backends.go @@ -45,7 +45,7 @@ const ( ) type Aerospike struct { - DefaultTTL int `mapstructure:"default_ttl_seconds"` + DefaultTTLSecs int `mapstructure:"default_ttl_seconds"` Host string `mapstructure:"host"` Hosts []string `mapstructure:"hosts"` Port int `mapstructure:"port"` @@ -59,7 +59,7 @@ type Aerospike struct { // race conditions where the server closes the connection but the client still // tries to use it. If set to a value less than or equal to 0, Aerospike // Client's default value will be used which is 55 seconds. - ConnectionIdleTimeout int `mapstructure:"connection_idle_timeout_seconds"` + ConnIdleTimeoutSecs int `mapstructure:"connection_idle_timeout_seconds"` } func (cfg *Aerospike) validateAndLog() error { @@ -77,12 +77,12 @@ func (cfg *Aerospike) validateAndLog() error { log.Infof("config.backend.aerospike.namespace: %s", cfg.Namespace) log.Infof("config.backend.aerospike.user: %s", cfg.User) - if cfg.DefaultTTL > 0 { - log.Infof("config.backend.aerospike.default_ttl_seconds: %d. Note that this configuration option is being deprecated in favor of config.request_limits.max_ttl_seconds", cfg.DefaultTTL) + if cfg.DefaultTTLSecs > 0 { + log.Infof("config.backend.aerospike.default_ttl_seconds: %d. Note that this configuration option is being deprecated in favor of config.request_limits.max_ttl_seconds", cfg.DefaultTTLSecs) } - if cfg.ConnectionIdleTimeout > 0 { - log.Infof("config.backend.aerospike.connection_idle_timeout_seconds: %d.", cfg.ConnectionIdleTimeout) + if cfg.ConnIdleTimeoutSecs > 0 { + log.Infof("config.backend.aerospike.connection_idle_timeout_seconds: %d.", cfg.ConnIdleTimeoutSecs) } if cfg.MaxReadRetries < 2 { diff --git a/config/backends_test.go b/config/backends_test.go index 0646b5e9..fe8b4bf4 100644 --- a/config/backends_test.go +++ b/config/backends_test.go @@ -100,10 +100,10 @@ func TestAerospikeValidateAndLog(t *testing.T) { { desc: "both aerospike.host, aerospike.hosts and aerospike.default_ttl_seconds set", inCfg: Aerospike{ - Host: "foo.com", - Hosts: []string{"foo.com", "bat.com"}, - Port: 8888, - DefaultTTL: 3600, + Host: "foo.com", + Hosts: []string{"foo.com", "bat.com"}, + Port: 8888, + DefaultTTLSecs: 3600, }, hasError: false, logEntries: []logComponents{ @@ -189,9 +189,9 @@ func TestAerospikeValidateAndLog(t *testing.T) { { desc: "aerospike.connection_idle_timeout_seconds value found in config", inCfg: Aerospike{ - Host: "foo.com", - Port: 8888, - ConnectionIdleTimeout: 1, + Host: "foo.com", + Port: 8888, + ConnIdleTimeoutSecs: 1, }, hasError: false, logEntries: []logComponents{ diff --git a/config/config_test.go b/config/config_test.go index d8b9c77f..28578b68 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1245,14 +1245,15 @@ func getExpectedFullConfigForTestFile() Configuration { Backend: Backend{ Type: BackendMemory, Aerospike: Aerospike{ - DefaultTTL: 3600, - Host: "aerospike.prebid.com", - Hosts: []string{"aerospike2.prebid.com", "aerospike3.prebid.com"}, - Port: 3000, - Namespace: "whatever", - User: "foo", - Password: "bar", - MaxReadRetries: 2, + DefaultTTLSecs: 3600, + Host: "aerospike.prebid.com", + Hosts: []string{"aerospike2.prebid.com", "aerospike3.prebid.com"}, + Port: 3000, + Namespace: "whatever", + User: "foo", + Password: "bar", + MaxReadRetries: 2, + ConnIdleTimeoutSecs: 2, }, Cassandra: Cassandra{ Hosts: "127.0.0.1", diff --git a/config/configtest/sample_full_config.yaml b/config/configtest/sample_full_config.yaml index 0f1454ee..6c298d59 100644 --- a/config/configtest/sample_full_config.yaml +++ b/config/configtest/sample_full_config.yaml @@ -21,6 +21,7 @@ backend: namespace: "whatever" user: "foo" password: "bar" + connection_idle_timeout_seconds: 2 cassandra: hosts: "127.0.0.1" keyspace: "prebid"