mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
Add support for conn_max_lifetime (#2270)
This adds support to configure MySQL conn_max_lifetime.
This commit is contained in:
parent
cf4d8ecfee
commit
2ad5205a4b
@ -254,6 +254,19 @@ Maximum idle connections to database. This value should be equal to or less than
|
|||||||
max_idle_conns: 50
|
max_idle_conns: 50
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### `conn_max_lifetime`
|
||||||
|
|
||||||
|
Maximum amount of time, in seconds, a connection may be reused.
|
||||||
|
|
||||||
|
- Default value: 0 (Unlimited)
|
||||||
|
- Environment variable: `KOLIDE_MYSQL_CONN_MAX_LIFETIME`
|
||||||
|
- Config file format:
|
||||||
|
|
||||||
|
```
|
||||||
|
mysql:
|
||||||
|
conn_max_lifetime: 50
|
||||||
|
```
|
||||||
|
|
||||||
#### Redis
|
#### Redis
|
||||||
|
|
||||||
##### `redis_address`
|
##### `redis_address`
|
||||||
|
@ -29,6 +29,7 @@ type MysqlConfig struct {
|
|||||||
TLSConfig string `yaml:"tls_config"` //tls=customValue in DSN
|
TLSConfig string `yaml:"tls_config"` //tls=customValue in DSN
|
||||||
MaxOpenConns int `yaml:"max_open_conns"`
|
MaxOpenConns int `yaml:"max_open_conns"`
|
||||||
MaxIdleConns int `yaml:"max_idle_conns"`
|
MaxIdleConns int `yaml:"max_idle_conns"`
|
||||||
|
ConnMaxLifetime int `yaml:"conn_max_lifetime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RedisConfig defines configs related to Redis
|
// RedisConfig defines configs related to Redis
|
||||||
@ -160,6 +161,7 @@ func (man Manager) addConfigs() {
|
|||||||
"MySQL TLS config value. Use skip-verify, true, false or custom key.")
|
"MySQL TLS config value. Use skip-verify, true, false or custom key.")
|
||||||
man.addConfigInt("mysql.max_open_conns", 50, "MySQL maximum open connection handles.")
|
man.addConfigInt("mysql.max_open_conns", 50, "MySQL maximum open connection handles.")
|
||||||
man.addConfigInt("mysql.max_idle_conns", 50, "MySQL maximum idle connection handles.")
|
man.addConfigInt("mysql.max_idle_conns", 50, "MySQL maximum idle connection handles.")
|
||||||
|
man.addConfigInt("mysql.conn_max_lifetime", 0, "MySQL maximum amount of time a connection may be reused.")
|
||||||
|
|
||||||
// Redis
|
// Redis
|
||||||
man.addConfigString("redis.address", "localhost:6379",
|
man.addConfigString("redis.address", "localhost:6379",
|
||||||
@ -274,6 +276,7 @@ func (man Manager) LoadConfig() KolideConfig {
|
|||||||
TLSConfig: man.getConfigString("mysql.tls_config"),
|
TLSConfig: man.getConfigString("mysql.tls_config"),
|
||||||
MaxOpenConns: man.getConfigInt("mysql.max_open_conns"),
|
MaxOpenConns: man.getConfigInt("mysql.max_open_conns"),
|
||||||
MaxIdleConns: man.getConfigInt("mysql.max_idle_conns"),
|
MaxIdleConns: man.getConfigInt("mysql.max_idle_conns"),
|
||||||
|
ConnMaxLifetime: man.getConfigInt("mysql.conn_max_lifetime"),
|
||||||
},
|
},
|
||||||
Redis: RedisConfig{
|
Redis: RedisConfig{
|
||||||
Address: man.getConfigString("redis.address"),
|
Address: man.getConfigString("redis.address"),
|
||||||
|
@ -117,6 +117,7 @@ func New(config config.MysqlConfig, c clock.Clock, opts ...DBOption) (*Datastore
|
|||||||
|
|
||||||
db.SetMaxIdleConns(config.MaxIdleConns)
|
db.SetMaxIdleConns(config.MaxIdleConns)
|
||||||
db.SetMaxOpenConns(config.MaxOpenConns)
|
db.SetMaxOpenConns(config.MaxOpenConns)
|
||||||
|
db.SetConnMaxLifetime(time.Second * time.Duration(config.ConnMaxLifetime))
|
||||||
|
|
||||||
var dbError error
|
var dbError error
|
||||||
for attempt := 0; attempt < options.maxAttempts; attempt++ {
|
for attempt := 0; attempt < options.maxAttempts; attempt++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user