Skip to content

Khaines/improved redis options #1923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -15,6 +15,7 @@
* [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
* [FEATURE] Added `global` ingestion rate limiter strategy. Deprecated `-distributor.limiter-reload-period` flag. #1766
* [FEATURE] Added support for Microsoft Azure blob storage to be used for storing chunk data. #1913
* [ENHANCEMENT] Added `password` and `enable_tls` options to redis cache configuration. Enables usage of Microsoft Azure Cache for Redis service.
* [BUGFIX] Fixed unnecessary CAS operations done by the HA tracker when the jitter is enabled. #1861

## 0.4.0 / 2019-12-02
Expand Down
14 changes: 13 additions & 1 deletion pkg/chunk/cache/redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type RedisConfig struct {
Expiration time.Duration `yaml:"expiration,omitempty"`
MaxIdleConns int `yaml:"max_idle_conns,omitempty"`
MaxActiveConns int `yaml:"max_active_conns,omitempty"`
Password string `yaml:"password"`
EnableTLS bool `yaml:"enable_tls"`
}

// RegisterFlagsWithPrefix adds the flags required to config this to the given FlagSet
Expand All @@ -34,6 +36,8 @@ func (cfg *RedisConfig) RegisterFlagsWithPrefix(prefix, description string, f *f
f.DurationVar(&cfg.Expiration, prefix+"redis.expiration", 0, description+"How long keys stay in the redis.")
f.IntVar(&cfg.MaxIdleConns, prefix+"redis.max-idle-conns", 80, description+"Maximum number of idle connections in pool.")
f.IntVar(&cfg.MaxActiveConns, prefix+"redis.max-active-conns", 0, description+"Maximum number of active connections in pool.")
f.StringVar(&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.")
}

// NewRedisCache creates a new RedisCache
Expand All @@ -44,7 +48,15 @@ func NewRedisCache(cfg RedisConfig, name string, pool *redis.Pool) *RedisCache {
MaxIdle: cfg.MaxIdleConns,
MaxActive: cfg.MaxActiveConns,
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", cfg.Endpoint)
options := make([]redis.DialOption, 0, 2)
if cfg.EnableTLS {
options = append(options, redis.DialUseTLS(true))
}
if cfg.Password != "" {
options = append(options, redis.DialPassword(cfg.Password))
}

c, err := redis.Dial("tcp", cfg.Endpoint, options...)
if err != nil {
return nil, err
}
Expand Down