Commit f8b6814c authored by Nick Thomas's avatar Nick Thomas

Merge branch 'jv-workhorse-remove-broken-settings' into 'master'

Remove broken Workhorse Redis settings

See merge request gitlab-org/gitlab!63023
parents 7a978275 5467c9fd
...@@ -103,15 +103,11 @@ Optional fields are as follows: ...@@ -103,15 +103,11 @@ Optional fields are as follows:
``` ```
[redis] [redis]
DB = 0 DB = 0
ReadTimeout = "1s"
KeepAlivePeriod = "5m"
MaxIdle = 1 MaxIdle = 1
MaxActive = 1 MaxActive = 1
``` ```
- `DB` is the Database to connect to. Defaults to `0` - `DB` is the Database to connect to. Defaults to `0`
- `ReadTimeout` is how long a redis read-command can take. Defaults to `1s`
- `KeepAlivePeriod` is how long the redis connection is to be kept alive without anything flowing through it. Defaults to `5m`
- `MaxIdle` is how many idle connections can be in the redis-pool at once. Defaults to 1 - `MaxIdle` is how many idle connections can be in the redis-pool at once. Defaults to 1
- `MaxActive` is how many connections the pool can keep. Defaults to 1 - `MaxActive` is how many connections the pool can keep. Defaults to 1
......
...@@ -70,16 +70,13 @@ type AzureCredentials struct { ...@@ -70,16 +70,13 @@ type AzureCredentials struct {
} }
type RedisConfig struct { type RedisConfig struct {
URL TomlURL URL TomlURL
Sentinel []TomlURL Sentinel []TomlURL
SentinelMaster string SentinelMaster string
Password string Password string
DB *int DB *int
ReadTimeout *TomlDuration MaxIdle *int
WriteTimeout *TomlDuration MaxActive *int
KeepAlivePeriod *TomlDuration
MaxIdle *int
MaxActive *int
} }
type ImageResizerConfig struct { type ImageResizerConfig struct {
......
...@@ -113,21 +113,9 @@ var poolDialFunc func() (redis.Conn, error) ...@@ -113,21 +113,9 @@ var poolDialFunc func() (redis.Conn, error)
var workerDialFunc func() (redis.Conn, error) var workerDialFunc func() (redis.Conn, error)
func timeoutDialOptions(cfg *config.RedisConfig) []redis.DialOption { func timeoutDialOptions(cfg *config.RedisConfig) []redis.DialOption {
readTimeout := defaultReadTimeout
writeTimeout := defaultWriteTimeout
if cfg != nil {
if cfg.ReadTimeout != nil {
readTimeout = cfg.ReadTimeout.Duration
}
if cfg.WriteTimeout != nil {
writeTimeout = cfg.WriteTimeout.Duration
}
}
return []redis.DialOption{ return []redis.DialOption{
redis.DialReadTimeout(readTimeout), redis.DialReadTimeout(defaultReadTimeout),
redis.DialWriteTimeout(writeTimeout), redis.DialWriteTimeout(defaultWriteTimeout),
} }
} }
...@@ -148,47 +136,45 @@ func dialOptionsBuilder(cfg *config.RedisConfig, setTimeouts bool) []redis.DialO ...@@ -148,47 +136,45 @@ func dialOptionsBuilder(cfg *config.RedisConfig, setTimeouts bool) []redis.DialO
return dopts return dopts
} }
func keepAliveDialer(timeout time.Duration) func(string, string) (net.Conn, error) { func keepAliveDialer(network, address string) (net.Conn, error) {
return func(network, address string) (net.Conn, error) { addr, err := net.ResolveTCPAddr(network, address)
addr, err := net.ResolveTCPAddr(network, address) if err != nil {
if err != nil { return nil, err
return nil, err
}
tc, err := net.DialTCP(network, nil, addr)
if err != nil {
return nil, err
}
if err := tc.SetKeepAlive(true); err != nil {
return nil, err
}
if err := tc.SetKeepAlivePeriod(timeout); err != nil {
return nil, err
}
return tc, nil
} }
tc, err := net.DialTCP(network, nil, addr)
if err != nil {
return nil, err
}
if err := tc.SetKeepAlive(true); err != nil {
return nil, err
}
if err := tc.SetKeepAlivePeriod(defaultKeepAlivePeriod); err != nil {
return nil, err
}
return tc, nil
} }
type redisDialerFunc func() (redis.Conn, error) type redisDialerFunc func() (redis.Conn, error)
func sentinelDialer(dopts []redis.DialOption, keepAlivePeriod time.Duration) redisDialerFunc { func sentinelDialer(dopts []redis.DialOption) redisDialerFunc {
return func() (redis.Conn, error) { return func() (redis.Conn, error) {
address, err := sntnl.MasterAddr() address, err := sntnl.MasterAddr()
if err != nil { if err != nil {
errorCounter.WithLabelValues("master", "sentinel").Inc() errorCounter.WithLabelValues("master", "sentinel").Inc()
return nil, err return nil, err
} }
dopts = append(dopts, redis.DialNetDial(keepAliveDialer(keepAlivePeriod))) dopts = append(dopts, redis.DialNetDial(keepAliveDialer))
return redisDial("tcp", address, dopts...) return redisDial("tcp", address, dopts...)
} }
} }
func defaultDialer(dopts []redis.DialOption, keepAlivePeriod time.Duration, url url.URL) redisDialerFunc { func defaultDialer(dopts []redis.DialOption, url url.URL) redisDialerFunc {
return func() (redis.Conn, error) { return func() (redis.Conn, error) {
if url.Scheme == "unix" { if url.Scheme == "unix" {
return redisDial(url.Scheme, url.Path, dopts...) return redisDial(url.Scheme, url.Path, dopts...)
} }
dopts = append(dopts, redis.DialNetDial(keepAliveDialer(keepAlivePeriod))) dopts = append(dopts, redis.DialNetDial(keepAliveDialer))
// redis.DialURL only works with redis[s]:// URLs // redis.DialURL only works with redis[s]:// URLs
if url.Scheme == "redis" || url.Scheme == "rediss" { if url.Scheme == "redis" || url.Scheme == "rediss" {
...@@ -231,15 +217,11 @@ func countDialer(dialer redisDialerFunc) redisDialerFunc { ...@@ -231,15 +217,11 @@ func countDialer(dialer redisDialerFunc) redisDialerFunc {
// DefaultDialFunc should always used. Only exception is for unit-tests. // DefaultDialFunc should always used. Only exception is for unit-tests.
func DefaultDialFunc(cfg *config.RedisConfig, setReadTimeout bool) func() (redis.Conn, error) { func DefaultDialFunc(cfg *config.RedisConfig, setReadTimeout bool) func() (redis.Conn, error) {
keepAlivePeriod := defaultKeepAlivePeriod
if cfg.KeepAlivePeriod != nil {
keepAlivePeriod = cfg.KeepAlivePeriod.Duration
}
dopts := dialOptionsBuilder(cfg, setReadTimeout) dopts := dialOptionsBuilder(cfg, setReadTimeout)
if sntnl != nil { if sntnl != nil {
return countDialer(sentinelDialer(dopts, keepAlivePeriod)) return countDialer(sentinelDialer(dopts))
} }
return countDialer(defaultDialer(dopts, keepAlivePeriod, cfg.URL.URL)) return countDialer(defaultDialer(dopts, cfg.URL.URL))
} }
// Configure redis-connection // Configure redis-connection
......
...@@ -96,13 +96,11 @@ func TestConfigureMinimalConfig(t *testing.T) { ...@@ -96,13 +96,11 @@ func TestConfigureMinimalConfig(t *testing.T) {
func TestConfigureFullConfig(t *testing.T) { func TestConfigureFullConfig(t *testing.T) {
i, a := 4, 10 i, a := 4, 10
r := config.TomlDuration{Duration: 3}
cfg := &config.RedisConfig{ cfg := &config.RedisConfig{
URL: config.TomlURL{}, URL: config.TomlURL{},
Password: "", Password: "",
MaxIdle: &i, MaxIdle: &i,
MaxActive: &a, MaxActive: &a,
ReadTimeout: &r,
} }
Configure(cfg, DefaultDialFunc) Configure(cfg, DefaultDialFunc)
...@@ -219,11 +217,7 @@ func TestDialOptionsBuildersSetTimeouts(t *testing.T) { ...@@ -219,11 +217,7 @@ func TestDialOptionsBuildersSetTimeouts(t *testing.T) {
} }
func TestDialOptionsBuildersSetTimeoutsConfig(t *testing.T) { func TestDialOptionsBuildersSetTimeoutsConfig(t *testing.T) {
cfg := &config.RedisConfig{ dopts := dialOptionsBuilder(nil, true)
ReadTimeout: &config.TomlDuration{Duration: time.Second * time.Duration(15)},
WriteTimeout: &config.TomlDuration{Duration: time.Second * time.Duration(15)},
}
dopts := dialOptionsBuilder(cfg, true)
require.Equal(t, 2, len(dopts)) require.Equal(t, 2, len(dopts))
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment