private final String licenseType;
private final Long installationDate;
private final String installationVersion;
+ private final boolean inDocker;
private TelemetryData(Builder builder) {
serverId = builder.serverId;
licenseType = builder.licenseType;
installationDate = builder.installationDate;
installationVersion = builder.installationVersion;
+ inDocker = builder.inDocker;
}
public String getServerId() {
return installationVersion;
}
+ public boolean isInDocker() {
+ return inDocker;
+ }
+
static Builder builder() {
return new Builder();
}
private String licenseType;
private Long installationDate;
private String installationVersion;
+ private boolean inDocker = false;
private Builder() {
// enforce static factory method
return this;
}
+ public Builder setInDocker(boolean inDocker) {
+ this.inDocker = inDocker;
+ return this;
+ }
+
TelemetryData build() {
requireNonNull(serverId);
requireNonNull(version);
if (statistics.getInstallationVersion() != null) {
json.prop("installationVersion", statistics.getInstallationVersion());
}
+ json.prop("docker", statistics.isInDocker());
json.endObject();
}
}
EsIndexesSection.class,
LoggingSection.class,
PluginsSection.class,
- SettingsSection.class,
- DockerSupportImpl.class
+ SettingsSection.class
);
if (standalone) {
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;
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;
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) {
}
Optional<String> installationVersionProperty = internalProperties.read(InternalProperties.INSTALLATION_VERSION);
data.setInstallationVersion(installationVersionProperty.orElse(null));
+ data.setInDocker(dockerSupport.isRunningInDocker());
return data.build();
}
+ "\"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) {
// 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() {
Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters();
assertThat(adapters)
- .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 18);
+ .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 17);
}
@Test
Collection<ComponentAdapter<?>> adapters = container.getPicoContainer().getComponentAdapters();
assertThat(adapters)
- .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 12);
+ .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 11);
}
}
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;
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;
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
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.");
}
"language": "js",
"ncloc": 50
}
- ]
+ ],
+ "docker": false
}
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;
new TempFolderProvider(),
System2.INSTANCE,
Paths2Impl.getInstance(),
+ DockerSupportImpl.class,
Clock.systemDefaultZone(),
// user session