Skip to content

Commit 9a75778

Browse files
authored
Setting kv driver defaults as configuration (#4553)
1 parent 2a74d86 commit 9a75778

15 files changed

+89
-83
lines changed

pkg/config/defaults.go

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,35 @@ import (
77
)
88

99
const (
10-
DatabaseTypeKey = "database.type"
11-
DefaultDatabaseType = "local"
10+
DatabaseTypeKey = "database.type"
11+
LocalDatabaseType = "local"
1212

13-
DatabaseKVLocalPath = "database.local.path"
14-
DefaultDatabaseLocalKVPath = "~/lakefs/metadata"
13+
DatabaseLocalPathKey = "database.local.path"
14+
DefaultDatabaseLocalPath = "~/lakefs/metadata"
1515

16-
BlockstoreTypeKey = "blockstore.type"
17-
DefaultBlockstoreType = "local"
16+
DatabaseLocalPrefetchSizeKey = "database.local.prefetch_size"
17+
DefaultDatabaseLocalPrefetchSize = 256
18+
19+
DatabaseDynamodbTableNameKey = "database.dynamodb.table_name"
20+
DefaultDatabaseDynamodbTableName = "kvstore"
21+
22+
DatabaseDynamodbReadCapacityUnitsKey = "database.dynamodb.read_capacity_units"
23+
DefaultDatabaseDynamodbReadCapacityUnits = 1000
24+
25+
DatabaseDynamodbWriteCapacityUnitsKey = "database.dynamodb.write_capacity_units"
26+
DefaultDatabaseDynamodbWriteCapacityUnits = 1000
27+
28+
DatabasePostgresMaxOpenConnectionsKey = "database.postgres.max_open_connections"
29+
DefaultDatabasePostgresMaxOpenConnections = 25
30+
31+
DatabasePostgresMaxIdleConnectionsKey = "database.postgres.max_idle_connections"
32+
DefaultDatabasePostgresMaxIdleConnections = 25
33+
34+
PostgresConnectionMaxLifetimeKey = "database.postgres.connection_max_lifetime"
35+
DefaultPostgresConnectionMaxLifetime = "5m"
36+
37+
BlockstoreTypeKey = "blockstore.type"
38+
LocalBlockstoreType = "local"
1839

1940
BlockstoreLocalPathKey = "blockstore.local.path"
2041
DefaultBlockstoreLocalPath = "~/lakefs/data/block"
@@ -88,8 +109,8 @@ const (
88109
LoggingFilesKeepKey = "logging.files_keep"
89110
LoggingAuditLogLevel = "logging.audit_log_level"
90111

91-
AuthEncryptSecretKey = "auth.encrypt.secret_key" // #nosec
92-
DefaultAuthEncryptSecretKey = "THIS_MUST_BE_CHANGED_IN_PRODUCTION" // #nosec
112+
AuthEncryptSecretKey = "auth.encrypt.secret_key" // #nosec
113+
LocalAuthEncryptSecretKey = "THIS_MUST_BE_CHANGED_IN_PRODUCTION" // #nosec
93114

94115
ActionsEnabledKey = "actions.enabled"
95116

@@ -134,17 +155,11 @@ const (
134155
UIEnabledKey = "ui.enabled"
135156
)
136157

137-
func setDefaultLocalConfig() {
138-
viper.SetDefault(DatabaseTypeKey, DefaultDatabaseType)
139-
viper.SetDefault(DatabaseKVLocalPath, DefaultDatabaseLocalKVPath)
140-
viper.SetDefault(BlockstoreLocalPathKey, DefaultBlockstoreLocalPath)
141-
viper.SetDefault(AuthEncryptSecretKey, DefaultAuthEncryptSecretKey)
142-
viper.SetDefault(BlockstoreTypeKey, DefaultBlockstoreType)
143-
}
144-
145158
func setDefaults(local bool) {
146159
if local {
147-
setDefaultLocalConfig()
160+
viper.SetDefault(DatabaseTypeKey, LocalDatabaseType)
161+
viper.SetDefault(AuthEncryptSecretKey, LocalAuthEncryptSecretKey)
162+
viper.SetDefault(BlockstoreTypeKey, LocalBlockstoreType)
148163
}
149164

150165
viper.SetDefault(ListenAddressKey, DefaultListenAddr)
@@ -166,7 +181,6 @@ func setDefaults(local bool) {
166181
viper.SetDefault(AuthLogoutRedirectURL, DefaultAuthLogoutRedirectURL)
167182

168183
viper.SetDefault(BlockstoreLocalPathKey, DefaultBlockstoreLocalPath)
169-
viper.SetDefault(BlockstoreTypeKey, DefaultBlockstoreType)
170184
viper.SetDefault(BlockstoreS3RegionKey, DefaultBlockstoreS3Region)
171185
viper.SetDefault(BlockstoreS3StreamingChunkSizeKey, DefaultBlockstoreS3StreamingChunkSize)
172186
viper.SetDefault(BlockstoreS3StreamingChunkTimeoutKey, DefaultBlockstoreS3StreamingChunkTimeout)
@@ -206,4 +220,18 @@ func setDefaults(local bool) {
206220
viper.SetDefault(LakefsEmailBaseURLKey, DefaultLakefsEmailBaseURL)
207221

208222
viper.SetDefault(UIEnabledKey, DefaultUIEnabled)
223+
224+
viper.SetDefault(BlockstoreLocalPathKey, DefaultBlockstoreLocalPath)
225+
226+
viper.SetDefault(DatabaseLocalPathKey, DefaultDatabaseLocalPath)
227+
viper.SetDefault(DatabaseLocalPrefetchSizeKey, DefaultDatabaseLocalPrefetchSize)
228+
229+
viper.SetDefault(DatabaseDynamodbTableNameKey, DefaultDatabaseDynamodbTableName)
230+
231+
viper.SetDefault(DatabaseDynamodbReadCapacityUnitsKey, DefaultDatabaseDynamodbReadCapacityUnits)
232+
viper.SetDefault(DatabaseDynamodbWriteCapacityUnitsKey, DefaultDatabaseDynamodbWriteCapacityUnits)
233+
234+
viper.SetDefault(DatabasePostgresMaxOpenConnectionsKey, DefaultDatabasePostgresMaxOpenConnections)
235+
viper.SetDefault(DatabasePostgresMaxIdleConnectionsKey, DefaultDatabasePostgresMaxIdleConnections)
236+
viper.SetDefault(PostgresConnectionMaxLifetimeKey, DefaultPostgresConnectionMaxLifetime)
209237
}

pkg/config/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type configuration struct {
7777
// DropTables Development flag to delete tables after successful migration to KV
7878
DropTables bool `mapstructure:"drop_tables"`
7979
// Type Name of the KV Store driver DB implementation which is available according to the kv package Drivers function
80-
Type string `mapstructure:"type"`
80+
Type string `mapstructure:"type" validate:"required"`
8181

8282
Local *struct {
8383
// Path - Local directory path to store the DB files

pkg/config/testdata/aws_credentials.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
database:
3+
type: local
4+
25
auth:
36
encrypt:
47
secret_key: "required in config"

pkg/config/testdata/aws_credentials_with_alias.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
database:
3+
type: local
4+
25
auth:
36
encrypt:
47
secret_key: "required in config"

pkg/config/testdata/domain_name_prefix.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
---
2+
database:
3+
type: local
4+
5+
blockstore:
6+
type: local
7+
28
gateways:
39
s3:
410
domain_name:

pkg/config/testdata/valid_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ logging:
55
output: "-"
66

77
database:
8+
type: postgres
89
postgres:
910
connection_string: test:///dev/null
1011
max_open_connections: 12

pkg/config/testdata/valid_custom_badger_config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
database:
3+
type: local
4+
25
logging:
36
format: text
47
level: NONE

pkg/config/testdata/valid_gs_adapter_config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
database:
3+
type: local
4+
25
logging:
36
format: text
47
level: NONE

pkg/config/testdata/valid_json_logger_config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
database:
3+
type: local
4+
25
logging:
36
format: json
47
level: DEBUG

pkg/config/testdata/valid_oidc_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ logging:
55
output: "-"
66

77
database:
8+
type: postgres
89
postgres:
910
connection_string: test:///dev/null
1011
max_open_connections: 12

0 commit comments

Comments
 (0)