Skip to content

Commit

Permalink
feat: use a better error handling logic and messages when run in hybr…
Browse files Browse the repository at this point in the history
…id mode with no common config (#4617)

Closes: #4615

Signed-off-by: Jim Wang <[email protected]>
  • Loading branch information
jim-wang-intel authored Jul 25, 2023
1 parent 70986df commit e9743d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit e9743d5

Please sign in to comment.