Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* [ENHANCEMENT] Add de-duplicated chunks counter `cortex_chunk_store_deduped_chunks_total` which counts every chunk not sent to the store because it was already sent by another replica. #2485
* [ENHANCEMENT] query-frontend now also logs the POST data of long queries. #2481
* [ENHANCEMENT] Experimental WAL: Ingester WAL records now have type header and the custom WAL records have been replaced by Prometheus TSDB's WAL records. Old records will not be supported from 1.3 onwards. Note: once this is deployed, you cannot downgrade without data loss. #2436
* [ENHANCEMENT] Redis Cache: Added `idle_timeout`, `wait_on_pool_exhaustion` and `max_conn_lifetime` options to redis cache configuration. #2550
* [BUGFIX] Ruler: Ensure temporary rule files with special characters are properly mapped and cleaned up. #2506
* [BUGFIX] Fixes #2411, Ensure requests are properly routed to the prometheus api embedded in the query if `-server.path-prefix` is set. #2372
* [BUGFIX] Experimental TSDB: fixed chunk data corruption when querying back series using the experimental blocks storage. #2400
Expand Down
16 changes: 16 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,22 @@ The `redis_config` configures the Redis backend cache. The supported CLI flags `
# Enables connecting to redis with TLS.
# CLI flag: -<prefix>.redis.enable-tls
[enable_tls: <boolean> | default = false]

# Close connections after remaining idle for this duration. If the value is
# zero, then idle connections are not closed.
# CLI flag: -<prefix>.redis.idle-timeout
[idle_timeout: <duration> | default = 0s]

# Enables waiting if there are no idle connections. If the value is false and
# the pool is at the max_active_conns limit, the pool will return a connection
# with ErrPoolExhausted error and not wait for idle connections.
# CLI flag: -<prefix>.redis.wait-on-pool-exhaustion
[wait_on_pool_exhaustion: <boolean> | default = false]

# Close connections older than this duration. If the value is zero, then the
# pool does not close connections based on age.
# CLI flag: -<prefix>.redis.max-conn-lifetime
[max_conn_lifetime: <duration> | default = 0s]
```

### `memcached_config`
Expand Down
27 changes: 18 additions & 9 deletions pkg/chunk/cache/redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ type RedisCache struct {

// RedisConfig defines how a RedisCache should be constructed.
type RedisConfig struct {
Endpoint string `yaml:"endpoint"`
Timeout time.Duration `yaml:"timeout"`
Expiration time.Duration `yaml:"expiration"`
MaxIdleConns int `yaml:"max_idle_conns"`
MaxActiveConns int `yaml:"max_active_conns"`
Password flagext.Secret `yaml:"password"`
EnableTLS bool `yaml:"enable_tls"`
Endpoint string `yaml:"endpoint"`
Timeout time.Duration `yaml:"timeout"`
Expiration time.Duration `yaml:"expiration"`
MaxIdleConns int `yaml:"max_idle_conns"`
MaxActiveConns int `yaml:"max_active_conns"`
Password flagext.Secret `yaml:"password"`
EnableTLS bool `yaml:"enable_tls"`
IdleTimeout time.Duration `yaml:"idle_timeout"`
WaitOnPoolExhaustion bool `yaml:"wait_on_pool_exhaustion"`
MaxConnLifetime time.Duration `yaml:"max_conn_lifetime"`
}

// RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
Expand All @@ -40,6 +43,9 @@ func (cfg *RedisConfig) RegisterFlagsWithPrefix(prefix, description string, f *f
f.IntVar(&cfg.MaxActiveConns, prefix+"redis.max-active-conns", 0, description+"Maximum number of active connections in pool.")
f.Var(&cfg.Password, prefix+"redis.password", description+"Password to use when connecting to redis.")
f.BoolVar(&cfg.EnableTLS, prefix+"redis.enable-tls", false, description+"Enables connecting to redis with TLS.")
f.DurationVar(&cfg.IdleTimeout, prefix+"redis.idle-timeout", 0, description+"Close connections after remaining idle for this duration. If the value is zero, then idle connections are not closed.")
f.BoolVar(&cfg.WaitOnPoolExhaustion, prefix+"redis.wait-on-pool-exhaustion", false, description+"Enables waiting if there are no idle connections. If the value is false and the pool is at the max_active_conns limit, the pool will return a connection with ErrPoolExhausted error and not wait for idle connections.")
f.DurationVar(&cfg.MaxConnLifetime, prefix+"redis.max-conn-lifetime", 0, description+"Close connections older than this duration. If the value is zero, then the pool does not close connections based on age.")
}

// NewRedisCache creates a new RedisCache
Expand All @@ -48,8 +54,6 @@ func NewRedisCache(cfg RedisConfig, name string, pool *redis.Pool) *RedisCache {
// pool != nil only in unit tests
if pool == nil {
pool = &redis.Pool{
MaxIdle: cfg.MaxIdleConns,
MaxActive: cfg.MaxActiveConns,
Dial: func() (redis.Conn, error) {
options := make([]redis.DialOption, 0, 2)
if cfg.EnableTLS {
Expand All @@ -65,6 +69,11 @@ func NewRedisCache(cfg RedisConfig, name string, pool *redis.Pool) *RedisCache {
}
return c, err
},
MaxIdle: cfg.MaxIdleConns,
MaxActive: cfg.MaxActiveConns,
IdleTimeout: cfg.IdleTimeout,
Wait: cfg.WaitOnPoolExhaustion,
MaxConnLifetime: cfg.MaxConnLifetime,
}
}

Expand Down