diff options
author | Michal Duda <michal.duda@sonarsource.com> | 2021-03-01 17:48:43 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-03-04 20:12:49 +0000 |
commit | 4c007c151c20a92ed5d76ce5ac04bae53919586e (patch) | |
tree | 46ebcf58d5bc7949c513d54b9ebb1feae5df8f1c /server/sonar-webserver-core | |
parent | 4558e5786f367160a219fd8bbc1f9872e51ea661 (diff) | |
download | sonarqube-4c007c151c20a92ed5d76ce5ac04bae53919586e.tar.gz sonarqube-4c007c151c20a92ed5d76ce5ac04bae53919586e.zip |
SONAR-14525 include CI usage information in telemetry
Diffstat (limited to 'server/sonar-webserver-core')
4 files changed, 22 insertions, 8 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java index 16354f7b359..8d26cb3300c 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java @@ -139,12 +139,9 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { data.setAlmIntegrationCountByAlm(countAlmUsage(dbSession)); data.setExternalAuthenticationProviders(dbClient.userDao().selectExternalIdentityProviders(dbSession)); - Map<String, Long> projectCountPerScmDetected = dbClient.analysisPropertiesDao() - .selectProjectCountPerAnalysisPropertyValueInLastAnalysis(dbSession, CorePropertyDefinitions.SONAR_ANALYSIS_DETECTEDSCM) - .stream() - .collect(Collectors.toMap(ProjectCountPerAnalysisPropertyValue::getPropertyValue, ProjectCountPerAnalysisPropertyValue::getCount)); - data.setProjectCountByScm(projectCountPerScmDetected); data.setSonarlintWeeklyUsers(dbClient.userDao().countSonarlintWeeklyUsers(dbSession)); + addScmInformationToTelemetry(dbSession, data); + addCiInformationToTelemetry(dbSession, data); } setSecurityCustomConfigIfPresent(data); @@ -174,6 +171,22 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { }); } + private void addScmInformationToTelemetry(DbSession dbSession, TelemetryData.Builder data) { + Map<String, Long> projectCountPerScmDetected = dbClient.analysisPropertiesDao() + .selectProjectCountPerAnalysisPropertyValueInLastAnalysis(dbSession, CorePropertyDefinitions.SONAR_ANALYSIS_DETECTEDSCM) + .stream() + .collect(Collectors.toMap(ProjectCountPerAnalysisPropertyValue::getPropertyValue, ProjectCountPerAnalysisPropertyValue::getCount)); + data.setProjectCountByScm(projectCountPerScmDetected); + } + + private void addCiInformationToTelemetry(DbSession dbSession, TelemetryData.Builder data) { + Map<String, Long> projectCountPerCiDetected = dbClient.analysisPropertiesDao() + .selectProjectCountPerAnalysisPropertyValueInLastAnalysis(dbSession, CorePropertyDefinitions.SONAR_ANALYSIS_DETECTEDCI) + .stream() + .collect(Collectors.toMap(ProjectCountPerAnalysisPropertyValue::getPropertyValue, ProjectCountPerAnalysisPropertyValue::getCount)); + data.setProjectCountByCi(projectCountPerCiDetected); + } + private Map<String, Long> countAlmUsage(DbSession dbSession) { return dbClient.almSettingDao().selectAll(dbSession).stream() .collect(Collectors.groupingBy(almSettingDto -> { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ClusterSystemInfoWriterTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ClusterSystemInfoWriterTest.java index e22bbe0cd20..f90cb0dba9d 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ClusterSystemInfoWriterTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ClusterSystemInfoWriterTest.java @@ -74,8 +74,8 @@ public class ClusterSystemInfoWriterTest { + "\"Search Nodes\":[{\"Name\":\"searchNodes\",\"\":{\"name\":\"searchNodes\"}}]," + "\"Statistics\":{\"id\":\"\",\"version\":\"\",\"database\":{\"name\":\"\",\"version\":\"\"},\"plugins\":[]," + "\"userCount\":0,\"projectCount\":0,\"usingBranches\":false,\"ncloc\":0,\"projectCountByLanguage\":[]," - + "\"nclocByLanguage\":[],\"almIntegrationCount\":[],\"externalAuthProviders\":[],\"projectCountByScm\":[],\"sonarlintWeeklyUsers\":0,\"installationDate\":0," - + "\"installationVersion\":\"\",\"docker\":false}}"); + + "\"nclocByLanguage\":[],\"almIntegrationCount\":[],\"externalAuthProviders\":[],\"projectCountByScm\":[],\"projectCountByCI\":[],\"sonarlintWeeklyUsers\":0," + + "\"installationDate\":0,\"installationVersion\":\"\",\"docker\":false}}"); } private static NodeInfo createNodeInfo(String name) { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java index d9e68091ae1..bd893c90327 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java @@ -81,7 +81,7 @@ public class StandaloneSystemInfoWriterTest { assertThat(writer).hasToString("{\"Health\":\"GREEN\",\"Health Causes\":[],\"Section One\":{\"foo\":\"bar\"},\"Section Two\":{\"one\":1,\"two\":2}," + "\"Statistics\":{\"id\":\"\",\"version\":\"\",\"database\":{\"name\":\"\",\"version\":\"\"},\"plugins\":[],\"userCount\":0,\"projectCount\":0,\"usingBranches\":false," + "\"ncloc\":0,\"projectCountByLanguage\":[],\"nclocByLanguage\":[],\"almIntegrationCount\":[],\"externalAuthProviders\":[],\"projectCountByScm\":[]," - + "\"sonarlintWeeklyUsers\":0,\"installationDate\":0,\"installationVersion\":\"\",\"docker\":false}}"); + + "\"projectCountByCI\":[],\"sonarlintWeeklyUsers\":0,\"installationDate\":0,\"installationVersion\":\"\",\"docker\":false}}"); } private void logInAsSystemAdministrator() { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java index ccf32d67327..4d643f91ac8 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java @@ -68,6 +68,7 @@ public class TelemetryDaemonTest { .setAlmIntegrationCountByAlm(Collections.emptyMap()) .setExternalAuthenticationProviders(singletonList("github")) .setProjectCountByScm(Collections.emptyMap()) + .setProjectCountByCi(Collections.emptyMap()) .setProjectMeasuresStatistics(ProjectMeasuresStatistics.builder() .setProjectCount(12) .setProjectCountByLanguage(Collections.emptyMap()) |