You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by zh...@apache.org on 2023/08/04 07:28:25 UTC
[incubator-devlake] branch release-v0.18 updated: fix: fix test connection timeout and remote api error (#5805) (#5807)
This is an automated email from the ASF dual-hosted git repository.
zhangliang2022 pushed a commit to branch release-v0.18
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v0.18 by this push:
new 3922b17ab fix: fix test connection timeout and remote api error (#5805) (#5807)
3922b17ab is described below
commit 3922b17abbf9e7e8317d849956922d09c3976a0b
Author: Liang Zhang <li...@merico.dev>
AuthorDate: Fri Aug 4 15:28:21 2023 +0800
fix: fix test connection timeout and remote api error (#5805) (#5807)
* fix: fix test connection timeout and remote api error
* fix: bamboo e2e test
* fix: remove one line of comment
---
backend/core/runner/db.go | 11 +++++++--
.../e2e/snapshot_tables/cicd_tasks_deploy.csv | 18 +++++++--------
.../plugins/bamboo/tasks/deploy_build_convertor.go | 6 ++---
backend/plugins/zentao/api/connection.go | 3 ++-
.../plugins/zentao/e2e/check_connection_test.go | 3 ++-
.../{register.go => 20230803_drop_total_real.go} | 27 ++++++++++++----------
.../zentao/models/migrationscripts/register.go | 1 +
backend/plugins/zentao/models/project.go | 1 -
8 files changed, 41 insertions(+), 29 deletions(-)
diff --git a/backend/core/runner/db.go b/backend/core/runner/db.go
index a255fa761..0a98704a4 100644
--- a/backend/core/runner/db.go
+++ b/backend/core/runner/db.go
@@ -18,6 +18,7 @@ limitations under the License.
package runner
import (
+ "context"
"fmt"
"net/url"
"strings"
@@ -127,10 +128,16 @@ func getDbConnection(dbUrl string, conf *gorm.Config) (*gorm.DB, error) {
}
}
-func CheckDbConnection(dbUrl string) errors.Error {
+func CheckDbConnection(dbUrl string, d time.Duration) errors.Error {
db, err := getDbConnection(dbUrl, &gorm.Config{})
if err != nil {
return errors.Convert(err)
}
- return errors.Convert(db.Exec("SELECT 1").Error)
+ ctx := context.Background()
+ if d > 0 {
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithTimeout(context.Background(), d)
+ defer cancel()
+ }
+ return errors.Convert(db.WithContext(ctx).Exec("SELECT 1").Error)
}
diff --git a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_tasks_deploy.csv b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_tasks_deploy.csv
index 5ba0f3921..93013c323 100644
--- a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_tasks_deploy.csv
+++ b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_tasks_deploy.csv
@@ -1,10 +1,10 @@
id,name,pipeline_id,result,status,type,environment,duration_sec,started_date,finished_date,cicd_scope_id
-bamboo:BambooDeployBuild:1:1769473,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:15:45.000+00:00,2023-03-10T12:15:46.000+00:00,bamboo:BambooProject:1:TEST1
-bamboo:BambooDeployBuild:1:1769474,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:27:28.000+00:00,2023-03-10T12:27:28.000+00:00,bamboo:BambooProject:1:TEST1
-bamboo:BambooDeployBuild:1:1769475,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:27:56.000+00:00,2023-03-10T12:27:56.000+00:00,bamboo:BambooProject:1:TEST1
-bamboo:BambooDeployBuild:1:1769476,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:28:12.000+00:00,2023-03-10T12:28:12.000+00:00,bamboo:BambooProject:1:TEST1
-bamboo:BambooDeployBuild:1:1769477,release-1,bamboo:BambooPlanBuild:1:TEST1-TEST1,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:29:08.000+00:00,2023-03-10T12:29:09.000+00:00,bamboo:BambooProject:1:TEST1
-bamboo:BambooDeployBuild:1:1769478,release-1,bamboo:BambooPlanBuild:1:TEST1-TEST1,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:29:28.000+00:00,2023-03-10T12:29:28.000+00:00,bamboo:BambooProject:1:TEST1
-bamboo:BambooDeployBuild:1:1769479,release-3,bamboo:BambooPlanBuild:1:TEST1-TEST1,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:30:37.000+00:00,2023-03-10T12:30:37.000+00:00,bamboo:BambooProject:1:TEST1
-bamboo:BambooDeployBuild:1:1769480,release-3,bamboo:BambooPlanBuild:1:TEST1-TEST1,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:30:49.000+00:00,2023-03-10T12:30:49.000+00:00,bamboo:BambooProject:1:TEST1
-bamboo:BambooDeployBuild:1:1769481,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,,IN_PROGRESS,DEPLOYMENT,PRODUCTION,0,2023-03-13T09:43:26.000+00:00,2023-03-13T09:43:26.000+00:00,bamboo:BambooProject:1:TEST1
+bamboo:BambooDeployBuild:1:1769473,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:15:45.000+00:00,2023-03-10T12:15:46.000+00:00,bamboo:BambooProject:1:TEST1
+bamboo:BambooDeployBuild:1:1769474,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:27:28.000+00:00,2023-03-10T12:27:28.000+00:00,bamboo:BambooProject:1:TEST1
+bamboo:BambooDeployBuild:1:1769475,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:27:56.000+00:00,2023-03-10T12:27:56.000+00:00,bamboo:BambooProject:1:TEST1
+bamboo:BambooDeployBuild:1:1769476,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:28:12.000+00:00,2023-03-10T12:28:12.000+00:00,bamboo:BambooProject:1:TEST1
+bamboo:BambooDeployBuild:1:1769477,release-1,bamboo:BambooPlanBuild:1:TEST1-TEST1,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:29:08.000+00:00,2023-03-10T12:29:09.000+00:00,bamboo:BambooProject:1:TEST1
+bamboo:BambooDeployBuild:1:1769478,release-1,bamboo:BambooPlanBuild:1:TEST1-TEST1,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:29:28.000+00:00,2023-03-10T12:29:28.000+00:00,bamboo:BambooProject:1:TEST1
+bamboo:BambooDeployBuild:1:1769479,release-3,bamboo:BambooPlanBuild:1:TEST1-TEST1,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:30:37.000+00:00,2023-03-10T12:30:37.000+00:00,bamboo:BambooProject:1:TEST1
+bamboo:BambooDeployBuild:1:1769480,release-3,bamboo:BambooPlanBuild:1:TEST1-TEST1,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2023-03-10T12:30:49.000+00:00,2023-03-10T12:30:49.000+00:00,bamboo:BambooProject:1:TEST1
+bamboo:BambooDeployBuild:1:1769481,release-2,bamboo:BambooPlanBuild:1:TEST1-TEST1,FAILURE,DONE,DEPLOYMENT,PRODUCTION,0,2023-03-13T09:43:26.000+00:00,2023-03-13T09:43:26.000+00:00,bamboo:BambooProject:1:TEST1
diff --git a/backend/plugins/bamboo/tasks/deploy_build_convertor.go b/backend/plugins/bamboo/tasks/deploy_build_convertor.go
index 92ac75a5e..a0ada3719 100644
--- a/backend/plugins/bamboo/tasks/deploy_build_convertor.go
+++ b/backend/plugins/bamboo/tasks/deploy_build_convertor.go
@@ -76,13 +76,13 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext) errors.Error {
Name: deployBuild.DeploymentVersionName,
Result: devops.GetResult(&devops.ResultRule{
- Failed: []string{"Failed"},
- Success: []string{"Successful"},
+ Failed: []string{"Failed", "FAILED"},
+ Success: []string{"Successful", "SUCCESSFUL"},
Default: "",
}, deployBuild.DeploymentState),
Status: devops.GetStatus(&devops.StatusRule{
- Done: []string{"Finished"},
+ Done: []string{"Finished", "FINISHED"},
Default: devops.IN_PROGRESS,
}, deployBuild.LifeCycleState),
diff --git a/backend/plugins/zentao/api/connection.go b/backend/plugins/zentao/api/connection.go
index 9c3fb608d..8bc9fee04 100644
--- a/backend/plugins/zentao/api/connection.go
+++ b/backend/plugins/zentao/api/connection.go
@@ -21,6 +21,7 @@ import (
"context"
"github.com/apache/incubator-devlake/core/runner"
"net/http"
+ "time"
"github.com/apache/incubator-devlake/server/api/shared"
@@ -67,7 +68,7 @@ func TestConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
return &plugin.ApiResourceOutput{Body: body, Status: http.StatusBadRequest}, nil
}
if connection.DbUrl != "" {
- err = runner.CheckDbConnection(connection.DbUrl)
+ err = runner.CheckDbConnection(connection.DbUrl, 5*time.Second)
if err != nil {
body.Success = false
body.Message = "invalid DbUrl"
diff --git a/backend/plugins/zentao/e2e/check_connection_test.go b/backend/plugins/zentao/e2e/check_connection_test.go
index 69a01c7ba..5b703003a 100644
--- a/backend/plugins/zentao/e2e/check_connection_test.go
+++ b/backend/plugins/zentao/e2e/check_connection_test.go
@@ -20,6 +20,7 @@ package e2e
import (
"github.com/apache/incubator-devlake/core/runner"
"testing"
+ "time"
"github.com/apache/incubator-devlake/core/config"
)
@@ -30,7 +31,7 @@ func TestZentaoCheckDbConnection(t *testing.T) {
if dbUrl == "" {
return
}
- err := runner.CheckDbConnection(dbUrl)
+ err := runner.CheckDbConnection(dbUrl, 10*time.Second)
if err != nil {
t.Error(err)
}
diff --git a/backend/plugins/zentao/models/migrationscripts/register.go b/backend/plugins/zentao/models/migrationscripts/20230803_drop_total_real.go
similarity index 58%
copy from backend/plugins/zentao/models/migrationscripts/register.go
copy to backend/plugins/zentao/models/migrationscripts/20230803_drop_total_real.go
index 4fdfac508..d7ba64229 100644
--- a/backend/plugins/zentao/models/migrationscripts/register.go
+++ b/backend/plugins/zentao/models/migrationscripts/20230803_drop_total_real.go
@@ -18,18 +18,21 @@ limitations under the License.
package migrationscripts
import (
- "github.com/apache/incubator-devlake/core/plugin"
+ "github.com/apache/incubator-devlake/core/context"
+ "github.com/apache/incubator-devlake/core/errors"
+ "github.com/apache/incubator-devlake/plugins/zentao/models/migrationscripts/archived"
)
-// All return all the migration scripts
-func All() []plugin.MigrationScript {
- return []plugin.MigrationScript{
- new(addInitTables),
- new(addScopeConfigTables),
- new(addIssueRepoCommitsTables),
- new(addInitChangelogTables),
- new(addTaskLeft),
- new(addExecutionStoryAndExecutionSummary),
- new(addRawParamTableForScope),
- }
+type dropTotalReal struct{}
+
+func (*dropTotalReal) Up(basicRes context.BasicRes) errors.Error {
+ return basicRes.GetDal().DropColumns(archived.ZentaoProject{}.TableName(), "total_real")
+}
+
+func (*dropTotalReal) Version() uint64 {
+ return 20230803145723
+}
+
+func (*dropTotalReal) Name() string {
+ return "drop the column total_real from the table _tool_zentao_projects"
}
diff --git a/backend/plugins/zentao/models/migrationscripts/register.go b/backend/plugins/zentao/models/migrationscripts/register.go
index 4fdfac508..914eb1f11 100644
--- a/backend/plugins/zentao/models/migrationscripts/register.go
+++ b/backend/plugins/zentao/models/migrationscripts/register.go
@@ -31,5 +31,6 @@ func All() []plugin.MigrationScript {
new(addTaskLeft),
new(addExecutionStoryAndExecutionSummary),
new(addRawParamTableForScope),
+ new(dropTotalReal),
}
}
diff --git a/backend/plugins/zentao/models/project.go b/backend/plugins/zentao/models/project.go
index f99aea130..241fbf494 100644
--- a/backend/plugins/zentao/models/project.go
+++ b/backend/plugins/zentao/models/project.go
@@ -93,7 +93,6 @@ type ZentaoProject struct {
TotalConsumed float64 `json:"totalConsumed" mapstructure:"totalConsumed"`
TotalLeft float64 `json:"totalLeft" mapstructure:"totalLeft"`
Progress float64 `json:"progress" mapstructure:"progress"`
- TotalReal int `json:"totalReal" mapstructure:"totalReal"`
ScopeConfigId uint64 `json:"scopeConfigId,omitempty" mapstructure:"scopeConfigId"`
}
type PM struct {