]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12487 send docker flag in telemetry
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 26 Sep 2019 09:45:26 +0000 (11:45 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 8 Oct 2019 18:21:04 +0000 (20:21 +0200)
server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryData.java
server/sonar-server-common/src/main/java/org/sonar/server/telemetry/TelemetryDataJsonWriter.java
server/sonar-webserver-core/src/main/java/org/sonar/server/platform/SystemInfoWriterModule.java
server/sonar-webserver-core/src/main/java/org/sonar/server/telemetry/TelemetryDataLoaderImpl.java
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/ClusterSystemInfoWriterTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/StandaloneSystemInfoWriterTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/platform/SystemInfoWriterModuleTest.java
server/sonar-webserver-core/src/test/java/org/sonar/server/telemetry/TelemetryDaemonTest.java
server/sonar-webserver-core/src/test/resources/org/sonar/server/telemetry/telemetry-example.json
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java

index 89f3df4b38f21ded622bf47477558cb17d5e40eb..dba25d97e37058e0d70a954d08ce14658dfcfc96 100644 (file)
@@ -42,6 +42,7 @@ public class TelemetryData {
   private final String licenseType;
   private final Long installationDate;
   private final String installationVersion;
+  private final boolean inDocker;
 
   private TelemetryData(Builder builder) {
     serverId = builder.serverId;
@@ -58,6 +59,7 @@ public class TelemetryData {
     licenseType = builder.licenseType;
     installationDate = builder.installationDate;
     installationVersion = builder.installationVersion;
+    inDocker = builder.inDocker;
   }
 
   public String getServerId() {
@@ -116,6 +118,10 @@ public class TelemetryData {
     return installationVersion;
   }
 
+  public boolean isInDocker() {
+    return inDocker;
+  }
+
   static Builder builder() {
     return new Builder();
   }
@@ -133,6 +139,7 @@ public class TelemetryData {
     private String licenseType;
     private Long installationDate;
     private String installationVersion;
+    private boolean inDocker = false;
 
     private Builder() {
       // enforce static factory method
@@ -198,6 +205,11 @@ public class TelemetryData {
       return this;
     }
 
+    public Builder setInDocker(boolean inDocker) {
+      this.inDocker = inDocker;
+      return this;
+    }
+
     TelemetryData build() {
       requireNonNull(serverId);
       requireNonNull(version);
index 8f4d17696d5be81ce788a6ab6bd336bd408c56cc..ea104d269c08ddf70409a3c7d924a5d9f403fb61 100644 (file)
@@ -77,6 +77,7 @@ public class TelemetryDataJsonWriter {
     if (statistics.getInstallationVersion() != null) {
       json.prop("installationVersion", statistics.getInstallationVersion());
     }
+    json.prop("docker", statistics.isInDocker());
     json.endObject();
   }
 }
index 379e7b7eab37a361f08ca179a66b5ed7a14adc18..e608a80755ee93190233e1c746d0b440f7c020a2 100644 (file)
@@ -58,8 +58,7 @@ public class SystemInfoWriterModule extends Module {
       EsIndexesSection.class,
       LoggingSection.class,
       PluginsSection.class,
-      SettingsSection.class,
-      DockerSupportImpl.class
+      SettingsSection.class
 
       );
     if (standalone) {
index b31f2b30678794fe6c795615447b04db51eacb35..8b888ab79bdcef1ad81df38597bafd80fca3415a 100644 (file)
@@ -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();
   }
index 60820406733d8703fe82774cb44a1a8fdc2f5d67..233bbe2967a6801900bf407d37e49173dc08acd2 100644 (file)
@@ -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) {
index 1213c87f39ffc8cf823eb4a46e42d25ca15ea7ad..ad829e7ddf73ae3b29f1c21b813e48011736e136 100644 (file)
@@ -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() {
index bf3d7a0f43991435b45b32fc0761cfb1ec89c63e..5dd35b81d738c31651149ba03165266edf0a9efb 100644 (file)
@@ -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);
   }
 
 }
index da4ea48913b781b45bacd404daa3d6d8cc680a62..8e78971a7eeceff690ddc901ce8859ee315a6711 100644 (file)
@@ -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.");
   }
index 1fd70e56cadfc28bfd4b3446df727310ed5f0a5e..0f26b6296ccdf5f8f95dca6338cdcae76b9a8bd0 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.api.internal.MetadataLoader;
 import org.sonar.api.internal.SonarRuntimeImpl;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.Version;
+import org.sonar.server.platform.DockerSupportImpl;
 import org.sonar.server.util.GlobalLockManagerImpl;
 import org.sonar.server.util.Paths2Impl;
 import org.sonar.server.util.TempFolderCleaner;
@@ -110,6 +111,7 @@ public class PlatformLevel1 extends PlatformLevel {
       new TempFolderProvider(),
       System2.INSTANCE,
       Paths2Impl.getInstance(),
+      DockerSupportImpl.class,
       Clock.systemDefaultZone(),
 
       // user session