fix(unified-storage): use the provided connection config parameters (#107455)
* fix(unified-storage): use the provided connection config parameters * extend tests * make update-workspace
This commit is contained in:
committed by
GitHub
parent
03fff523b1
commit
d76e55371a
@@ -87,9 +87,10 @@ func getEngineMySQL(getter confGetter) (*xorm.Engine, error) {
|
||||
return nil, fmt.Errorf("open database: %w", err)
|
||||
}
|
||||
|
||||
engine.SetMaxOpenConns(0)
|
||||
engine.SetMaxIdleConns(2)
|
||||
engine.SetConnMaxLifetime(4 * time.Hour)
|
||||
engine.SetMaxOpenConns(getter.Int("max_open_conns", 0))
|
||||
engine.SetMaxIdleConns(getter.Int("max_idle_conn", 4))
|
||||
maxLifetime := time.Duration(getter.Int("conn_max_lifetime", 14400)) * time.Second
|
||||
engine.SetConnMaxLifetime(maxLifetime)
|
||||
|
||||
return engine, nil
|
||||
}
|
||||
@@ -188,5 +189,10 @@ func getEnginePostgres(getter confGetter) (*xorm.Engine, error) {
|
||||
return nil, fmt.Errorf("open database: %w", err)
|
||||
}
|
||||
|
||||
engine.SetMaxOpenConns(getter.Int("max_open_conns", 0))
|
||||
engine.SetMaxIdleConns(getter.Int("max_idle_conn", 4))
|
||||
maxLifetime := time.Duration(getter.Int("conn_max_lifetime", 14400)) * time.Second
|
||||
engine.SetConnMaxLifetime(maxLifetime)
|
||||
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ type confGetter interface {
|
||||
Err() error
|
||||
Bool(key string) bool
|
||||
String(key string) string
|
||||
Int(key string, def int) int
|
||||
}
|
||||
|
||||
func newConfGetter(ds *setting.DynamicSection, keyPrefix string) confGetter {
|
||||
@@ -52,6 +53,10 @@ func (g *sectionGetter) String(key string) string {
|
||||
return v
|
||||
}
|
||||
|
||||
func (g *sectionGetter) Int(key string, def int) int {
|
||||
return g.ds.Key(g.keyPrefix + key).MustInt(def)
|
||||
}
|
||||
|
||||
// MakeDSN creates a DSN from the given key/value pair. It validates the strings
|
||||
// form valid UTF-8 sequences and escapes values if needed.
|
||||
func MakeDSN(m map[string]string) (string, error) {
|
||||
|
||||
@@ -28,11 +28,13 @@ func TestSectionGetter(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var (
|
||||
key = "the key"
|
||||
keyBoolTrue = "I'm true"
|
||||
keyBoolFalse = "not me!"
|
||||
prefix = "this is some prefix"
|
||||
val = string(invalidUTF8ByteSequence)
|
||||
key = "the key"
|
||||
keyBoolTrue = "I'm true"
|
||||
keyBoolFalse = "not me!"
|
||||
keyIntValid = "valid_int"
|
||||
keyIntMissing = "missing_int"
|
||||
prefix = "this is some prefix"
|
||||
val = string(invalidUTF8ByteSequence)
|
||||
)
|
||||
|
||||
t.Run("with prefix", func(t *testing.T) {
|
||||
@@ -42,6 +44,8 @@ func TestSectionGetter(t *testing.T) {
|
||||
prefix + key: val,
|
||||
prefix + keyBoolTrue: "YES",
|
||||
prefix + keyBoolFalse: "0",
|
||||
prefix + keyIntValid: "42",
|
||||
// Note: keyIntMissing is intentionally not included to test default behavior
|
||||
}, prefix)
|
||||
|
||||
require.False(t, g.Bool("whatever bool"))
|
||||
@@ -53,6 +57,15 @@ func TestSectionGetter(t *testing.T) {
|
||||
require.True(t, g.Bool(keyBoolTrue))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
require.Equal(t, 999, g.Int("whatever int", 999))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
require.Equal(t, 42, g.Int(keyIntValid, 100))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
require.Equal(t, 200, g.Int(keyIntMissing, 200))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
require.Empty(t, g.String("whatever string"))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
@@ -68,6 +81,8 @@ func TestSectionGetter(t *testing.T) {
|
||||
key: val,
|
||||
keyBoolTrue: "true",
|
||||
keyBoolFalse: "f",
|
||||
keyIntValid: "123",
|
||||
// Note: keyIntMissing is intentionally not included to test default behavior
|
||||
}, "")
|
||||
|
||||
require.False(t, g.Bool("whatever bool"))
|
||||
@@ -79,6 +94,15 @@ func TestSectionGetter(t *testing.T) {
|
||||
require.True(t, g.Bool(keyBoolTrue))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
require.Equal(t, 500, g.Int("whatever int", 500))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
require.Equal(t, 123, g.Int(keyIntValid, 0))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
require.Equal(t, 300, g.Int(keyIntMissing, 300))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
require.Empty(t, g.String("whatever string"))
|
||||
require.NoError(t, g.Err())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user