Skip to content

Commit

Permalink
cacheutil: adding 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 <giedrius.statkevicius@vinted.com>
  • Loading branch information
GiedriusS committed Dec 21, 2022
1 parent e85bc1f commit e64a749
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#5889](https://github.com/thanos-io/thanos/pull/5889) Query Frontend: Support sharding vertical sharding `label_replace` and `label_join` functions.
- [#5819](https://github.com/thanos-io/thanos/pull/5819) Store: Add a few objectives for Store's data touched/fetched amount and sizes. They are: 50, 95, and 99 quantiles.
- [#5940](https://github.com/thanos-io/thanos/pull/5940) Objstore: Support for authenticating to Swift using application credentials.
- [#5990](https://github.com/thanos-io/thanos/pull/5990) Cache/Redis: add support for Redis Sentinel via new option `master_name`.

### Changed

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

0 comments on commit e64a749

Please sign in to comment.