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(sonarqube): fix data loss #4477

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
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
38 changes: 15 additions & 23 deletions backend/plugins/sonarqube/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,22 @@ func (p Sonarqube) PrepareTaskData(taskCtx plugin.TaskContext, options map[strin
Options: op,
ApiClient: apiClient,
}
if op.ProjectKey != "" {
var scope *models.SonarqubeProject
var apiProject *tasks.SonarqubeApiProject
// support v100 & advance mode
// If we still cannot find the record in db, we have to request from remote server and save it to db
db := taskCtx.GetDal()
err = db.First(&scope, dal.Where("connection_id = ? AND project_key = ?", op.ConnectionId, op.ProjectKey))
if err != nil && db.IsErrorNotFound(err) {
apiProject, err = api.GetApiProject(op.ProjectKey, apiClient)
if err != nil {
return nil, err
}
logger.Debug(fmt.Sprintf("Current project: %s", apiProject.ProjectKey))
scope = tasks.ConvertProject(apiProject)
scope.ConnectionId = op.ConnectionId
err = taskCtx.GetDal().CreateIfNotExist(&scope)
if err != nil {
return nil, err
}
}
if err != nil {
return nil, errors.Default.Wrap(err, fmt.Sprintf("fail to find project: %s", op.ProjectKey))
}
// even we have project in _tool_sonaqube_projects, we still need to collect project to update LastAnalysisDate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? what column updated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the date will be updated each time, maybe we should split the model into 2 model

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this come from the same api. Hmm, maybe we don't need to update the model, just set the value to taskData

var scope *models.SonarqubeProject
var apiProject *tasks.SonarqubeApiProject
apiProject, err = api.GetApiProject(op.ProjectKey, apiClient)
if err != nil {
return nil, err
}
logger.Debug(fmt.Sprintf("Current project: %s", apiProject.ProjectKey))
scope = tasks.ConvertProject(apiProject)
scope.ConnectionId = op.ConnectionId
err = taskCtx.GetDal().CreateOrUpdate(&scope)
if err != nil {
return nil, err
}
taskData.LastAnalysisDate = scope.LastAnalysisDate.ToNullableTime()

var createdDateAfter time.Time
if op.CreatedDateAfter != "" {
createdDateAfter, err = errors.Convert01(time.Parse(time.RFC3339, op.CreatedDateAfter))
Expand Down
1 change: 0 additions & 1 deletion backend/plugins/sonarqube/tasks/issues_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func CollectIssues(taskCtx plugin.SubTaskContext) (err errors.Error) {
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_ISSUES_TABLE)
logger := taskCtx.GetLogger()
logger.Info("collect issues")

collectorWithState, err := helper.NewApiCollectorWithState(*rawDataSubTaskArgs, data.CreatedDateAfter)
if err != nil {
return err
Expand Down
7 changes: 2 additions & 5 deletions backend/plugins/sonarqube/tasks/issues_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"hash"
"strings"

"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/sonarqube/models"
"hash"
"strings"
)

var _ plugin.SubTaskEntryPoint = ExtractIssues
Expand All @@ -45,7 +44,6 @@ func ExtractIssues(taskCtx plugin.SubTaskContext) errors.Error {
if err != nil {
return nil, err
}

sonarqubeIssue := &models.SonarqubeIssue{
ConnectionId: data.Options.ConnectionId,
IssueKey: body.Key,
Expand Down Expand Up @@ -91,7 +89,6 @@ func ExtractIssues(taskCtx plugin.SubTaskContext) errors.Error {
results = append(results, codeBlock)
}
}

return results, nil
},
})
Expand Down
3 changes: 3 additions & 0 deletions devops/releases/lake-v0.14.0/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ services:
MYSQL_DATABASE: lake
MYSQL_USER: merico
MYSQL_PASSWORD: merico
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_bin

grafana:
image: apache/devlake-dashboard:v0.14.0
Expand Down
4 changes: 4 additions & 0 deletions devops/releases/lake-v0.15.0/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ services:
MYSQL_DATABASE: lake
MYSQL_USER: merico
MYSQL_PASSWORD: merico
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_bin


grafana:
image: apache/devlake-dashboard:v0.15.0
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ services:
MYSQL_DATABASE: lake
MYSQL_USER: merico
MYSQL_PASSWORD: merico
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_bin


# postgres:
# image: postgres:14.2
Expand Down