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;
hasUnanalyzedCpp = builder.hasUnanalyzedCpp;
customSecurityConfigs = requireNonNullElse(builder.customSecurityConfigs, Set.of());
managedInstanceInformation = builder.managedInstanceInformation;
+ cloudUsage = builder.cloudUsage;
ncdId = builder.ncdId;
branches = builder.branches;
newCodeDefinitions = builder.newCodeDefinitions;
return managedInstanceInformation;
}
+ public CloudUsage getCloudUsage() {
+ return cloudUsage;
+ }
+
public Optional<Boolean> hasUnanalyzedC() {
return Optional.ofNullable(hasUnanalyzedC);
}
private String installationVersion;
private boolean inDocker = false;
private ManagedInstanceInformation managedInstanceInformation;
+ private CloudUsage cloudUsage;
private Boolean hasUnanalyzedC;
private Boolean hasUnanalyzedCpp;
private Set<String> customSecurityConfigs;
return this;
}
+ Builder setCloudUsage(CloudUsage cloudUsage) {
+ this.cloudUsage = cloudUsage;
+ return this;
+ }
+
TelemetryData build() {
requireNonNullValues(serverId, version, plugins, database, messageSequenceNumber);
return new TelemetryData(this);
record ManagedInstanceInformation(boolean isManaged, @Nullable String provider) {
}
+ record CloudUsage(boolean kubernetes) {
+ }
+
public static class ProjectStatistics {
private final String projectUuid;
private final Long branchCount;
@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";
writeNewCodeDefinitions(json, telemetryData);
writeQualityGates(json, telemetryData);
writeManagedInstanceInformation(json, telemetryData.getManagedInstanceInformation());
+ writeCloudUsage(json, telemetryData.getCloudUsage());
extensions.forEach(e -> e.write(json));
json.endObject();
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)
.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);
}
--- /dev/null
+/*
+ * 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;
+ }
+}
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<>();
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;
this.qualityGateCaycChecker = qualityGateCaycChecker;
this.qualityGateFinder = qualityGateFinder;
this.managedInstanceService = managedInstanceService;
+ this.cloudUsageDataProvider = cloudUsageDataProvider;
}
private static Database loadDatabaseMetadata(DbSession dbSession) {
.setInstallationVersion(installationVersionProperty.orElse(null))
.setInDocker(dockerSupport.isRunningInDocker())
.setManagedInstanceInformation(buildManagedInstanceInformation())
+ .setCloudUsage(buildCloudUsage())
.build();
}
return new TelemetryData.ManagedInstanceInformation(managedInstanceService.isInstanceExternallyManaged(), provider);
}
+ private TelemetryData.CloudUsage buildCloudUsage() {
+ return cloudUsageDataProvider.getCloudUsage();
+ }
}
--- /dev/null
+/*
+ * 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();
+ }
+}
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;
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;
TelemetryDataJsonWriter.class,
TelemetryDaemon.class,
TelemetryClient.class,
+ CloudUsageDataProvider.class,
// monitoring
ServerMonitoringMetrics.class,