@@ -46,6 +46,7 @@ public class TelemetryData { | |||
private final String installationVersion; | |||
private final boolean inDocker; | |||
private final ManagedInstanceInformation managedInstanceInformation; | |||
private final CloudUsage cloudUsage; | |||
private final List<UserTelemetryDto> users; | |||
private final List<Project> projects; | |||
private final List<ProjectStatistics> projectStatistics; | |||
@@ -76,6 +77,7 @@ public class TelemetryData { | |||
hasUnanalyzedCpp = builder.hasUnanalyzedCpp; | |||
customSecurityConfigs = requireNonNullElse(builder.customSecurityConfigs, Set.of()); | |||
managedInstanceInformation = builder.managedInstanceInformation; | |||
cloudUsage = builder.cloudUsage; | |||
ncdId = builder.ncdId; | |||
branches = builder.branches; | |||
newCodeDefinitions = builder.newCodeDefinitions; | |||
@@ -125,6 +127,10 @@ public class TelemetryData { | |||
return managedInstanceInformation; | |||
} | |||
public CloudUsage getCloudUsage() { | |||
return cloudUsage; | |||
} | |||
public Optional<Boolean> hasUnanalyzedC() { | |||
return Optional.ofNullable(hasUnanalyzedC); | |||
} | |||
@@ -181,6 +187,7 @@ public class TelemetryData { | |||
private String installationVersion; | |||
private boolean inDocker = false; | |||
private ManagedInstanceInformation managedInstanceInformation; | |||
private CloudUsage cloudUsage; | |||
private Boolean hasUnanalyzedC; | |||
private Boolean hasUnanalyzedCpp; | |||
private Set<String> customSecurityConfigs; | |||
@@ -276,6 +283,11 @@ public class TelemetryData { | |||
return this; | |||
} | |||
Builder setCloudUsage(CloudUsage cloudUsage) { | |||
this.cloudUsage = cloudUsage; | |||
return this; | |||
} | |||
TelemetryData build() { | |||
requireNonNullValues(serverId, version, plugins, database, messageSequenceNumber); | |||
return new TelemetryData(this); | |||
@@ -340,6 +352,9 @@ public class TelemetryData { | |||
record ManagedInstanceInformation(boolean isManaged, @Nullable String provider) { | |||
} | |||
record CloudUsage(boolean kubernetes) { | |||
} | |||
public static class ProjectStatistics { | |||
private final String projectUuid; | |||
private final Long branchCount; |
@@ -37,6 +37,8 @@ public class TelemetryDataJsonWriter { | |||
@VisibleForTesting | |||
static final String MANAGED_INSTANCE_PROPERTY = "managedInstanceInformation"; | |||
@VisibleForTesting | |||
static final String CLOUD_USAGE_PROPERTY = "cloudUsage"; | |||
private static final String LANGUAGE_PROPERTY = "language"; | |||
private static final String VERSION = "version"; | |||
@@ -101,6 +103,7 @@ public class TelemetryDataJsonWriter { | |||
writeNewCodeDefinitions(json, telemetryData); | |||
writeQualityGates(json, telemetryData); | |||
writeManagedInstanceInformation(json, telemetryData.getManagedInstanceInformation()); | |||
writeCloudUsage(json, telemetryData.getCloudUsage()); | |||
extensions.forEach(e -> e.write(json)); | |||
json.endObject(); | |||
@@ -229,6 +232,13 @@ public class TelemetryDataJsonWriter { | |||
json.endObject(); | |||
} | |||
private static void writeCloudUsage(JsonWriter json, TelemetryData.CloudUsage cloudUsage) { | |||
json.name(CLOUD_USAGE_PROPERTY); | |||
json.beginObject(); | |||
json.prop("kubernetes", cloudUsage.kubernetes()); | |||
json.endObject(); | |||
} | |||
@NotNull | |||
private static String toUtc(long date) { | |||
return DateTimeFormatter.ofPattern(DATETIME_FORMAT) |
@@ -585,6 +585,7 @@ public class TelemetryDataJsonWriterTest { | |||
.setMessageSequenceNumber(1L) | |||
.setPlugins(Collections.emptyMap()) | |||
.setManagedInstanceInformation(new TelemetryData.ManagedInstanceInformation(false, null)) | |||
.setCloudUsage(new TelemetryData.CloudUsage(false)) | |||
.setDatabase(new TelemetryData.Database("H2", "11")) | |||
.setNcdId(NCD_ID); | |||
} |
@@ -0,0 +1,34 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.telemetry; | |||
import org.sonar.api.server.ServerSide; | |||
@ServerSide | |||
public class CloudUsageDataProvider { | |||
public TelemetryData.CloudUsage getCloudUsage() { | |||
return new TelemetryData.CloudUsage(isKubernetes()); | |||
} | |||
private static boolean isKubernetes() { | |||
return true; | |||
} | |||
} |
@@ -109,6 +109,7 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { | |||
private final QualityGateCaycChecker qualityGateCaycChecker; | |||
private final QualityGateFinder qualityGateFinder; | |||
private final ManagedInstanceService managedInstanceService; | |||
private final CloudUsageDataProvider cloudUsageDataProvider; | |||
private final Set<NewCodeDefinition> newCodeDefinitions = new HashSet<>(); | |||
private final Map<String, NewCodeDefinition> ncdByProject = new HashMap<>(); | |||
private final Map<String, NewCodeDefinition> ncdByBranch = new HashMap<>(); | |||
@@ -118,7 +119,7 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { | |||
public TelemetryDataLoaderImpl(Server server, DbClient dbClient, PluginRepository pluginRepository, | |||
PlatformEditionProvider editionProvider, InternalProperties internalProperties, Configuration configuration, | |||
DockerSupport dockerSupport, QualityGateCaycChecker qualityGateCaycChecker, QualityGateFinder qualityGateFinder, | |||
ManagedInstanceService managedInstanceService) { | |||
ManagedInstanceService managedInstanceService, CloudUsageDataProvider cloudUsageDataProvider) { | |||
this.server = server; | |||
this.dbClient = dbClient; | |||
this.pluginRepository = pluginRepository; | |||
@@ -129,6 +130,7 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { | |||
this.qualityGateCaycChecker = qualityGateCaycChecker; | |||
this.qualityGateFinder = qualityGateFinder; | |||
this.managedInstanceService = managedInstanceService; | |||
this.cloudUsageDataProvider = cloudUsageDataProvider; | |||
} | |||
private static Database loadDatabaseMetadata(DbSession dbSession) { | |||
@@ -181,6 +183,7 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { | |||
.setInstallationVersion(installationVersionProperty.orElse(null)) | |||
.setInDocker(dockerSupport.isRunningInDocker()) | |||
.setManagedInstanceInformation(buildManagedInstanceInformation()) | |||
.setCloudUsage(buildCloudUsage()) | |||
.build(); | |||
} | |||
@@ -443,4 +446,7 @@ public class TelemetryDataLoaderImpl implements TelemetryDataLoader { | |||
return new TelemetryData.ManagedInstanceInformation(managedInstanceService.isInstanceExternallyManaged(), provider); | |||
} | |||
private TelemetryData.CloudUsage buildCloudUsage() { | |||
return cloudUsageDataProvider.getCloudUsage(); | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.telemetry; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class CloudUsageDataProviderTest { | |||
private final CloudUsageDataProvider underTest = new CloudUsageDataProvider(); | |||
@Test | |||
public void isKubernetes_shouldReturnValue() { | |||
assertThat(underTest.getCloudUsage().kubernetes()).isTrue(); | |||
} | |||
} |
@@ -113,11 +113,12 @@ public class TelemetryDataLoaderImplTest { | |||
private final QualityGateFinder qualityGateFinder = new QualityGateFinder(db.getDbClient()); | |||
private final InternalProperties internalProperties = spy(new MapInternalProperties()); | |||
private final ManagedInstanceService managedInstanceService = mock(ManagedInstanceService.class); | |||
private final CloudUsageDataProvider cloudUsageDataProvider = mock(CloudUsageDataProvider.class); | |||
private final TelemetryDataLoader communityUnderTest = new TelemetryDataLoaderImpl(server, db.getDbClient(), pluginRepository, editionProvider, | |||
internalProperties, configuration, dockerSupport, qualityGateCaycChecker, qualityGateFinder, managedInstanceService); | |||
internalProperties, configuration, dockerSupport, qualityGateCaycChecker, qualityGateFinder, managedInstanceService, cloudUsageDataProvider); | |||
private final TelemetryDataLoader commercialUnderTest = new TelemetryDataLoaderImpl(server, db.getDbClient(), pluginRepository, editionProvider, | |||
internalProperties, configuration, dockerSupport, qualityGateCaycChecker, qualityGateFinder, managedInstanceService); | |||
internalProperties, configuration, dockerSupport, qualityGateCaycChecker, qualityGateFinder, managedInstanceService, cloudUsageDataProvider); | |||
private QualityGateDto builtInDefaultQualityGate; | |||
private MetricDto bugsDto; |
@@ -237,6 +237,7 @@ import org.sonar.server.setting.SettingsChangeNotifier; | |||
import org.sonar.server.setting.ws.SettingsWsModule; | |||
import org.sonar.server.source.ws.SourceWsModule; | |||
import org.sonar.server.startup.LogServerId; | |||
import org.sonar.server.telemetry.CloudUsageDataProvider; | |||
import org.sonar.server.telemetry.TelemetryClient; | |||
import org.sonar.server.telemetry.TelemetryDaemon; | |||
import org.sonar.server.telemetry.TelemetryDataJsonWriter; | |||
@@ -619,6 +620,7 @@ public class PlatformLevel4 extends PlatformLevel { | |||
TelemetryDataJsonWriter.class, | |||
TelemetryDaemon.class, | |||
TelemetryClient.class, | |||
CloudUsageDataProvider.class, | |||
// monitoring | |||
ServerMonitoringMetrics.class, |