Skip to content

Commit

Permalink
fix(config): redis sentinel in v2.9 (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf authored Sep 27, 2024
1 parent da69459 commit 0769e6a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Ruby 2.6
- name: Set up Ruby 3.3
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
ruby-version: 3.3

- name: Install fpm
run: gem install fpm
Expand Down
20 changes: 11 additions & 9 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,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)
})
})
}

0 comments on commit 0769e6a

Please sign in to comment.