Skip to content
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

fix(config): redis sentinel in v2.11 #1103

Closed
wants to merge 1 commit into from
Closed
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
20 changes: 11 additions & 9 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ type RedisConfig struct {
// GetSettings returns redis config parsed from moira config files.
func (config *RedisConfig) GetSettings() redis.DatabaseConfig {
return redis.DatabaseConfig{
MasterName: config.MasterName,
Addrs: strings.Split(config.Addrs, ","),
Username: config.Username,
Password: config.Password,
MaxRetries: config.MaxRetries,
MetricsTTL: to.Duration(config.MetricsTTL),
DialTimeout: to.Duration(config.DialTimeout),
ReadTimeout: to.Duration(config.ReadTimeout),
WriteTimeout: to.Duration(config.WriteTimeout),
MasterName: config.MasterName,
Addrs: strings.Split(config.Addrs, ","),
Username: config.Username,
Password: config.Password,
SentinelUsername: config.SentinelUsername,
SentinelPassword: config.SentinelPassword,
MaxRetries: config.MaxRetries,
MetricsTTL: to.Duration(config.MetricsTTL),
DialTimeout: to.Duration(config.DialTimeout),
ReadTimeout: to.Duration(config.ReadTimeout),
WriteTimeout: to.Duration(config.WriteTimeout),
}
}

Expand Down
55 changes: 55 additions & 0 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cmd

import (
"testing"
"time"

"github.com/moira-alert/moira/database/redis"
. "github.com/smartystreets/goconvey/convey"
)

func TestRedisConfig(t *testing.T) {
Convey("Test RedisConfig.GetSettings", t, func() {
Convey("With empty config", func() {
redisCfg := RedisConfig{}

expected := redis.DatabaseConfig{
Addrs: []string{""},
}
databaseCfg := redisCfg.GetSettings()
So(databaseCfg, ShouldResemble, expected)
})

Convey("With filled config", func() {
redisCfg := RedisConfig{
MasterName: "test-master",
Addrs: "redis1:6379",
SentinelUsername: "sentinel-user",
SentinelPassword: "sentinel-pass",
Username: "user",
Password: "pass",
MetricsTTL: "1m",
DialTimeout: "1m",
ReadTimeout: "1m",
WriteTimeout: "1m",
MaxRetries: 3,
}

expected := redis.DatabaseConfig{
MasterName: "test-master",
Addrs: []string{"redis1:6379"},
SentinelUsername: "sentinel-user",
SentinelPassword: "sentinel-pass",
Username: "user",
Password: "pass",
MetricsTTL: time.Minute,
DialTimeout: time.Minute,
ReadTimeout: time.Minute,
WriteTimeout: time.Minute,
MaxRetries: 3,
}
databaseCfg := redisCfg.GetSettings()
So(databaseCfg, ShouldResemble, expected)
})
})
}
Loading