From b4a6a0f82888fe26724a01439cfb279bbf08d589 Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 14 Dec 2022 11:29:10 +0100 Subject: [PATCH] SONAR-13799 Drop deprecated measures counters from `api/project_pull_requests/list` --- .../sonar/server/issue/index/IssueIndex.java | 32 -------- .../server/issue/index/IssueIndexTest.java | 76 ++----------------- .../protobuf/ws-projectpullrequests.proto | 6 +- 3 files changed, 9 insertions(+), 105 deletions(-) diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 25ff1fb637a..5fa48dda090 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -49,7 +49,6 @@ import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.HasAggregations; -import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; @@ -1102,37 +1101,6 @@ public class IssueIndex { .collect(MoreCollectors.toList(projectUuids.size())); } - public List searchBranchStatistics(String projectUuid, List branchUuids) { - if (branchUuids.isEmpty()) { - return Collections.emptyList(); - } - - SearchSourceBuilder sourceBuilder = new SearchSourceBuilder() - .query( - boolQuery() - .must(termsQuery(FIELD_ISSUE_BRANCH_UUID, branchUuids)) - .mustNot(existsQuery(FIELD_ISSUE_RESOLUTION)) - .must(termQuery(FIELD_ISSUE_IS_MAIN_BRANCH, Boolean.toString(false)))) - .size(0) - .aggregation(AggregationBuilders.terms("branchUuids") - .field(FIELD_ISSUE_BRANCH_UUID) - .size(branchUuids.size()) - .subAggregation(AggregationBuilders.terms("types") - .field(FIELD_ISSUE_TYPE))); - - SearchRequest requestBuilder = EsClient.prepareSearch(TYPE_ISSUE.getMainType()) - .routing(AuthorizationDoc.idOf(projectUuid)); - - requestBuilder.source(sourceBuilder); - SearchResponse response = client.search(requestBuilder); - return ((ParsedStringTerms) response.getAggregations().get("branchUuids")).getBuckets().stream() - .map(bucket -> new PrStatistics(bucket.getKeyAsString(), - ((ParsedStringTerms) bucket.getAggregations().get("types")).getBuckets() - .stream() - .collect(uniqueIndex(MultiBucketsAggregation.Bucket::getKeyAsString, MultiBucketsAggregation.Bucket::getDocCount)))) - .collect(MoreCollectors.toList(branchUuids.size())); - } - /** * @deprecated SansTop25 report is outdated and will be removed in future versions */ diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java index 4d26ed316be..8c043d1bfa8 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java @@ -23,10 +23,8 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.List; -import java.util.stream.IntStream; import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.TotalHits.Relation; -import org.assertj.core.groups.Tuple; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.search.SearchHit; import org.junit.Test; @@ -43,11 +41,6 @@ import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; -import static org.assertj.core.api.Assertions.tuple; -import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; -import static org.sonar.api.rules.RuleType.BUG; -import static org.sonar.api.rules.RuleType.CODE_SMELL; -import static org.sonar.api.rules.RuleType.VULNERABILITY; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; import static org.sonar.db.user.GroupTesting.newGroupDto; @@ -88,7 +81,7 @@ public class IssueIndexTest extends IssueIndexTestCommon { String key = "I" + i; issues.add(newDoc(key, file)); } - indexIssues(issues.toArray(new IssueDoc[]{})); + indexIssues(issues.toArray(new IssueDoc[] {})); IssueQuery.Builder query = IssueQuery.builder(); SearchResponse result = underTest.search(query.build(), new SearchOptions().setLimit(500)); @@ -105,7 +98,7 @@ public class IssueIndexTest extends IssueIndexTestCommon { String key = "I" + i; issues.add(newDoc(key, file)); } - indexIssues(issues.toArray(new IssueDoc[]{})); + indexIssues(issues.toArray(new IssueDoc[] {})); IssueQuery.Builder query = IssueQuery.builder(); SearchResponse result = underTest.search(query.build(), new SearchOptions().setLimit(500)); @@ -119,12 +112,12 @@ public class IssueIndexTest extends IssueIndexTestCommon { ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); List issues = new ArrayList<>(); - //we are adding issues in reverse order to see if the sort is actually doing anything + // we are adding issues in reverse order to see if the sort is actually doing anything for (int i = 9; i >= 1; i--) { String key = "I" + i; issues.add(newDoc(key, file)); } - indexIssues(issues.toArray(new IssueDoc[]{})); + indexIssues(issues.toArray(new IssueDoc[] {})); IssueQuery.Builder query = IssueQuery.builder().asc(true); SearchResponse result = underTest.search(query.sort(IssueQuery.SORT_BY_CREATION_DATE).build(), new SearchOptions()); @@ -140,12 +133,12 @@ public class IssueIndexTest extends IssueIndexTestCommon { ComponentDto project = newPrivateProjectDto(); ComponentDto file = newFileDto(project, null); List issues = new ArrayList<>(); - //we are adding issues in reverse order to see if the sort is actually doing anything + // we are adding issues in reverse order to see if the sort is actually doing anything for (int i = 9; i >= 1; i--) { String key = "I" + i; issues.add(newDoc(key, file)); } - indexIssues(issues.toArray(new IssueDoc[]{})); + indexIssues(issues.toArray(new IssueDoc[] {})); IssueQuery.Builder query = IssueQuery.builder().asc(true); SearchResponse result = underTest.search(query.sort(IssueQuery.SORT_BY_CREATION_DATE).build(), new SearchOptions()); @@ -294,63 +287,6 @@ public class IssueIndexTest extends IssueIndexTestCommon { assertThat(underTest.countTags(projectQuery("other"), 10)).isEmpty(); } - @Test - public void searchBranchStatistics() { - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch1 = db.components().insertProjectBranch(project); - ComponentDto branch2 = db.components().insertProjectBranch(project); - ComponentDto branch3 = db.components().insertProjectBranch(project); - ComponentDto fileOnBranch3 = db.components().insertComponent(newFileDto(branch3)); - indexIssues(newDoc(project), - newDoc(branch1).setType(BUG).setResolution(null), newDoc(branch1).setType(VULNERABILITY).setResolution(null), newDoc(branch1).setType(CODE_SMELL).setResolution(null), - newDoc(branch1).setType(CODE_SMELL).setResolution(RESOLUTION_FIXED), - newDoc(branch3).setType(CODE_SMELL).setResolution(null), newDoc(branch3).setType(CODE_SMELL).setResolution(null), - newDoc(fileOnBranch3).setType(CODE_SMELL).setResolution(null), newDoc(fileOnBranch3).setType(CODE_SMELL).setResolution(RESOLUTION_FIXED)); - - List prStatistics = underTest.searchBranchStatistics(project.uuid(), asList(branch1.uuid(), branch2.uuid(), branch3.uuid())); - - assertThat(prStatistics).extracting(PrStatistics::getBranchUuid, PrStatistics::getBugs, PrStatistics::getVulnerabilities, PrStatistics::getCodeSmells) - .containsExactlyInAnyOrder( - tuple(branch1.uuid(), 1L, 1L, 1L), - tuple(branch3.uuid(), 0L, 0L, 3L)); - } - - @Test - public void searchBranchStatistics_on_many_branches() { - ComponentDto project = db.components().insertPublicProject(); - List branchUuids = new ArrayList<>(); - List expectedResult = new ArrayList<>(); - IntStream.range(0, 15).forEach(i -> { - ComponentDto branch = db.components().insertProjectBranch(project); - addIssues(branch, 1 + i, 2 + i, 3 + i); - expectedResult.add(tuple(branch.uuid(), 1L + i, 2L + i, 3L + i)); - branchUuids.add(branch.uuid()); - }); - - List prStatistics = underTest.searchBranchStatistics(project.uuid(), branchUuids); - - assertThat(prStatistics) - .extracting(PrStatistics::getBranchUuid, PrStatistics::getBugs, PrStatistics::getVulnerabilities, PrStatistics::getCodeSmells) - .hasSize(15) - .containsAll(expectedResult); - } - - @Test - public void searchBranchStatistics_on_empty_list() { - ComponentDto project = db.components().insertPublicProject(); - - assertThat(underTest.searchBranchStatistics(project.uuid(), emptyList())).isEmpty(); - assertThat(underTest.searchBranchStatistics(project.uuid(), singletonList("unknown"))).isEmpty(); - } - - private void addIssues(ComponentDto component, int bugs, int vulnerabilities, int codeSmelles) { - List issues = new ArrayList<>(); - IntStream.range(0, bugs).forEach(b -> issues.add(newDoc(component).setType(BUG).setResolution(null))); - IntStream.range(0, vulnerabilities).forEach(v -> issues.add(newDoc(component).setType(VULNERABILITY).setResolution(null))); - IntStream.range(0, codeSmelles).forEach(c -> issues.add(newDoc(component).setType(CODE_SMELL).setResolution(null))); - indexIssues(issues.toArray(new IssueDoc[0])); - } - private IssueQuery projectQuery(String projectUuid) { return IssueQuery.builder().projectUuids(singletonList(projectUuid)).resolved(false).build(); } diff --git a/sonar-ws/src/main/protobuf/ws-projectpullrequests.proto b/sonar-ws/src/main/protobuf/ws-projectpullrequests.proto index cad1acf8e58..bf0d871ae81 100644 --- a/sonar-ws/src/main/protobuf/ws-projectpullrequests.proto +++ b/sonar-ws/src/main/protobuf/ws-projectpullrequests.proto @@ -45,7 +45,7 @@ message PullRequest { message Status { optional string qualityGateStatus = 1; - optional int64 bugs = 2; - optional int64 vulnerabilities = 3; - optional int64 codeSmells = 4; + reserved 2; // drop bugs field + reserved 3; // drop vulnerabilities field + reserved 4; // drop codeSmells field } -- 2.39.5