diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2019-09-26 11:45:26 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-10-08 20:21:04 +0200 |
commit | c595b6fe57b412549892784b6445184e01dc0c08 (patch) | |
tree | 2233c165e0aa85215316251814d98d8aaf9b1457 /server/sonar-webserver-core | |
parent | 73b4994806f23169d2d412b93200a570ef4dff36 (diff) | |
download | sonarqube-c595b6fe57b412549892784b6445184e01dc0c08.tar.gz sonarqube-c595b6fe57b412549892784b6445184e01dc0c08.zip |
SONAR-12487 send docker flag in telemetry
Diffstat (limited to 'server/sonar-webserver-core')
7 files changed, 23 insertions, 15 deletions
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java index 379e7b7eab3..e608a80755e 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java @@ -58,8 +58,7 @@ public class SystemInfoWriterModule extends Module { EsIndexesSection.class, LoggingSection.class, PluginsSection.class, - SettingsSection.class, - DockerSupportImpl.class + SettingsSection.class ); if (standalone) { 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 b31f2b30678..8b888ab79bd 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 @@ -39,6 +39,7 @@ import org.sonar.server.es.SearchOptions; import org.sonar.server.measure.index.ProjectMeasuresIndex; import org.sonar.server.measure.index.ProjectMeasuresStatistics; import org.sonar.server.organization.DefaultOrganizationProvider; +import org.sonar.server.platform.DockerSupport; import org.sonar.server.property.InternalProperties; import org.sonar.server.telemetry.TelemetryData.Database; import org.sonar.server.user.index.UserIndex; @@ -56,17 +57,18 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { private final PlatformEditionProvider editionProvider; private final DefaultOrganizationProvider defaultOrganizationProvider; private final InternalProperties internalProperties; + private final DockerSupport dockerSupport; @CheckForNull private final LicenseReader licenseReader; public TelemetryDataLoaderImpl(Server server, DbClient dbClient, PluginRepository pluginRepository, UserIndex userIndex, ProjectMeasuresIndex projectMeasuresIndex, - PlatformEditionProvider editionProvider, DefaultOrganizationProvider defaultOrganizationProvider, InternalProperties internalProperties) { - this(server, dbClient, pluginRepository, userIndex, projectMeasuresIndex, editionProvider, defaultOrganizationProvider, internalProperties, null); + PlatformEditionProvider editionProvider, DefaultOrganizationProvider defaultOrganizationProvider, InternalProperties internalProperties, DockerSupport dockerSupport) { + this(server, dbClient, pluginRepository, userIndex, projectMeasuresIndex, editionProvider, defaultOrganizationProvider, internalProperties, dockerSupport, null); } public TelemetryDataLoaderImpl(Server server, DbClient dbClient, PluginRepository pluginRepository, UserIndex userIndex, ProjectMeasuresIndex projectMeasuresIndex, PlatformEditionProvider editionProvider, DefaultOrganizationProvider defaultOrganizationProvider, InternalProperties internalProperties, - @Nullable LicenseReader licenseReader) { + DockerSupport dockerSupport, @Nullable LicenseReader licenseReader) { this.server = server; this.dbClient = dbClient; this.pluginRepository = pluginRepository; @@ -74,8 +76,9 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { this.projectMeasuresIndex = projectMeasuresIndex; this.editionProvider = editionProvider; this.defaultOrganizationProvider = defaultOrganizationProvider; - this.licenseReader = licenseReader; this.internalProperties = internalProperties; + this.dockerSupport = dockerSupport; + this.licenseReader = licenseReader; } private static Database loadDatabaseMetadata(DbSession dbSession) { @@ -120,6 +123,7 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { } Optional<String> installationVersionProperty = internalProperties.read(InternalProperties.INSTALLATION_VERSION); data.setInstallationVersion(installationVersionProperty.orElse(null)); + data.setInDocker(dockerSupport.isRunningInDocker()); return data.build(); } 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 60820406733..233bbe2967a 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 @@ -71,7 +71,7 @@ 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\":[],\"installationDate\":0,\"installationVersion\":\"\"}}"); + "\"nclocByLanguage\":[],\"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 1213c87f39f..ad829e7ddf7 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 @@ -79,7 +79,7 @@ public class StandaloneSystemInfoWriterTest { // 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}," + "\"Statistics\":{\"id\":\"\",\"version\":\"\",\"database\":{\"name\":\"\",\"version\":\"\"},\"plugins\":[],\"userCount\":0,\"projectCount\":0,\"usingBranches\":false," + - "\"ncloc\":0,\"projectCountByLanguage\":[],\"nclocByLanguage\":[],\"installationDate\":0,\"installationVersion\":\"\"}}"); + "\"ncloc\":0,\"projectCountByLanguage\":[],\"nclocByLanguage\":[],\"installationDate\":0,\"installationVersion\":\"\",\"docker\":false}}"); } private void logInAsSystemAdministrator() { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java index bf3d7a0f439..5dd35b81d73 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java @@ -42,7 +42,7 @@ public class SystemInfoWriterModuleTest { Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters(); assertThat(adapters) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 18); + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 17); } @Test @@ -54,7 +54,7 @@ public class SystemInfoWriterModuleTest { Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters(); assertThat(adapters) - .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 12); + .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 11); } } 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 da4ea48913b..8e78971a7ee 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 @@ -20,6 +20,7 @@ package org.sonar.server.telemetry; import java.io.IOException; +import java.net.URL; import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.List; @@ -45,6 +46,7 @@ import org.sonar.server.es.EsTester; import org.sonar.server.measure.index.ProjectMeasuresIndex; import org.sonar.server.measure.index.ProjectMeasuresIndexer; import org.sonar.server.organization.DefaultOrganizationProviderImpl; +import org.sonar.server.platform.DockerSupport; import org.sonar.server.property.InternalProperties; import org.sonar.server.property.MapInternalProperties; import org.sonar.server.tester.UserSessionRule; @@ -106,13 +108,14 @@ public class TelemetryDaemonTest { private UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client()); private PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class); + private final DockerSupport dockerSupport = mock(DockerSupport.class); private final TelemetryDataLoader communityDataLoader = new TelemetryDataLoaderImpl(server, db.getDbClient(), pluginRepository, new UserIndex(es.client(), system2), - new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, new DefaultOrganizationProviderImpl(db.getDbClient()), internalProperties, null); + new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, new DefaultOrganizationProviderImpl(db.getDbClient()), internalProperties, dockerSupport, null); private TelemetryDaemon communityUnderTest = new TelemetryDaemon(communityDataLoader, client, settings.asConfig(), internalProperties, lockManager, system2); private final LicenseReader licenseReader = mock(LicenseReader.class); private final TelemetryDataLoader commercialDataLoader = new TelemetryDataLoaderImpl(server, db.getDbClient(), pluginRepository, new UserIndex(es.client(), system2), - new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, new DefaultOrganizationProviderImpl(db.getDbClient()), internalProperties, licenseReader); + new ProjectMeasuresIndex(es.client(), null, system2), editionProvider, new DefaultOrganizationProviderImpl(db.getDbClient()), internalProperties, dockerSupport, licenseReader); private TelemetryDaemon commercialUnderTest = new TelemetryDaemon(commercialDataLoader, client, settings.asConfig(), internalProperties, lockManager, system2); @After @@ -158,8 +161,9 @@ public class TelemetryDaemonTest { ArgumentCaptor<String> jsonCaptor = captureJson(); String json = jsonCaptor.getValue(); - assertJson(json).ignoreFields("database").isSimilarTo(getClass().getResource("telemetry-example.json")); - assertJson(getClass().getResource("telemetry-example.json")).ignoreFields("database").isSimilarTo(json); + URL url = getClass().getResource("telemetry-example.json"); + assertJson(json).ignoreFields("database").isSimilarTo(url); + assertJson(url).ignoreFields("database").isSimilarTo(json); assertDatabaseMetadata(json); assertThat(logger.logs(LoggerLevel.INFO)).contains("Sharing of SonarQube statistics is enabled."); } diff --git a/server/sonar-webserver-core/src/test/resources/org/sonar/server/telemetry/telemetry-example.json b/server/sonar-webserver-core/src/test/resources/org/sonar/server/telemetry/telemetry-example.json index 5eeb14d2ff0..d9edc0ee818 100644 --- a/server/sonar-webserver-core/src/test/resources/org/sonar/server/telemetry/telemetry-example.json +++ b/server/sonar-webserver-core/src/test/resources/org/sonar/server/telemetry/telemetry-example.json @@ -51,5 +51,6 @@ "language": "js", "ncloc": 50 } - ] + ], + "docker": false } |