Skip to content

Commit 7127724

Browse files
authored
Merge pull request #1923 from khaines/khaines/improved-redis-options
Khaines/improved redis options
2 parents 4c91fac + 566ba5d commit 7127724

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [FEATURE] The distributor can now drop labels from samples (similar to the removal of the replica label for HA ingestion) per user via the `distributor.drop-label` flag. #1726
1616
* [FEATURE] Added `global` ingestion rate limiter strategy. Deprecated `-distributor.limiter-reload-period` flag. #1766
1717
* [FEATURE] Added support for Microsoft Azure blob storage to be used for storing chunk data. #1913
18+
* [ENHANCEMENT] Added `password` and `enable_tls` options to redis cache configuration. Enables usage of Microsoft Azure Cache for Redis service.
1819
* [BUGFIX] Fixed unnecessary CAS operations done by the HA tracker when the jitter is enabled. #1861
1920
* [BUGFIX] Fixed #1904 ingesters getting stuck in a LEAVING state after coming up from an ungraceful exit. #1921
2021

pkg/chunk/cache/redis_cache.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type RedisConfig struct {
2525
Expiration time.Duration `yaml:"expiration,omitempty"`
2626
MaxIdleConns int `yaml:"max_idle_conns,omitempty"`
2727
MaxActiveConns int `yaml:"max_active_conns,omitempty"`
28+
Password string `yaml:"password"`
29+
EnableTLS bool `yaml:"enable_tls"`
2830
}
2931

3032
// RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
@@ -34,6 +36,8 @@ func (cfg *RedisConfig) RegisterFlagsWithPrefix(prefix, description string, f *f
3436
f.DurationVar(&cfg.Expiration, prefix+"redis.expiration", 0, description+"How long keys stay in the redis.")
3537
f.IntVar(&cfg.MaxIdleConns, prefix+"redis.max-idle-conns", 80, description+"Maximum number of idle connections in pool.")
3638
f.IntVar(&cfg.MaxActiveConns, prefix+"redis.max-active-conns", 0, description+"Maximum number of active connections in pool.")
39+
f.StringVar(&cfg.Password, prefix+"redis.password", "", description+"Password to use when connecting to redis.")
40+
f.BoolVar(&cfg.EnableTLS, prefix+"redis.enable-tls", false, description+"Enables connecting to redis with TLS.")
3741
}
3842

3943
// NewRedisCache creates a new RedisCache
@@ -44,7 +48,15 @@ func NewRedisCache(cfg RedisConfig, name string, pool *redis.Pool) *RedisCache {
4448
MaxIdle: cfg.MaxIdleConns,
4549
MaxActive: cfg.MaxActiveConns,
4650
Dial: func() (redis.Conn, error) {
47-
c, err := redis.Dial("tcp", cfg.Endpoint)
51+
options := make([]redis.DialOption, 0, 2)
52+
if cfg.EnableTLS {
53+
options = append(options, redis.DialUseTLS(true))
54+
}
55+
if cfg.Password != "" {
56+
options = append(options, redis.DialPassword(cfg.Password))
57+
}
58+
59+
c, err := redis.Dial("tcp", cfg.Endpoint, options...)
4860
if err != nil {
4961
return nil, err
5062
}

0 commit comments

Comments
 (0)