diff options
author | John Cai <jcai@gitlab.com> | 2020-06-02 06:21:54 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2020-06-02 06:21:54 +0300 |
commit | 34810c8ca5d2e8ee168d0dcbec39bd7fbc7563c9 (patch) | |
tree | aa56766f11a329144890739edf31ae7bee7cee55 /internal/praefect/config | |
parent | d4f6083d79d41b03c520d365be109a947e679569 (diff) | |
parent | 4fa59a2930143998f91a3849556696bb3103c009 (diff) |
Merge branch 'zj-default-sql-failover' into 'master'
failover: Default to enabling SQL strategy
Closes #2682
See merge request gitlab-org/gitaly!2218
Diffstat (limited to 'internal/praefect/config')
-rw-r--r-- | internal/praefect/config/config.go | 10 | ||||
-rw-r--r-- | internal/praefect/config/config_test.go | 22 | ||||
-rw-r--r-- | internal/praefect/config/testdata/config.overwritedefaults.toml | 5 |
3 files changed, 35 insertions, 2 deletions
diff --git a/internal/praefect/config/config.go b/internal/praefect/config/config.go index c69104cd9..e25f909ff 100644 --- a/internal/praefect/config/config.go +++ b/internal/praefect/config/config.go @@ -20,6 +20,8 @@ type Failover struct { ReadOnlyAfterFailover bool `toml:"read_only_after_failover"` } +const sqlFailoverValue = "sql" + // Config is a container for everything found in the TOML config file type Config struct { ListenAddr string `toml:"listen_addr"` @@ -46,7 +48,10 @@ type VirtualStorage struct { // FromFile loads the config for the passed file path func FromFile(filePath string) (Config, error) { - conf := &Config{} + conf := &Config{ + // Sets the default Failover, to be overwritten when deserializing the TOML + Failover: Failover{Enabled: true, ElectionStrategy: sqlFailoverValue, ReadOnlyAfterFailover: true}, + } if _, err := toml.DecodeFile(filePath, conf); err != nil { return Config{}, err } @@ -143,7 +148,8 @@ func (c *Config) Validate() error { // NeedsSQL returns true if the driver for SQL needs to be initialized func (c *Config) NeedsSQL() bool { - return !c.MemoryQueueEnabled || (c.Failover.Enabled && c.Failover.ElectionStrategy == "sql") + return !c.MemoryQueueEnabled || + (c.Failover.Enabled && c.Failover.ElectionStrategy == sqlFailoverValue) } func (c *Config) setDefaults() { diff --git a/internal/praefect/config/config_test.go b/internal/praefect/config/config_test.go index aa78dae87..982565229 100644 --- a/internal/praefect/config/config_test.go +++ b/internal/praefect/config/config_test.go @@ -265,6 +265,23 @@ func TestConfigParsing(t *testing.T) { }, MemoryQueueEnabled: true, GracefulStopTimeout: config.Duration(30 * time.Second), + Failover: Failover{ + Enabled: true, + ElectionStrategy: sqlFailoverValue, + ReadOnlyAfterFailover: true, + }, + }, + }, + { + desc: "overwriting default values in the config", + filePath: "testdata/config.overwritedefaults.toml", + expected: Config{ + GracefulStopTimeout: config.Duration(time.Minute), + Failover: Failover{ + Enabled: false, + ElectionStrategy: "local", + ReadOnlyAfterFailover: false, + }, }, }, { @@ -272,6 +289,11 @@ func TestConfigParsing(t *testing.T) { filePath: "testdata/config.empty.toml", expected: Config{ GracefulStopTimeout: config.Duration(time.Minute), + Failover: Failover{ + Enabled: true, + ElectionStrategy: sqlFailoverValue, + ReadOnlyAfterFailover: true, + }, }, }, { diff --git a/internal/praefect/config/testdata/config.overwritedefaults.toml b/internal/praefect/config/testdata/config.overwritedefaults.toml new file mode 100644 index 000000000..39771fcd6 --- /dev/null +++ b/internal/praefect/config/testdata/config.overwritedefaults.toml @@ -0,0 +1,5 @@ +[failover] +enabled = false +election_strategy = "local" +read_only_after_failover = false + |