Skip to content

Commit

Permalink
fix(dora): use table incidents to make connection with deployments (#…
Browse files Browse the repository at this point in the history
…7806) (#7807)

* fix(dora): use table incidents to make connection with deployments

* fix(dora): fix e2e test

* fix(dora): fix unit test

Co-authored-by: Lynwee <[email protected]>
  • Loading branch information
github-actions[bot] and d4x1 authored Jul 31, 2024
1 parent a6db4ef commit 198d193
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 20 deletions.
9 changes: 4 additions & 5 deletions backend/plugins/dora/e2e/connect_incident_to_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ func TestConnectIncidentToDeploymentDataFlow(t *testing.T) {
},
}
// import raw data table
dataflowTester.ImportCsvIntoTabler("./prev_success_deployment_commit/cicd_deployment_commits_after.csv", &devops.CicdDeploymentCommit{})
dataflowTester.ImportCsvIntoTabler("./raw_tables/project_mapping.csv", &crossdomain.ProjectMapping{})
dataflowTester.ImportCsvIntoTabler("./raw_tables/board_issues.csv", &ticket.BoardIssue{})
dataflowTester.ImportCsvIntoTabler("./raw_tables/issues.csv", &ticket.Issue{})
dataflowTester.ImportCsvIntoTabler("./connect_incident_to_deployment/prev_success_deployment_commit/cicd_deployment_commits_after.csv", &devops.CicdDeploymentCommit{})
dataflowTester.ImportCsvIntoTabler("./connect_incident_to_deployment/raw_tables/project_mapping.csv", &crossdomain.ProjectMapping{})
dataflowTester.ImportCsvIntoTabler("./connect_incident_to_deployment/raw_tables/incidents.csv", &ticket.Incident{})

// verify converter
dataflowTester.FlushTabler(&crossdomain.ProjectIncidentDeploymentRelationship{})
dataflowTester.Subtask(tasks.ConnectIncidentToDeploymentMeta, taskData)
dataflowTester.VerifyTableWithOptions(&crossdomain.ProjectIncidentDeploymentRelationship{}, e2ehelper.TableOptions{
CSVRelPath: "./snapshot_tables/project_incident_deployment_relationships.csv",
CSVRelPath: "./connect_incident_to_deployment/snapshot_tables/project_incident_deployment_relationships.csv",
IgnoreTypes: []interface{}{common.NoPKModel{}},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
id,commit_sha,result,started_date,finished_date,cicd_deployment_id,cicd_scope_id,repo_url,environment,prev_success_deployment_commit_id
1,1,SUCCESS,2022-09-10T06:51:47.000+00:00,2022-09-11T06:51:47.000+00:00,pipeline1,cicd1,REPO111,PRODUCTION,
10,10,SUCCESS,2022-09-13T07:53:31.000+00:00,2022-09-21T06:51:47.000+00:00,pipeline6,cicd1,REPO222,PRODUCTION,6
11,11,FAILURE,2022-09-13T07:54:39.000+00:00,2022-09-22T06:51:47.000+00:00,pipeline7,cicd2,REPO111,PRODUCTION,
12,12,SUCCESS,2022-09-13T07:55:01.000+00:00,2022-09-23T06:51:47.000+00:00,pipeline7,cicd2,REPO333,PRODUCTION,4
13,13,SUCCESS,2022-09-13T07:56:39.000+00:00,2022-09-24T06:51:47.000+00:00,pipeline7,cicd2,REPO111,PRODUCTION,3
14,14,FAILURE,2022-09-13T07:57:26.000+00:00,2022-09-20T06:51:47.000+00:00,pipeline8,cicd3,REPO111,PRODUCTION,
15,15,SUCCESS,2022-09-13T07:57:45.000+00:00,2022-09-14T06:51:47.000+00:00,pipeline9,cicd3,REPO111,PRODUCTION,
16,16,SUCCESS,2022-09-13T07:58:24.000+00:00,2022-09-15T06:51:47.000+00:00,pipeline10,cicd3,REPO333,,
2,2,SUCCESS,2022-09-10T06:53:51.000+00:00,2022-09-12T06:51:47.000+00:00,pipeline1,cicd1,REPO222,PRODUCTION,
3,3,SUCCESS,2022-09-13T07:21:16.000+00:00,2022-09-14T06:51:47.000+00:00,pipeline2,cicd2,REPO111,PRODUCTION,
4,4,SUCCESS,2022-09-13T07:22:14.000+00:00,2022-09-15T06:51:47.000+00:00,pipeline2,cicd2,REPO333,PRODUCTION,
5,5,SUCCESS,2022-09-13T07:28:14.000+00:00,2022-09-16T06:51:47.000+00:00,pipeline4,cicd1,REPO111,PRODUCTION,1
6,6,SUCCESS,2022-09-13T07:29:34.000+00:00,2022-09-17T06:51:47.000+00:00,pipeline4,cicd1,REPO222,PRODUCTION,2
7,7,SUCCESS,2022-09-13T07:31:53.000+00:00,2022-09-18T06:51:47.000+00:00,pipeline5,cicd1,REPO111,STAGING,
8,8,SUCCESS,2022-09-13T07:36:30.000+00:00,2022-09-19T06:51:47.000+00:00,pipeline5,cicd1,REPO111,STAGING,7
9,9,SUCCESS,2022-09-13T07:51:26.000+00:00,2022-09-20T06:51:47.000+00:00,pipeline6,cicd1,REPO111,PRODUCTION,5
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
id,created_date,updated_date,table,scope_id
github:GithubIssue:1:1367714738,2022-11-13 23:37:21,2022-11-15 22:37:21,repos,repo1
github:GithubIssue:1:1370816458,2022-11-13 01:07:21,2022-11-14 00:07:21,repos,repo1
github:GithubIssue:1:1371320153,2022-11-02 08:21:09,2022-11-04 07:21:09,repos,repo1
github:GithubIssue:1:1372381019,2022-11-28 01:46:47,2022-11-29 00:46:47,repos,repo2
github:GithubIssue:1:1372644519,2022-11-16 21:34:01,2022-11-19 20:34:01,repos,repo2
github:GithubIssue:1:1373792477,2022-09-15 01:56:06,2022-09-15 02:13:18,repos,repo3
github:GithubIssue:1:1373792478,2022-09-15 01:56:16,2022-09-15 02:13:18,boards,board1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
project_name,table,row_id
project1,cicd_scopes,cicd1
project1,cicd_scopes,cicd2
project1,repos,repo1
project1,repos,repo2
project2,cicd_scopes,cicd3
project1,boards,board1
project1,boards,board2
project2,boards,board3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id,project_name,deployment_id
github:GithubIssue:1:1367714738,project1,pipeline7
github:GithubIssue:1:1370816458,project1,pipeline7
github:GithubIssue:1:1371320153,project1,pipeline7
github:GithubIssue:1:1372381019,project1,pipeline7
github:GithubIssue:1:1372644519,project1,pipeline7
github:GithubIssue:1:1373792478,project1,pipeline2
2 changes: 1 addition & 1 deletion backend/plugins/dora/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ func (p Dora) MakeMetricPluginPipelinePlanV200(projectName string, options json.
},
Subtasks: []string{
"calculateChangeLeadTime",
"ConnectIncidentToDeployment",
tasks.IssuesToIncidentsMeta.Name,
"ConnectIncidentToDeployment",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion backend/plugins/dora/impl/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func TestMakeMetricPluginPipelinePlanV200(t *testing.T) {
Plugin: "dora",
Subtasks: []string{
"calculateChangeLeadTime",
"ConnectIncidentToDeployment",
tasks.IssuesToIncidentsMeta.Name,
"ConnectIncidentToDeployment",
},
Options: map[string]interface{}{"projectName": projectName},
},
Expand Down
21 changes: 8 additions & 13 deletions backend/plugins/dora/tasks/incident_deploy_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type simpleCicdDeploymentCommit struct {
}

// ConnectIncidentToDeployment will generate data to crossdomain.ProjectIncidentDeploymentRelationship.
// FIXME: it should be generated from Incident.
func ConnectIncidentToDeployment(taskCtx plugin.SubTaskContext) errors.Error {
db := taskCtx.GetDal()
data := taskCtx.GetData().(*DoraTaskData)
Expand All @@ -56,13 +55,9 @@ func ConnectIncidentToDeployment(taskCtx plugin.SubTaskContext) errors.Error {
}
// select all issues belongs to the board
clauses := []dal.Clause{
dal.From(`issues i`),
dal.Join(`left join board_issues bi on bi.issue_id = i.id`),
dal.Join(`left join project_mapping pm on pm.row_id = bi.board_id`),
dal.Where(
"i.type = ? and pm.project_name = ? and pm.table = ?",
"INCIDENT", data.Options.ProjectName, "boards",
),
dal.From(`incidents i`),
dal.Join(`left join project_mapping pm on pm.row_id = i.scope_id and pm.table = i.table`),
dal.Where("pm.project_name = ?", data.Options.ProjectName),
}
cursor, err := db.Cursor(clauses...)
if err != nil {
Expand All @@ -76,15 +71,15 @@ func ConnectIncidentToDeployment(taskCtx plugin.SubTaskContext) errors.Error {
Params: DoraApiParams{
ProjectName: data.Options.ProjectName,
},
Table: "issues",
Table: "incidents",
},
InputRowType: reflect.TypeOf(ticket.Issue{}),
InputRowType: reflect.TypeOf(ticket.Incident{}),
Input: cursor,
Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
issue := inputRow.(*ticket.Issue)
incident := inputRow.(*ticket.Incident)
projectIssueMetric := &crossdomain.ProjectIncidentDeploymentRelationship{
DomainEntity: domainlayer.DomainEntity{
Id: issue.Id,
Id: incident.Id,
},
ProjectName: data.Options.ProjectName,
}
Expand All @@ -100,7 +95,7 @@ func ConnectIncidentToDeployment(taskCtx plugin.SubTaskContext) errors.Error {
and cicd_deployment_commits.environment = ?
and pm.table = ?
and pm.project_name = ?`,
issue.CreatedDate, devops.RESULT_SUCCESS, devops.PRODUCTION, "cicd_scopes", data.Options.ProjectName,
incident.CreatedDate, devops.RESULT_SUCCESS, devops.PRODUCTION, "cicd_scopes", data.Options.ProjectName,
),
dal.Orderby("finished_date DESC"),
dal.Limit(1),
Expand Down

0 comments on commit 198d193

Please sign in to comment.