Skip to content

chore: log errors of ssl generate task (backport #1110) #1111

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

Merged
merged 1 commit into from
Dec 1, 2024
Merged
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
11 changes: 9 additions & 2 deletions swiftwave_service/worker/process_ssl_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

haproxymanager "github.com/swiftwave-org/swiftwave/haproxy_manager"
"github.com/swiftwave-org/swiftwave/swiftwave_service/core"
"github.com/swiftwave-org/swiftwave/swiftwave_service/logger"
"github.com/swiftwave-org/swiftwave/swiftwave_service/manager"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -40,6 +41,7 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
return nil
}
_ = domain.UpdateSSLStatus(ctx, dbWithoutTx, core.DomainSSLStatusFailed)
logger.CronJobLoggerError.Println("Domain", domain.Name, "is not pointing to this server. Marking SSL Issue as failed")
return nil
}
// generate private key [if not found]
Expand All @@ -51,6 +53,7 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
domain.SSLPrivateKey = privateKey
err = domain.Update(ctx, dbWithoutTx)
if err != nil {
logger.CronJobLoggerError.Println("Failed to update domain", domain.Name, "with private key.", err.Error(), "\nWill retry later")
return err
}
}
Expand All @@ -74,11 +77,13 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
// fetch all proxy servers
proxyServers, err := core.FetchProxyActiveServers(&m.ServiceManager.DbClient)
if err != nil {
logger.CronJobLoggerError.Println("Failed to fetch proxy servers while generating SSL certificate", err.Error(), "\nWill retry later")
return err
}
// fetch all haproxy managers
haproxyManagers, err := manager.HAProxyClients(context.Background(), proxyServers)
if err != nil {
logger.CronJobLoggerError.Println("Failed to fetch haproxy managers while generating SSL certificate", err.Error())
return err
}
// map of server ip and transaction id
Expand All @@ -89,13 +94,15 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
// generate a new transaction id for haproxy
transactionId, err := haproxyManager.FetchNewTransactionId()
if err != nil {
logger.CronJobLoggerError.Println("Failed to fetch new transaction id while generating SSL certificate", err.Error(), "\nWill retry later")
return err
}
// add to map
transactionIdMap[haproxyManager] = transactionId
// upload certificate to haproxy
err = haproxyManager.UpdateSSL(transactionId, domain.Name, []byte(domain.SSLPrivateKey), []byte(domain.SSLFullChain))
if err != nil {
logger.CronJobLoggerError.Println("Failed to update SSL certificate while generating SSL certificate", err.Error(), "\nWill retry later")
isFailed = true
break
}
Expand All @@ -107,10 +114,10 @@ func (m Manager) SSLGenerate(request SSLGenerateRequest, ctx context.Context, _
}
if isFailed || err != nil {
isFailed = true
log.Println("failed to commit haproxy transaction", err)
logger.CronJobLoggerError.Println("Failed to commit haproxy transaction while generating SSL certificate", err.Error())
err := haproxyManager.DeleteTransaction(haproxyTransactionId)
if err != nil {
log.Println("failed to rollback haproxy transaction", err)
logger.CronJobLoggerError.Println("Failed to rollback haproxy transaction while generating SSL certificate", err.Error())
}
}
}
Expand Down