This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch release-v1.0
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v1.0 by this push:
new 198d193e9 fix(dora): use table incidents to make connection with
deployments (#7806) (#7807)
198d193e9 is described below
commit 198d193e9143b1b0945788ccf8e91ec2971f0d7b
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jul 31 21:33:03 2024 +0800
fix(dora): use table incidents to make connection with deployments (#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]>
---
.../dora/e2e/connect_incident_to_deploy_test.go | 9 ++++-----
.../cicd_deployment_commits_after.csv | 17 +++++++++++++++++
.../raw_tables/incidents.csv | 8 ++++++++
.../raw_tables/project_mapping.csv | 9 +++++++++
.../project_incident_deployment_relationships.csv | 7 +++++++
backend/plugins/dora/impl/impl.go | 2 +-
backend/plugins/dora/impl/impl_test.go | 2 +-
.../plugins/dora/tasks/incident_deploy_connector.go | 21 ++++++++-------------
8 files changed, 55 insertions(+), 20 deletions(-)
diff --git a/backend/plugins/dora/e2e/connect_incident_to_deploy_test.go
b/backend/plugins/dora/e2e/connect_incident_to_deploy_test.go
index ed625063d..8af1750fe 100644
--- a/backend/plugins/dora/e2e/connect_incident_to_deploy_test.go
+++ b/backend/plugins/dora/e2e/connect_incident_to_deploy_test.go
@@ -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{}},
})
}
diff --git
a/backend/plugins/dora/e2e/connect_incident_to_deployment/prev_success_deployment_commit/cicd_deployment_commits_after.csv
b/backend/plugins/dora/e2e/connect_incident_to_deployment/prev_success_deployment_commit/cicd_deployment_commits_after.csv
new file mode 100644
index 000000000..2691aa12c
--- /dev/null
+++
b/backend/plugins/dora/e2e/connect_incident_to_deployment/prev_success_deployment_commit/cicd_deployment_commits_after.csv
@@ -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
diff --git
a/backend/plugins/dora/e2e/connect_incident_to_deployment/raw_tables/incidents.csv
b/backend/plugins/dora/e2e/connect_incident_to_deployment/raw_tables/incidents.csv
new file mode 100644
index 000000000..0281937ca
--- /dev/null
+++
b/backend/plugins/dora/e2e/connect_incident_to_deployment/raw_tables/incidents.csv
@@ -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
diff --git
a/backend/plugins/dora/e2e/connect_incident_to_deployment/raw_tables/project_mapping.csv
b/backend/plugins/dora/e2e/connect_incident_to_deployment/raw_tables/project_mapping.csv
new file mode 100644
index 000000000..296ab9e2f
--- /dev/null
+++
b/backend/plugins/dora/e2e/connect_incident_to_deployment/raw_tables/project_mapping.csv
@@ -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
\ No newline at end of file
diff --git
a/backend/plugins/dora/e2e/connect_incident_to_deployment/snapshot_tables/project_incident_deployment_relationships.csv
b/backend/plugins/dora/e2e/connect_incident_to_deployment/snapshot_tables/project_incident_deployment_relationships.csv
new file mode 100644
index 000000000..22d9d6eed
--- /dev/null
+++
b/backend/plugins/dora/e2e/connect_incident_to_deployment/snapshot_tables/project_incident_deployment_relationships.csv
@@ -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
diff --git a/backend/plugins/dora/impl/impl.go
b/backend/plugins/dora/impl/impl.go
index a0764a962..bd464ee8b 100644
--- a/backend/plugins/dora/impl/impl.go
+++ b/backend/plugins/dora/impl/impl.go
@@ -160,8 +160,8 @@ func (p Dora) MakeMetricPluginPipelinePlanV200(projectName
string, options json.
},
Subtasks: []string{
"calculateChangeLeadTime",
- "ConnectIncidentToDeployment",
tasks.IssuesToIncidentsMeta.Name,
+ "ConnectIncidentToDeployment",
},
},
},
diff --git a/backend/plugins/dora/impl/impl_test.go
b/backend/plugins/dora/impl/impl_test.go
index 54cc7d5c4..7719d09e5 100644
--- a/backend/plugins/dora/impl/impl_test.go
+++ b/backend/plugins/dora/impl/impl_test.go
@@ -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},
},
diff --git a/backend/plugins/dora/tasks/incident_deploy_connector.go
b/backend/plugins/dora/tasks/incident_deploy_connector.go
index 9dc70f812..be6d9e597 100644
--- a/backend/plugins/dora/tasks/incident_deploy_connector.go
+++ b/backend/plugins/dora/tasks/incident_deploy_connector.go
@@ -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)
@@ -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 {
@@ -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,
}
@@ -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),