-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add redis sentinel support #161
Conversation
632ced9
to
deb938c
Compare
0139e4d
to
0a0db31
Compare
518074e
to
88d9616
Compare
It should pass the tests now 😃 |
88d9616
to
b418372
Compare
b418372
to
366fd2d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validated in test environment
README.md
Outdated
| port | integer | Redis server port | | ||
| host | string | Redis server URI (redis standalone mode) | | ||
| port | integer | Redis server port (redis standalone mode) | | ||
| hosts |string array | Redis server sentinel URI (redis sentinel mode)| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the name hosts
and the description in the third column suggests that host
and hosts
have the same format but, the SentinelAddrs
field is a list of host:port
strings.
19 // FailoverOptions are used to configure a failover client and should
20 // be passed to NewFailoverClient.
21 type FailoverOptions struct {
22 // The master name.
23 MasterName string
24 // A seed list of host:port addresses of sentinel nodes.
25 SentinelAddrs []string
26
/newgo/pkg/mod/github.com/redis/go-redis/v9@v9.3.0/sentinel.go
Should we modify the description to mention the formatting difference with host
? Or add a separate array called ports
?
246 | Configuration field | Type | Description |
247 | --- | --- | --- |
248 | host | string | Redis server URI (redis standalone mode) |
249 | port | integer | Redis server port (redis standalone mode) |
250 | hosts |string array | Redis server sentinel URI (redis sentinel mode)|
+ | ports |integer array | Redis server sentinel port (redis sentinel mode)|
251 | mastername | string | Redis master sentinel name (redis sentinel mode)|
README.md
I lean more towards modifiying the description to explain the difference and even rename this variable. I'm not great at naming. sentinel_hosts_ports
maybe?
246 | Configuration field | Type | Description |
247 | --- | --- | --- |
248 | host | string | Redis server URI (redis standalone mode) |
249 | port | integer | Redis server port (redis standalone mode) |
250 - | hosts |string array | Redis server sentinel URI (redis sentinel mode)|
+ | sentinel_hosts_ports | string array | Redis server sentinel host:port list (redis sentinel mode)|
251 | mastername | string | Redis master sentinel name (redis sentinel mode)|
README.md
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will go for sentinel_hosts_ports
and sentinel_mastername
so. I'm agree with that.
I tried to do breaking change and want to keep host
and port
for redis mode. And in general in others backends, its common to use hosts
that take a list of host:port.
@@ -149,6 +149,8 @@ func TestNewBaseBackend(t *testing.T) { | |||
desc: "Redis", | |||
inConfig: config.Backend{Type: config.BackendRedis}, | |||
expectedLogEntries: []logEntry{ | |||
{msg: "Error creating Redis backend: At least one Host[s] is required.", lvl: logrus.FatalLevel}, | |||
{msg: "Creating Redis backend", lvl: logrus.InfoLevel}, | |||
{msg: "Error creating Redis backend: ", lvl: logrus.FatalLevel}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice, logrus.FatalLevel
stops execution. Under this scenario, we would only see the first entry in the logs:
148 {
149 desc: "Redis",
150 inConfig: config.Backend{Type: config.BackendRedis},
151 expectedLogEntries: []logEntry{
152 {msg: "Error creating Redis backend: At least one Host[s] is required.", lvl: logrus.FatalLevel},
153 - {msg: "Creating Redis backend", lvl: logrus.InfoLevel},
154 - {msg: "Error creating Redis backend: ", lvl: logrus.FatalLevel},
155 },
156 },
backends/config/config_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the same but without those three items the test fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because the test function disables the logrus
exit functions, so we can have as many log.Fatalf
calls without interrupting the test:
func TestNewBaseBackend(t *testing.T) {
// logrus entries will be recorded to this `hook` object so we can compare and assert them
hook := logrusTest.NewGlobal()
defer func() { logrus.StandardLogger().ExitFunc = nil }()
logrus.StandardLogger().ExitFunc = func(int) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks @sebmil-daily
config/config_test.go
Outdated
@@ -1202,6 +1202,7 @@ func getExpectedDefaultConfig() Configuration { | |||
DefaultTTL: utils.CASSANDRA_DEFAULT_TTL_SECONDS, | |||
}, | |||
Redis: Redis{ | |||
Hosts: []string{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this. The test is able to pass without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I beat a lot to find what was wrong before I explicit declare this here.
Without, it fail because the array is nil.
dfd0ac3
to
b9f0ed2
Compare
b9f0ed2
to
6cbdc16
Compare
Hi @cyrinux, if you don't mind, going forward could you please avoid force pushes and instead just add additional commits when making updates? It saves us review time since we can then just review the delta. Thanks! |
Sure, I understand no problems. I don't touch anymore now. Waiting for you now 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still an error in a test case, hence the validation didn't pass. Can we please fix?
Otherwise, it's looking pretty good.
log.Infof("config.backend.redis.port: %d", cfg.Port) | ||
if cfg.Host != "" && len(cfg.SentinelHostsPorts) > 0 { | ||
log.Infof("config.backend.redis.sentinel_hosts_ports: %s. Note that redis 'host' will be ignore if 'sentinel_hosts_ports' is define", cfg.SentinelHostsPorts) | ||
log.Infof("config.backend.redis.sentinel_mastername: %s.", cfg.SentinelMasterName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cyrinux thank you for your addresing our feedback. When we want to configure Redis in Sentinel mode, is SentinelMasterName
a required field? In other words, if len(cfg.SentinelHostsPorts) > 0
is true, do we also need cfg.SentinelMasterName
to not be empty?
If we do, then I believe an extra cfg.SentinelMasterName != ""
check should be added in case len(cfg.SentinelHostsPorts) > 0
is found to be true and log.Infof()
or error out accordingly.
Thoughts?
Hey @guscarreon , considering those points:
I suggest we cancel this PR for now and we'll come back with a new one that will introduce What do you think? (@cyrinux and me are working in the same company and we already agreed on this) |
I agree. Let's close this PR now and will keep an eye for your upcoming Redis entinel adapter PR. |
Hi,
This PR do the following things:
Thanks for the project.