You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by li...@apache.org on 2022/11/23 07:59:35 UTC

[incubator-devlake] branch main updated: fix(dora): use project name as data scope to enrich env (#3785)

This is an automated email from the ASF dual-hosted git repository.

likyh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 912388829 fix(dora): use project name as data scope to enrich env (#3785)
912388829 is described below

commit 91238882972dc864f25c43820af80485d00801b3
Author: Warren Chen <yi...@merico.dev>
AuthorDate: Wed Nov 23 15:59:31 2022 +0800

    fix(dora): use project name as data scope to enrich env (#3785)
---
 plugins/dora/e2e/env_enricher_test.go              | 16 ++++++---
 .../dora/e2e/snapshot_tables/enrich_cicd_tasks.csv | 38 +++++++++++-----------
 plugins/dora/tasks/cicd_task_env_enricher.go       | 15 +++------
 3 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/plugins/dora/e2e/env_enricher_test.go b/plugins/dora/e2e/env_enricher_test.go
index 520156a4a..c3a077b90 100644
--- a/plugins/dora/e2e/env_enricher_test.go
+++ b/plugins/dora/e2e/env_enricher_test.go
@@ -22,7 +22,6 @@ import (
 	"testing"
 
 	"github.com/apache/incubator-devlake/helpers/e2ehelper"
-	"github.com/apache/incubator-devlake/models/common"
 	"github.com/apache/incubator-devlake/models/domainlayer/devops"
 	"github.com/apache/incubator-devlake/plugins/dora/impl"
 	"github.com/apache/incubator-devlake/plugins/dora/tasks"
@@ -49,8 +48,15 @@ func TestEnrichEnvDataFlow(t *testing.T) {
 
 	// verify enrich with repoId
 	dataflowTester.Subtask(tasks.EnrichTaskEnvMeta, taskData)
-	dataflowTester.VerifyTableWithOptions(&devops.CICDTask{}, e2ehelper.TableOptions{
-		CSVRelPath:  "./snapshot_tables/enrich_cicd_tasks.csv",
-		IgnoreTypes: []interface{}{common.NoPKModel{}},
-	})
+	dataflowTester.VerifyTable(
+		&devops.CICDTask{},
+		"./snapshot_tables/enrich_cicd_tasks.csv",
+		[]string{
+			"id",
+			"name",
+			"environment",
+			"type",
+			"cicd_scope_id",
+		},
+	)
 }
diff --git a/plugins/dora/e2e/snapshot_tables/enrich_cicd_tasks.csv b/plugins/dora/e2e/snapshot_tables/enrich_cicd_tasks.csv
index 3c3d03fcb..ee52b8d1d 100644
--- a/plugins/dora/e2e/snapshot_tables/enrich_cicd_tasks.csv
+++ b/plugins/dora/e2e/snapshot_tables/enrich_cicd_tasks.csv
@@ -1,19 +1,19 @@
-id,name,pipeline_id,result,status,type,environment,duration_sec,started_date,finished_date,cicd_scope_id
-task10,deployxIG,pipeline110,SUCCESS,DONE,DEPLOYMENT,PRODUCTION,0,2022-07-19T22:06:28.000+00:00,2022-11-13T22:37:21.000+00:00,cicd1
-task11,deploya,pipeline111,SUCCESS,DONE,DEPLOYMENT,PRODUCTION,0,2022-08-06T14:06:50.000+00:00,2022-11-13T00:07:21.000+00:00,cicd1
-task12,deployc,pipeline112,SUCCESS,DONE,DEPLOYMENT,PRODUCTION,0,2022-08-23T17:44:05.000+00:00,2022-11-02T07:21:09.000+00:00,cicd2
-task13,deploy,pipeline113,SUCCESS,DONE,DEPLOYMENT,PRODUCTION,0,2022-08-30T23:45:29.000+00:00,2022-11-28T00:46:47.000+00:00,cicd1
-task14,deployp0;,pipeline114,SUCCESS,DONE,DEPLOYMENT,PRODUCTION,0,2022-09-07T02:49:26.000+00:00,2022-11-16T20:34:01.000+00:00,cicd1
-task15,deployY{,pipeline115,SUCCESS,DONE,DEPLOYMENT,PRODUCTION,0,2022-09-27T01:07:50.000+00:00,2022-11-19T07:17:33.000+00:00,cicd2
-task16,deploy8',pipeline116,SUCCESS,DONE,DEPLOYMENT,PRODUCTION,0,2022-09-30T21:05:38.000+00:00,2022-11-08T07:56:03.000+00:00,cicd1
-task17,deployKd%,pipeline117,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2022-10-09T06:42:02.000+00:00,,cicd1
-task19,deploy1,pipeline119,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2022-10-24T18:41:04.000+00:00,2022-11-24T04:26:48.000+00:00,cicd1
-task21,deploy^^.,pipeline39,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2004-01-10T03:31:11.000+00:00,2022-11-28T20:41:59.000+00:00,cicd1
-task22,deploy,pipeline35,SUCCESS,DONE,DEPLOYMENT,PRODUCTION,0,2000-10-25T09:57:28.000+00:00,2022-11-28T21:24:02.000+00:00,cicd1
-task23,deploy,pipeline36,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2005-02-07T11:03:27.000+00:00,2022-11-05T18:18:03.000+00:00,cicd1
-task24,deploym,pipeline12,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2015-08-11T19:58:06.000+00:00,2022-11-01T22:31:56.000+00:00,cicd1
-task25,deploy$p<,pipeline26,FAILURE,DONE,,,,2014-02-06T13:42:43.000+00:00,2022-11-30T08:01:38.000+00:00,cicd3
-task26,deployb>@,pipeline20,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2016-08-26T05:41:49.000+00:00,2022-11-15T07:31:46.000+00:00,cicd2
-task27,deployKfn,pipeline37,SUCCESS,DONE,DEPLOYMENT,PRODUCTION,0,2003-12-13T23:19:14.000+00:00,2022-11-11T18:29:31.000+00:00,cicd2
-task28,deployl?,pipeline29,,IN_PROGRESS,DEPLOYMENT,,,2007-01-19T01:13:39.000+00:00,2022-11-24T05:39:46.000+00:00,cicd3
-task29,deployUb,pipeline27,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2006-05-20T18:17:13.000+00:00,2022-11-28T10:13:51.000+00:00,cicd2
+id,name,environment,type,cicd_scope_id
+task10,deployxIG,PRODUCTION,DEPLOYMENT,cicd1
+task11,deploya,PRODUCTION,DEPLOYMENT,cicd1
+task12,deployc,PRODUCTION,DEPLOYMENT,cicd2
+task13,deploy,PRODUCTION,DEPLOYMENT,cicd1
+task14,deployp0;,PRODUCTION,DEPLOYMENT,cicd1
+task15,deployY{,PRODUCTION,DEPLOYMENT,cicd2
+task16,deploy8',PRODUCTION,DEPLOYMENT,cicd1
+task17,deployKd%,PRODUCTION,DEPLOYMENT,cicd1
+task19,deploy1,PRODUCTION,DEPLOYMENT,cicd1
+task21,deploy^^.,PRODUCTION,DEPLOYMENT,cicd1
+task22,deploy,PRODUCTION,DEPLOYMENT,cicd1
+task23,deploy,PRODUCTION,DEPLOYMENT,cicd1
+task24,deploym,PRODUCTION,DEPLOYMENT,cicd1
+task25,deploy$p<,,,cicd3
+task26,deployb>@,PRODUCTION,DEPLOYMENT,cicd2
+task27,deployKfn,PRODUCTION,DEPLOYMENT,cicd2
+task28,deployl?,,DEPLOYMENT,cicd3
+task29,deployUb,PRODUCTION,DEPLOYMENT,cicd2
diff --git a/plugins/dora/tasks/cicd_task_env_enricher.go b/plugins/dora/tasks/cicd_task_env_enricher.go
index 5e1c424e9..cc2de66e5 100644
--- a/plugins/dora/tasks/cicd_task_env_enricher.go
+++ b/plugins/dora/tasks/cicd_task_env_enricher.go
@@ -49,8 +49,8 @@ func EnrichTasksEnv(taskCtx core.SubTaskContext) (err errors.Error) {
 
 	cursor, err := db.Cursor(
 		dal.From(`cicd_tasks ct`),
-		dal.Join("inner join project_mapping pm on pm.row_id = ct.cicd_scope_id and pm.table = ?", "cicd_scopes"),
-		dal.Where(`pm.project_name = ?`, projectName),
+		dal.Join("left join project_mapping pm on pm.row_id = ct.cicd_scope_id"),
+		dal.Where(`pm.project_name = ? and pm.table = ?`, projectName, "cicd_scopes"),
 	)
 
 	if err != nil {
@@ -70,16 +70,11 @@ func EnrichTasksEnv(taskCtx core.SubTaskContext) (err errors.Error) {
 		Input:        cursor,
 		Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
 			cicdTask := inputRow.(*devops.CICDTask)
-			results := make([]interface{}, 0, 1)
-			if productionNamePattern == "" {
+			if productionNamePattern == "" || productionNameRegexp.FindString(cicdTask.Name) != "" {
 				cicdTask.Environment = devops.PRODUCTION
-			} else {
-				if productEnv := productionNameRegexp.FindString(cicdTask.Name); productEnv != "" {
-					cicdTask.Environment = devops.PRODUCTION
-				}
+				return []interface{}{cicdTask}, nil
 			}
-			results = append(results, cicdTask)
-			return results, nil
+			return nil, nil
 		},
 	})
 	if err != nil {