aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2020-04-07 15:34:48 +0200
committersonartech <sonartech@sonarsource.com>2020-04-15 20:03:38 +0000
commit712587e8883960d0a91e6b70460d15609d8e9327 (patch)
treec620862901fc28527fb874e61bebcbfd7d60f5a8 /server
parent39e46b040e7c7d60ade26bca89c460ce1dfec0a4 (diff)
downloadsonarqube-712587e8883960d0a91e6b70460d15609d8e9327.tar.gz
sonarqube-712587e8883960d0a91e6b70460d15609d8e9327.zip
SONAR-13188 update telemetry project count query to ignore applications
Diffstat (limited to 'server')
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java4
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java47
2 files changed, 49 insertions, 2 deletions
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
index 029b9ffbca3..820b2c8033a 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/measure/index/ProjectMeasuresIndex.java
@@ -242,7 +242,9 @@ public class ProjectMeasuresIndex {
.setFetchSource(false)
.setSize(0);
- BoolQueryBuilder esFilter = boolQuery();
+ BoolQueryBuilder esFilter = boolQuery()
+ .filter(termQuery(FIELD_INDEX_TYPE, TYPE_PROJECT_MEASURES.getName()))
+ .filter(termQuery(FIELD_QUALIFIER, Qualifiers.PROJECT));
request.setQuery(esFilter);
request.addAggregation(AggregationBuilders.terms(FIELD_LANGUAGES)
.field(FIELD_LANGUAGES)
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
index f8ce765abf6..90887064a9d 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexTest.java
@@ -497,7 +497,7 @@ public class ProjectMeasuresIndexTest {
@Test
public void filter_on_qualifier() {
- index(newDoc(PROJECT1), newDoc(PROJECT2), newDoc(PROJECT3),
+ index(newDoc(PROJECT1), newDoc(PROJECT2), newDoc(PROJECT3),
newDoc(APP1), newDoc(APP2), newDoc(APP3));
assertResults(new ProjectMeasuresQuery(),
@@ -1613,6 +1613,51 @@ public class ProjectMeasuresIndexTest {
}
@Test
+ public void search_statistics_should_ignore_applications() {
+ es.putDocuments(TYPE_PROJECT_MEASURES,
+ // insert projects
+ newDoc(ComponentTesting.newPrivateProjectDto(ORG), "lines", 10, "coverage", 80)
+ .setLanguages(Arrays.asList("java", "cs", "js"))
+ .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 200, "cs", 250, "js", 50)),
+ newDoc(ComponentTesting.newPrivateProjectDto(ORG), "lines", 20, "coverage", 80)
+ .setLanguages(Arrays.asList("java", "python", "kotlin"))
+ .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)),
+
+ // insert applications
+ newDoc(ComponentTesting.newApplication(ORG), "lines", 1000, "coverage", 70)
+ .setLanguages(Arrays.asList("java", "python", "kotlin"))
+ .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)),
+ newDoc(ComponentTesting.newApplication(ORG), "lines", 20, "coverage", 80)
+ .setLanguages(Arrays.asList("java", "python", "kotlin"))
+ .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)));
+
+ ProjectMeasuresStatistics result = underTest.searchTelemetryStatistics();
+
+ assertThat(result.getProjectCount()).isEqualTo(2);
+ assertThat(result.getProjectCountByLanguage()).containsOnly(
+ entry("java", 2L), entry("cs", 1L), entry("js", 1L), entry("python", 1L), entry("kotlin", 1L));
+ assertThat(result.getNclocByLanguage()).containsOnly(
+ entry("java", 500L), entry("cs", 250L), entry("js", 50L), entry("python", 100L), entry("kotlin", 404L));
+ }
+
+ @Test
+ public void search_statistics_should_count_0_if_no_projects() {
+ es.putDocuments(TYPE_PROJECT_MEASURES,
+ // insert applications
+ newDoc(ComponentTesting.newApplication(ORG), "lines", 1000, "coverage", 70)
+ .setLanguages(Arrays.asList("java", "python", "kotlin"))
+ .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)),
+ newDoc(ComponentTesting.newApplication(ORG), "lines", 20, "coverage", 80)
+ .setLanguages(Arrays.asList("java", "python", "kotlin"))
+ .setNclocLanguageDistributionFromMap(ImmutableMap.of("java", 300, "python", 100, "kotlin", 404)));
+
+ ProjectMeasuresStatistics result = underTest.searchTelemetryStatistics();
+
+ assertThat(result.getProjectCount()).isEqualTo(0);
+ assertThat(result.getProjectCountByLanguage()).isEmpty();
+ }
+
+ @Test
public void fail_if_page_size_greater_than_500() {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Page size must be lower than or equals to 500");