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

fix(dora): add more log in task ConnectIncidentToDeployment #7854

Merged
merged 1 commit into from
Aug 7, 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
10 changes: 8 additions & 2 deletions backend/plugins/dora/tasks/incident_deploy_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ type simpleCicdDeploymentCommit struct {
func ConnectIncidentToDeployment(taskCtx plugin.SubTaskContext) errors.Error {
db := taskCtx.GetDal()
data := taskCtx.GetData().(*DoraTaskData)
logger := taskCtx.GetLogger()
// Clear previous results from the project
err := db.Exec("DELETE FROM project_incident_deployment_relationships WHERE project_name = ?", data.Options.ProjectName)
if err != nil {
return errors.Default.Wrap(err, "error deleting previous project_incident_deployment_relationships")
}
logger.Info("delete previous project_incident_deployment_relationships")
// select all issues belongs to the board
clauses := []dal.Clause{
dal.From(`incidents i`),
Expand All @@ -61,10 +63,11 @@ func ConnectIncidentToDeployment(taskCtx plugin.SubTaskContext) errors.Error {
}
cursor, err := db.Cursor(clauses...)
if err != nil {
logger.Error(err, "db.cursor error")
return err
}
defer cursor.Close()

logger.Info("start enricher")
enricher, err := api.NewDataConverter(api.DataConverterArgs{
RawDataSubTaskArgs: api.RawDataSubTaskArgs{
Ctx: taskCtx,
Expand All @@ -83,7 +86,7 @@ func ConnectIncidentToDeployment(taskCtx plugin.SubTaskContext) errors.Error {
},
ProjectName: data.Options.ProjectName,
}

logger.Info("get incident: %+v", incident.Id)
cicdDeploymentCommit := &devops.CicdDeploymentCommit{}
cicdDeploymentCommitClauses := []dal.Clause{
dal.Select("cicd_deployment_commits.cicd_deployment_id as id, cicd_deployment_commits.finished_date as finished_date"),
Expand All @@ -105,15 +108,18 @@ func ConnectIncidentToDeployment(taskCtx plugin.SubTaskContext) errors.Error {
err = db.All(scdc, cicdDeploymentCommitClauses...)
if err != nil {
if db.IsErrorNotFound(err) {
logger.Warn(err, "deployment commit not found")
return nil, nil
} else {
logger.Error(err, "get all deployment commits")
return nil, err
}
}
if scdc.Id != "" {
projectIssueMetric.DeploymentId = scdc.Id
return []interface{}{projectIssueMetric}, nil
}
logger.Info("scdc.id is empty, incident will be ignored: %+v", incident.Id)
return nil, nil
},
})
Expand Down
Loading