Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBG-3324: Add startup cnf logging to DefaultDbConfig (#6381) #6459

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion rest/adminapitest/admin_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,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 @@ -507,11 +507,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 @@ -3349,6 +3376,8 @@ func TestConfigsIncludeDefaults(t *testing.T) {
// Start SG with no databases
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 @@ -3381,6 +3410,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 @@ -85,6 +85,20 @@ func GenerateDatabaseConfigVersionID(ctx context.Context, previousRevID string,
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 @@ -163,6 +177,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