aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-core
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2021-02-26 15:03:43 +0100
committersonartech <sonartech@sonarsource.com>2021-03-04 20:12:49 +0000
commitbd5b4a869dfe128ccbebc86af58c4a4bb77962e1 (patch)
tree05afc91040043017e2252eaa82d93a0c1a63c950 /server/sonar-webserver-core
parentd59b2466752eed8e91f178a346b5da9b86e80d3e (diff)
downloadsonarqube-bd5b4a869dfe128ccbebc86af58c4a4bb77962e1.tar.gz
sonarqube-bd5b4a869dfe128ccbebc86af58c4a4bb77962e1.zip
SONAR-14525 include SCM usage information in telemetry
Diffstat (limited to 'server/sonar-webserver-core')
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java14
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ClusterSystemInfoWriterTest.java18
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java20
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java15
4 files changed, 37 insertions, 30 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 266a6db942a..c944b32e857 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
@@ -32,6 +32,7 @@ import javax.annotation.Nullable;
import org.sonar.api.config.Configuration;
import org.sonar.api.platform.Server;
import org.sonar.api.server.ServerSide;
+import org.sonar.core.config.CorePropertyDefinitions;
import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
@@ -40,6 +41,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.alm.setting.ALM;
import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.component.ProjectCountPerAnalysisPropertyValue;
import org.sonar.db.measure.SumNclocDbQuery;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.measure.index.ProjectMeasuresIndex;
@@ -74,13 +76,13 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader {
private final LicenseReader licenseReader;
public TelemetryDataLoaderImpl(Server server, DbClient dbClient, PluginRepository pluginRepository, UserIndex userIndex, ProjectMeasuresIndex projectMeasuresIndex,
- PlatformEditionProvider editionProvider, InternalProperties internalProperties, Configuration configuration, DockerSupport dockerSupport) {
+ PlatformEditionProvider editionProvider, InternalProperties internalProperties, Configuration configuration, DockerSupport dockerSupport) {
this(server, dbClient, pluginRepository, userIndex, projectMeasuresIndex, editionProvider, internalProperties, configuration, dockerSupport, null);
}
public TelemetryDataLoaderImpl(Server server, DbClient dbClient, PluginRepository pluginRepository, UserIndex userIndex, ProjectMeasuresIndex projectMeasuresIndex,
- PlatformEditionProvider editionProvider, InternalProperties internalProperties, Configuration configuration,
- DockerSupport dockerSupport, @Nullable LicenseReader licenseReader) {
+ PlatformEditionProvider editionProvider, InternalProperties internalProperties, Configuration configuration,
+ DockerSupport dockerSupport, @Nullable LicenseReader licenseReader) {
this.server = server;
this.dbClient = dbClient;
this.pluginRepository = pluginRepository;
@@ -137,7 +139,11 @@ 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);
}
setSecurityCustomConfigIfPresent(data);
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 f3096ecfe32..560e4461f19 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
@@ -42,13 +42,13 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ClusterSystemInfoWriterTest {
- private GlobalInfoLoader globalInfoLoader = mock(GlobalInfoLoader.class);
- private AppNodesInfoLoader appNodesInfoLoader = mock(AppNodesInfoLoader.class);
- private SearchNodesInfoLoader searchNodesInfoLoader = mock(SearchNodesInfoLoader.class);
- private HealthChecker healthChecker = mock(HealthChecker.class);
- private TelemetryDataLoader telemetry = mock(TelemetryDataLoader.class, Mockito.RETURNS_MOCKS);
- private TelemetryDataJsonWriter dataJsonWriter = new TelemetryDataJsonWriter();
- private ClusterSystemInfoWriter underTest = new ClusterSystemInfoWriter(globalInfoLoader, appNodesInfoLoader,
+ private final GlobalInfoLoader globalInfoLoader = mock(GlobalInfoLoader.class);
+ private final AppNodesInfoLoader appNodesInfoLoader = mock(AppNodesInfoLoader.class);
+ private final SearchNodesInfoLoader searchNodesInfoLoader = mock(SearchNodesInfoLoader.class);
+ private final HealthChecker healthChecker = mock(HealthChecker.class);
+ private final TelemetryDataLoader telemetry = mock(TelemetryDataLoader.class, Mockito.RETURNS_MOCKS);
+ private final TelemetryDataJsonWriter dataJsonWriter = new TelemetryDataJsonWriter();
+ private final ClusterSystemInfoWriter underTest = new ClusterSystemInfoWriter(globalInfoLoader, appNodesInfoLoader,
searchNodesInfoLoader, healthChecker, telemetry, dataJsonWriter);
@Before
@@ -68,13 +68,13 @@ public class ClusterSystemInfoWriterTest {
underTest.write(jsonWriter);
jsonWriter.endObject();
- assertThat(writer.toString()).isEqualTo("{\"Health\":\"GREEN\","
+ assertThat(writer).hasToString("{\"Health\":\"GREEN\","
+ "\"Health Causes\":[],\"\":{\"name\":\"globalInfo\"},"
+ "\"Application Nodes\":[{\"Name\":\"appNodes\",\"\":{\"name\":\"appNodes\"}}],"
+ "\"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\":[],\"installationDate\":0,\"installationVersion\":\"\",\"docker\":false}}");
+ "\"nclocByLanguage\":[],\"almIntegrationCount\":[],\"externalAuthProviders\":[],\"projectCountByScm\":[],\"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 a7e99d4f402..c22757e9e81 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
@@ -48,14 +48,13 @@ public class StandaloneSystemInfoWriterTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private SystemInfoSection section1 = mock(SystemInfoSection.class);
- private SystemInfoSection section2 = mock(SystemInfoSection.class);
- private CeHttpClient ceHttpClient = mock(CeHttpClientImpl.class, Mockito.RETURNS_MOCKS);
- private TestStandaloneHealthChecker healthChecker = new TestStandaloneHealthChecker();
- private TelemetryDataLoader telemetry = mock(TelemetryDataLoader.class, Mockito.RETURNS_MOCKS);
- private TelemetryDataJsonWriter dataJsonWriter = new TelemetryDataJsonWriter();
-
- private StandaloneSystemInfoWriter underTest = new StandaloneSystemInfoWriter(telemetry, ceHttpClient, healthChecker, dataJsonWriter, section1, section2);
+ private final SystemInfoSection section1 = mock(SystemInfoSection.class);
+ private final SystemInfoSection section2 = mock(SystemInfoSection.class);
+ private final CeHttpClient ceHttpClient = mock(CeHttpClientImpl.class, Mockito.RETURNS_MOCKS);
+ private final TestStandaloneHealthChecker healthChecker = new TestStandaloneHealthChecker();
+ private final TelemetryDataLoader telemetry = mock(TelemetryDataLoader.class, Mockito.RETURNS_MOCKS);
+ private final TelemetryDataJsonWriter dataJsonWriter = new TelemetryDataJsonWriter();
+ private final StandaloneSystemInfoWriter underTest = new StandaloneSystemInfoWriter(telemetry, ceHttpClient, healthChecker, dataJsonWriter, section1, section2);
@Test
public void write_json() {
@@ -79,10 +78,9 @@ public class StandaloneSystemInfoWriterTest {
underTest.write(jsonWriter);
jsonWriter.endObject();
// response does not contain empty "Section Three"
- assertThat(writer.toString()).isEqualTo("{\"Health\":\"GREEN\",\"Health Causes\":[],\"Section One\":{\"foo\":\"bar\"},\"Section Two\":{\"one\":1,\"two\":2}," +
+ 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\":[],\"installationDate\":0," +
- "\"installationVersion\":\"\",\"docker\":false}}");
+ "\"ncloc\":0,\"projectCountByLanguage\":[],\"nclocByLanguage\":[],\"almIntegrationCount\":[],\"externalAuthProviders\":[],\"projectCountByScm\":[],\"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 423c00cee02..ccf32d67327 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
@@ -35,6 +35,7 @@ import org.sonar.server.property.MapInternalProperties;
import org.sonar.server.util.GlobalLockManager;
import org.sonar.server.util.GlobalLockManagerImpl;
+import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -65,6 +66,8 @@ public class TelemetryDaemonTest {
.setVersion("bar")
.setPlugins(Collections.emptyMap())
.setAlmIntegrationCountByAlm(Collections.emptyMap())
+ .setExternalAuthenticationProviders(singletonList("github"))
+ .setProjectCountByScm(Collections.emptyMap())
.setProjectMeasuresStatistics(ProjectMeasuresStatistics.builder()
.setProjectCount(12)
.setProjectCountByLanguage(Collections.emptyMap())
@@ -76,15 +79,15 @@ public class TelemetryDaemonTest {
.setUsingBranches(true)
.build();
- private TelemetryClient client = mock(TelemetryClient.class);
- private InternalProperties internalProperties = spy(new MapInternalProperties());
+ private final TelemetryClient client = mock(TelemetryClient.class);
+ private final InternalProperties internalProperties = spy(new MapInternalProperties());
private final GlobalLockManager lockManager = mock(GlobalLockManagerImpl.class);
- private TestSystem2 system2 = new TestSystem2().setNow(System.currentTimeMillis());
- private MapSettings settings = new MapSettings();
+ private final TestSystem2 system2 = new TestSystem2().setNow(System.currentTimeMillis());
+ private final MapSettings settings = new MapSettings();
private final TelemetryDataLoader dataLoader = mock(TelemetryDataLoader.class);
private final TelemetryDataJsonWriter dataJsonWriter = mock(TelemetryDataJsonWriter.class);
- private TelemetryDaemon underTest = new TelemetryDaemon(dataLoader, dataJsonWriter, client, settings.asConfig(), internalProperties, lockManager, system2);
+ private final TelemetryDaemon underTest = new TelemetryDaemon(dataLoader, dataJsonWriter, client, settings.asConfig(), internalProperties, lockManager, system2);
@After
public void tearDown() {
@@ -134,7 +137,7 @@ public class TelemetryDaemonTest {
internalProperties.write("telemetry.lastPing", String.valueOf(sevenDaysAgo));
- verify(client, timeout(2_000)).upload(anyString());
+ verify(client, timeout(2_000)).upload(anyString());
verify(dataJsonWriter).writeTelemetryData(any(JsonWriter.class), same(SOME_TELEMETRY_DATA));
}