Skip to content

Commit

Permalink
Add SentinelPassword configuration for Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
zalegrala committed Jun 1, 2022
1 parent 382f8eb commit a17804c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [CHANGE] metrics-generator: Changed added metric label `instance` to `__metrics_gen_instance` to reduce collisions with custom dimensions. [#1439](https://github.com/grafana/tempo/pull/1439) (@joe-elliott)
* [CHANGE] Don't enforce `max_bytes_per_tag_values_query` when set to 0. [#1447](https://github.com/grafana/tempo/pull/1447) (@joe-elliott)
* [FEATURE] metrics-generator: support per-tenant processor configuration [#1434](https://github.com/grafana/tempo/pull/1434) (@kvrhdn)
* [FEATURE] Add SentinelPassword configuration for Redis [#1463](https://github.com/grafana/tempo/pull/1463) (@zalegrala)
* [ENHANCEMENT] Added the ability to have a per tenant max search duration. [#1421](https://github.com/grafana/tempo/pull/1421) (@joe-elliott)
* [BUGFIX] Fix nil pointer panic when the trace by id path errors. [#1441](https://github.com/grafana/tempo/pull/1441) (@joe-elliott)

Expand Down
4 changes: 4 additions & 0 deletions docs/tempo/website/configuration/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ storage:
# close connections older than this duration. (default 0s)
[max-connection-age: <duration>]

# optional.
# password to use when connecting to redis sentinel. (default "")
[sentinel_password: <string>]

# the worker pool is used primarily when finding traces by id, but is also used by other
pool:

Expand Down
17 changes: 10 additions & 7 deletions pkg/cache/redis_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type RedisConfig struct {
DB int `yaml:"db"`
PoolSize int `yaml:"pool_size"`
Password flagext.Secret `yaml:"password"`
SentinelPassword flagext.Secret `yaml:"sentinel_password"`
EnableTLS bool `yaml:"tls_enabled"`
InsecureSkipVerify bool `yaml:"tls_insecure_skip_verify"`
IdleTimeout time.Duration `yaml:"idle_timeout"`
Expand All @@ -38,6 +39,7 @@ func (cfg *RedisConfig) RegisterFlagsWithPrefix(prefix, description string, f *f
f.IntVar(&cfg.DB, prefix+"redis.db", 0, description+"Database index.")
f.IntVar(&cfg.PoolSize, prefix+"redis.pool-size", 0, description+"Maximum number of connections in the pool.")
f.Var(&cfg.Password, prefix+"redis.password", description+"Password to use when connecting to redis.")
f.Var(&cfg.SentinelPassword, prefix+"redis.sentinel-password", description+"Password to use when connecting to redis sentinel.")
f.BoolVar(&cfg.EnableTLS, prefix+"redis.tls-enabled", false, description+"Enable connecting to redis with TLS.")
f.BoolVar(&cfg.InsecureSkipVerify, prefix+"redis.tls-insecure-skip-verify", false, description+"Skip validating server certificate.")
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.")
Expand All @@ -53,13 +55,14 @@ type RedisClient struct {
// NewRedisClient creates Redis client
func NewRedisClient(cfg *RedisConfig) *RedisClient {
opt := &redis.UniversalOptions{
Addrs: strings.Split(cfg.Endpoint, ","),
MasterName: cfg.MasterName,
Password: cfg.Password.String(),
DB: cfg.DB,
PoolSize: cfg.PoolSize,
IdleTimeout: cfg.IdleTimeout,
MaxConnAge: cfg.MaxConnAge,
Addrs: strings.Split(cfg.Endpoint, ","),
MasterName: cfg.MasterName,
Password: cfg.Password.String(),
SentinelPassword: cfg.SentinelPassword.String(),
DB: cfg.DB,
PoolSize: cfg.PoolSize,
IdleTimeout: cfg.IdleTimeout,
MaxConnAge: cfg.MaxConnAge,
}
if cfg.EnableTLS {
opt.TLSConfig = &tls.Config{InsecureSkipVerify: cfg.InsecureSkipVerify}
Expand Down
43 changes: 24 additions & 19 deletions pkg/cache/redis_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package cache

import (
"context"
"strings"
"testing"
"time"

"github.com/alicebob/miniredis/v2"
"github.com/go-redis/redis/v8"
miniredis "github.com/alicebob/miniredis/v2"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -69,32 +69,37 @@ func mockRedisClientSingle() (*RedisClient, error) {
if err != nil {
return nil, err
}
return &RedisClient{
expiration: time.Minute,
timeout: 100 * time.Millisecond,
rdb: redis.NewClient(&redis.Options{
Addr: redisServer.Addr(),
}),
}, nil

cfg := &RedisConfig{
Expiration: time.Minute,
Timeout: 100 * time.Millisecond,
Endpoint: strings.Join([]string{
redisServer.Addr(),
}, ","),
}

return NewRedisClient(cfg), nil
}

func mockRedisClientCluster() (*RedisClient, error) {
redisServer1, err := miniredis.Run()
if err != nil {
return nil, err
}

redisServer2, err := miniredis.Run()
if err != nil {
return nil, err
}
return &RedisClient{
expiration: time.Minute,
timeout: 100 * time.Millisecond,
rdb: redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{
redisServer1.Addr(),
redisServer2.Addr(),
},
}),
}, nil

cfg := &RedisConfig{
Expiration: time.Minute,
Timeout: 100 * time.Millisecond,
Endpoint: strings.Join([]string{
redisServer1.Addr(),
redisServer2.Addr(),
}, ","),
}

return NewRedisClient(cfg), nil
}

0 comments on commit a17804c

Please sign in to comment.