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

feat: use a better error handling logic and messages when run in hybrid mode with no common config #4617

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
5 changes: 5 additions & 0 deletions internal/core/command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ func MessagingBootstrapHandler(ctx context.Context, wg *sync.WaitGroup, startupT
lc := bootstrapContainer.LoggingClientFrom(dic.Get)
configuration := container.ConfigurationFrom(dic.Get)

if len(configuration.Service.RequestTimeout) == 0 {
lc.Error("Service.RequestTimeout found empty in service's configuration, missing common config? Use -cp or -cc flags for common config")
return false
}

requestTimeout, err := time.ParseDuration(configuration.Service.RequestTimeout)
if err != nil {
lc.Errorf("Failed to parse Service.RequestTimeout configuration value: %v", err)
Expand Down
19 changes: 17 additions & 2 deletions internal/pkg/bootstrap/handlers/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ func (d Database) BootstrapHandler(
lc := bootstrapContainer.LoggingClientFrom(dic.Get)
secretProvider := bootstrapContainer.SecretProviderFrom(dic.Get)

// get database credentials.
dbInfo := d.database.GetDatabaseInfo()
if len(dbInfo.Host) == 0 || dbInfo.Port == 0 || len(dbInfo.Type) == 0 || len(dbInfo.Timeout) == 0 {
lc.Error("Database configuration is empty or incomplete, missing common config? Use -cp or -cc flags for common config")
return false
}

var credentials bootstrapConfig.Credentials
dbCredsRetrieved := false
for startupTimer.HasNotElapsed() {
var err error

Expand All @@ -86,13 +92,22 @@ func (d Database) BootstrapHandler(
Password: secrets[secret.PasswordKey],
}

dbCredsRetrieved = true
break
}

lc.Warnf("couldn't retrieve database credentials: %v", err.Error())
lc.Warnf("couldn't retrieve database credentials: %v and will retry it again, %s", err.Error(),
"missing common config? Use -cp or -cc flags for common config")
startupTimer.SleepForInterval()
}

// using this check to avoid the confusion with the case of both Username and Password being set to empty from credentials
if !dbCredsRetrieved {
// shouldn't go further if database credentials failed to retrieve
lc.Error("bootstrap failed: couldn't retrieve database credentials after some retries, missing common config? Use -cp or -cc flags for common config")
return false
}

// initialize database.
var dbClient interfaces.DBClient

Expand Down