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

Some more verbose/improved error logging for the bootstrap process. #49

Merged
merged 1 commit into from
Jan 14, 2025
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: 4 additions & 1 deletion backend/cmd/web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ var (
}
if bootstrap == true || !initialised {
log.Info("Bootstrap flag set or uninitialised workdir, bootstrapping")
processes.BootstrapEnv(&appConfig)
err := processes.BootstrapEnv(&appConfig)
if err != nil {
log.Errorf("Errors were encountered during bootstrap process. Please check the errorlog for more details.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the err object be printed out, to see details of the error?

}
}
router := web.DefineRoutes(appConfig)

Expand Down
6 changes: 6 additions & 0 deletions backend/internal/database/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func (g GormDatastore) StoreSSMParams(p []config.SSMParameter, owner string) err
model.Value = param.Value
model.Owner = owner

log.WithFields(log.Fields{
"name": param.Name,
"type": param.Type,
"owner": owner,
}).Info("Storing SSM parameter")

// Use Save to insert or update the record
if err := g.db.Save(&model).Error; err != nil {
// Handle error for Save
Expand Down
33 changes: 24 additions & 9 deletions backend/internal/processes/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/unity-sds/unity-management-console/backend/types"
)

func BootstrapEnv(appconf *config.AppConfig) {
func BootstrapEnv(appconf *config.AppConfig) error {
// Print out everything in appConfig
log.Infof("AppConfig contents:")
log.Infof("GithubToken: %s", appconf.GithubToken)
Expand All @@ -36,94 +36,109 @@ func BootstrapEnv(appconf *config.AppConfig) {
for _, item := range appconf.MarketplaceItems {
log.Infof(" - Name: %s, Version: %s", item.Name, item.Version)
}

log.Infof("Creating Local Database")
store, err := database.NewGormDatastore()
if err != nil {
log.WithError(err).Error("Problem creating database")
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
return err
}

log.Infof("Provisioning S3 Bucket")
err = provisionS3(appconf)
if err != nil {
log.WithError(err).Error("Error provisioning S3 bucket")
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
return err
}

log.Infof("Setting Up Default SSM Parameters")
err = storeDefaultSSMParameters(appconf, store)
if err != nil {
log.WithError(err).Error("Error setting SSM Parameters")
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
return err
}

log.Infof("Setting Up Terraform")
err = initTerraform(store, appconf)
if err != nil {
log.WithError(err).Error("Error installing Terraform")
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
return err
}

//r := action.ActRunnerImpl{}
//err = UpdateCoreConfig(appconf, store, nil, "")
//if err != nil {
// log.WithError(err).Error("Problem updating ssm config")
//}

log.Infof("Setting Up HTTPD Gateway from Marketplace")
err = installGateway(store, appconf)
if err != nil {
log.WithError(err).Error("Error installing HTTPD Gateway")
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
return err
}

log.Infof("Setting Up Health Status Lambda")
err = installHealthStatusLambda(store, appconf)
if err != nil {
log.WithError(err).Error("Error installing Health Status")
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
return err
}

log.Infof("Setting Up Basic API Gateway from Marketplace")
err = installBasicAPIGateway(store, appconf)
if err != nil {
log.WithError(err).Error("Error installing API Gateway")
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
return err
}

log.Infof("Setting Up Unity UI from Marketplace")
err = installUnityUi(store, appconf)
if err != nil {
log.WithError(err).Error("Error installing unity-ui")
err = store.AddToAudit(application.Bootstrap_Unsuccessful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
}
return
return err
}

err = store.AddToAudit(application.Bootstrap_Successful, "test")
if err != nil {
log.WithError(err).Error("Problem writing to auditlog")
return err
}

log.Infof("Bootstrap Process Completed Succesfully")
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this return statement necessary? There wasn't a return here previously, and I just wasn't sure if this was a best practice, or it may change some behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh never mind, I see why you are returning now

}

func provisionS3(appConfig *config.AppConfig) error {
Expand Down
Loading