Skip to content

Commit

Permalink
cacheutil: add support for Redis Sentinel
Browse files Browse the repository at this point in the history
Add a new option `master_name` that if not empty chooses the appropriate
master. Reusing terminology used by Cortex and official Redis
documentation (https://redis.io/docs/management/sentinel/).

Signed-off-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
GiedriusS committed Jan 2, 2023
1 parent b60c09b commit 01a91f9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

## Unreleased

### Added

- [#5990](https://github.com/thanos-io/thanos/pull/5990) Cache/Redis: add support for Redis Sentinel via new option `master_name`.

## [v0.30.0](https://github.com/thanos-io/thanos/tree/release-0.30) - in progress.

### Fixed
Expand Down
1 change: 1 addition & 0 deletions docs/components/query-frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ config:
server_name: ""
insecure_skip_verify: false
cache_size: 0
master_name: ""
expiration: 24h0m0s
```
Expand Down
1 change: 1 addition & 0 deletions docs/components/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ config:
server_name: ""
insecure_skip_verify: false
cache_size: 0
master_name: ""
```

The **required** settings are:
Expand Down
16 changes: 14 additions & 2 deletions pkg/cacheutil/redis_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ type RedisClientConfig struct {
// instead of fetching data each time.
// See https://redis.io/docs/manual/client-side-caching/ for info.
CacheSize model.Bytes `yaml:"cache_size"`

// MasterName specifies the master's name. Must be not empty
// for Redis Sentinel.
MasterName string `yaml:"master_name"`
}

func (c *RedisClientConfig) validate() error {
Expand Down Expand Up @@ -194,7 +198,7 @@ func NewRedisClientWithConfig(logger log.Logger, name string, config RedisClient
clientSideCacheDisabled = true
}

client, err := rueidis.NewClient(rueidis.ClientOption{
clientOpts := rueidis.ClientOption{
InitAddress: strings.Split(config.Addr, ","),
ShuffleInit: true,
Username: config.Username,
Expand All @@ -205,7 +209,15 @@ func NewRedisClientWithConfig(logger log.Logger, name string, config RedisClient
ConnWriteTimeout: config.WriteTimeout,
DisableCache: clientSideCacheDisabled,
TLSConfig: tlsConfig,
})
}

if config.MasterName != "" {
clientOpts.Sentinel = rueidis.SentinelOption{
MasterSet: config.MasterName,
}
}

client, err := rueidis.NewClient(clientOpts)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/queryfrontend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func NewCacheConfig(logger log.Logger, confContentYaml []byte) (*cortexcache.Con
Redis: cortexcache.RedisConfig{
Endpoint: config.Redis.Addr,
Timeout: config.Redis.ReadTimeout,
MasterName: config.Redis.MasterName,
Expiration: config.Expiration,
DB: config.Redis.DB,
PoolSize: config.Redis.PoolSize,
Expand Down

0 comments on commit 01a91f9

Please sign in to comment.