Skip to content

Commit

Permalink
CBG-3324: Add startup cnf logging to DefaultDbConfig (#6381)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammed-madi authored Aug 24, 2023
1 parent a45339d commit 5288dbf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
34 changes: 33 additions & 1 deletion rest/adminapitest/admin_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func TestDBOfflinePutDbConfig(t *testing.T) {

// Tests that the users returned in the config endpoint have the correct names
// Reproduces #2223
func TestDBGetConfigNames(t *testing.T) {
func TestDBGetConfigNamesAndDefaultLogging(t *testing.T) {

p := "password"
rt := rest.NewRestTester(t,
Expand All @@ -563,11 +563,38 @@ func TestDBGetConfigNames(t *testing.T) {
require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &body))

assert.Equal(t, len(rt.DatabaseConfig.Users), len(body.Users))
emptyCnf := &rest.DbLoggingConfig{}
assert.Equal(t, body.Logging, emptyCnf)

for k, v := range body.Users {
assert.Equal(t, k, *v.Name)
}
}

func TestDBGetConfigCustomLogging(t *testing.T) {
logKeys := []string{base.KeyAccess.String(), base.KeyHTTP.String()}
rt := rest.NewRestTester(t,
&rest.RestTesterConfig{
DatabaseConfig: &rest.DatabaseConfig{DbConfig: rest.DbConfig{
Logging: &rest.DbLoggingConfig{
Console: &rest.DbConsoleLoggingConfig{
LogLevel: base.LogLevelPtr(base.LevelError),
LogKeys: logKeys,
},
},
},
},
},
)

defer rt.Close()

response := rt.SendAdminRequest("GET", "/db/_config?include_runtime=true", "")
var body rest.DbConfig
require.NoError(t, base.JSONUnmarshal(response.Body.Bytes(), &body))

assert.Equal(t, body.Logging.Console.LogLevel, base.LogLevelPtr(base.LevelError))
assert.Equal(t, body.Logging.Console.LogKeys, logKeys)
}

// Take DB offline and ensure can post _resync
Expand Down Expand Up @@ -3271,6 +3298,8 @@ func TestConfigsIncludeDefaults(t *testing.T) {
ctx := base.TestCtx(t)
config := rest.BootstrapStartupConfigForTest(t)
sc, err := rest.SetupServerContext(ctx, &config, true)
config.Logging.Console.LogKeys = []string{base.KeyDCP.String()}
config.Logging.Console.LogLevel.Set(base.LevelDebug)
require.NoError(t, err)
defer func() {
sc.Close(ctx)
Expand Down Expand Up @@ -3303,6 +3332,9 @@ func TestConfigsIncludeDefaults(t *testing.T) {
assert.Equal(t, false, *dbConfig.StartOffline)
assert.Equal(t, db.DefaultCompactInterval, uint32(*dbConfig.CompactIntervalDays))

assert.Equal(t, dbConfig.Logging.Console.LogLevel.String(), base.LevelDebug.String())
assert.Equal(t, dbConfig.Logging.Console.LogKeys, []string{base.KeyDCP.String()})

var runtimeServerConfigResponse rest.RunTimeServerConfigResponse
resp = rest.BootstrapAdminRequest(t, http.MethodGet, "/_config?include_runtime=true", "")
resp.RequireStatus(http.StatusOK)
Expand Down
15 changes: 15 additions & 0 deletions rest/config_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ func GenerateDatabaseConfigVersionID(previousRevID string, dbConfig *DbConfig) (
return hash, nil
}

func DefaultPerDBLogging(bootstrapLoggingCnf base.LoggingConfig) *DbLoggingConfig {
if bootstrapLoggingCnf.Console != nil {
if *bootstrapLoggingCnf.Console.Enabled {
return &DbLoggingConfig{
Console: &DbConsoleLoggingConfig{
LogLevel: bootstrapLoggingCnf.Console.LogLevel,
LogKeys: bootstrapLoggingCnf.Console.LogKeys,
},
}
}
}
return &DbLoggingConfig{}
}

// MergeDatabaseConfigWithDefaults merges the passed in config onto a DefaultDbConfig which results in returned value
// being populated with defaults when not set
func MergeDatabaseConfigWithDefaults(sc *StartupConfig, dbConfig *DbConfig) (*DbConfig, error) {
Expand Down Expand Up @@ -165,6 +179,7 @@ func DefaultDbConfig(sc *StartupConfig) *DbConfig {
ClientPartitionWindowSecs: base.IntPtr(int(base.DefaultClientPartitionWindow.Seconds())),
JavascriptTimeoutSecs: base.Uint32Ptr(base.DefaultJavascriptTimeoutSecs),
Suspendable: base.BoolPtr(sc.IsServerless()),
Logging: DefaultPerDBLogging(sc.Logging),
}

revsLimit := db.DefaultRevsLimitNoConflicts
Expand Down

0 comments on commit 5288dbf

Please sign in to comment.