aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2024-11-28 14:31:33 +0100
committersonartech <sonartech@sonarsource.com>2024-11-29 20:03:05 +0000
commit42a7e5b7c425d0894d853bcbc485df70ac749f10 (patch)
treea5e430ac2fe9559c9db551b6200fb52c49ba5952
parent68aabf3ee33173bd2b8585997f3fa8a4014ad84e (diff)
downloadsonarqube-42a7e5b7c425d0894d853bcbc485df70ac749f10.tar.gz
sonarqube-42a7e5b7c425d0894d853bcbc485df70ac749f10.zip
SONAR-23729 Drop telemetry metric about CPP configuration type
-rw-r--r--server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java100
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java2
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java85
-rw-r--r--server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java42
4 files changed, 0 insertions, 229 deletions
diff --git a/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java b/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java
deleted file mode 100644
index 2a2e39c2ac5..00000000000
--- a/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 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.platform.telemetry;
-
-import java.util.Map;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
-import org.sonar.api.utils.System2;
-import org.sonar.db.DbTester;
-import org.sonar.db.component.ProjectData;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY;
-
-class ProjectCppAutoconfigTelemetryProviderIT {
-
- private final System2 system2 = new AlwaysIncreasingSystem2(1000L);
-
- @RegisterExtension
- public final DbTester db = DbTester.create(system2);
-
- ProjectCppAutoconfigTelemetryProvider underTest = new ProjectCppAutoconfigTelemetryProvider(db.getDbClient());
-
- @Test
- void getValues_whenNoProjects_returnEmptyList() {
- assertThat(underTest.getValues()).isEmpty();
- }
-
- @Test
- void getValues_whenNoCppAndCProjects_returnEmptyMap() {
- ProjectData project1 = db.components().insertPrivateProject();
- ProjectData project2 = db.components().insertPrivateProject();
-
- db.measures().insertMeasure(project1, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "java=100"));
- db.measures().insertMeasure(project2, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "cobol=100"));
-
- assertThat(underTest.getValues()).isEmpty();
- }
-
- @Test
- void getValues_when1CppAnd1CProject_returnMapWithSize2AndAutoconfigByDefault() {
- ProjectData project1 = db.components().insertPrivateProject();
- ProjectData project2 = db.components().insertPrivateProject();
- ProjectData project3 = db.components().insertPrivateProject();
- ProjectData project4 = db.components().insertPrivateProject();
-
- db.measures().insertMeasure(project1, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "c=100;java=2"));
- db.measures().insertMeasure(project2, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "java=2;cpp=100"));
- db.measures().insertMeasure(project3, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "java=100"));
- db.measures().insertMeasure(project4, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "cobol=100"));
-
- Map<String, String> actualResult = underTest.getValues();
-
- assertThat(actualResult).hasSize(2)
- .containsExactlyInAnyOrderEntriesOf(
- Map.of(project1.getProjectDto().getUuid(), "AUTOCONFIG", project2.getProjectDto().getUuid(), "AUTOCONFIG")
- );
- }
-
- @Test
- void getValues_whenCAndCppProjectsWithDifferentConfig_returnMapWithSize2AndNotAutoconfig() {
- ProjectData project1 = db.components().insertPrivateProject();
- ProjectData project2 = db.components().insertPrivateProject();
- ProjectData project3 = db.components().insertPrivateProject();
- ProjectData project4 = db.components().insertPrivateProject();
-
- db.measures().insertMeasure(project1, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "c=100"));
- db.measures().insertMeasure(project2, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "cpp=100"));
- db.measures().insertMeasure(project3, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "java=100"));
- db.measures().insertMeasure(project4, m -> m.addValue(NCLOC_LANGUAGE_DISTRIBUTION_KEY, "cobol=100"));
-
- db.properties().insertProperty("sonar.cfamily.build-wrapper-output", "anyvalue", project1.getProjectDto().getUuid());
- db.properties().insertProperty("sonar.cfamily.compile-commands", "anyvalue", project2.getProjectDto().getUuid());
-
- Map<String, String> actualResult = underTest.getValues();
-
- assertThat(actualResult).hasSize(2)
- .containsExactlyInAnyOrderEntriesOf(
- Map.of(project1.getProjectDto().getUuid(), "BW_DEPRECATED", project2.getProjectDto().getUuid(), "COMPDB")
- );
- }
-}
diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
index 1b03e89f093..5b8197fb29b 100644
--- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
+++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
@@ -188,7 +188,6 @@ import org.sonar.server.platform.PersistentSettings;
import org.sonar.server.platform.SystemInfoWriterModule;
import org.sonar.server.platform.WebCoreExtensionsInstaller;
import org.sonar.server.platform.db.CheckAnyonePermissionsAtStartup;
-import org.sonar.server.platform.telemetry.ProjectCppAutoconfigTelemetryProvider;
import org.sonar.server.platform.telemetry.TelemetryFipsEnabledProvider;
import org.sonar.server.platform.telemetry.TelemetryMQRModePropertyProvider;
import org.sonar.server.platform.telemetry.TelemetryNclocProvider;
@@ -674,7 +673,6 @@ public class PlatformLevel4 extends PlatformLevel {
IndexersImpl.class,
// new telemetry metrics
- ProjectCppAutoconfigTelemetryProvider.class,
TelemetryVersionProvider.class,
TelemetryMQRModePropertyProvider.class,
TelemetryNclocProvider.class,
diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java
deleted file mode 100644
index 79c36f92dac..00000000000
--- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 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.platform.telemetry;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.measure.ProjectMainBranchMeasureDto;
-import org.sonar.db.property.PropertyDto;
-import org.sonar.db.property.PropertyQuery;
-import org.sonar.telemetry.core.AbstractTelemetryDataProvider;
-import org.sonar.telemetry.core.Dimension;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-public class ProjectCppAutoconfigTelemetryProvider extends AbstractTelemetryDataProvider<String> {
-
- private final DbClient dbClient;
-
- public ProjectCppAutoconfigTelemetryProvider(DbClient dbClient) {
- super("project_cpp_config_type", Dimension.PROJECT, Granularity.WEEKLY, TelemetryDataType.STRING);
- this.dbClient = dbClient;
- }
-
- @Override
- public Map<String, String> getValues() {
- Map<String, String> cppConfigTypePerProjectUuid = new HashMap<>();
- try (DbSession dbSession = dbClient.openSession(true)) {
- List<ProjectMainBranchMeasureDto> measureDtos = dbClient.measureDao().selectAllForProjectMainBranches(dbSession);
- for (ProjectMainBranchMeasureDto measureDto : measureDtos) {
- String distribution = (String) measureDto.getMetricValues().get(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY);
- if (distribution != null && Set.of("cpp", "c").stream().anyMatch(language -> distributionContainsLanguage(distribution, language))) {
- CppConfigType cppConfigType = getCppConfigType(measureDto.getProjectUuid(), dbSession);
- cppConfigTypePerProjectUuid.put(measureDto.getProjectUuid(), cppConfigType.name());
- }
- }
- }
- return cppConfigTypePerProjectUuid;
- }
-
- private static boolean distributionContainsLanguage(String distribution, String language) {
- return distribution.startsWith(language + "=") || distribution.contains(";" + language + "=");
- }
-
- private CppConfigType getCppConfigType(String entityUuid, DbSession dbSession) {
- List<PropertyDto> propertyDtos = dbClient.propertiesDao().selectByQuery(PropertyQuery
- .builder()
- .setEntityUuid(entityUuid)
- .build(), dbSession);
- for (PropertyDto propertyDto : propertyDtos) {
- if (propertyDto.getKey().equals("sonar.cfamily.build-wrapper-output")) {
- return CppConfigType.BW_DEPRECATED;
- }
- if (propertyDto.getKey().equals("sonar.cfamily.compile-commands")) {
- return CppConfigType.COMPDB;
- }
- }
- return CppConfigType.AUTOCONFIG;
- }
-
- enum CppConfigType {
- BW_DEPRECATED, COMPDB, AUTOCONFIG
- }
-}
diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java
deleted file mode 100644
index 295d03b07b1..00000000000
--- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2024 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.platform.telemetry;
-
-import org.junit.jupiter.api.Test;
-import org.sonar.db.DbClient;
-import org.sonar.telemetry.core.Dimension;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.mock;
-
-class ProjectCppAutoconfigTelemetryProviderTest {
-
- @Test
- void testGetters() {
- ProjectCppAutoconfigTelemetryProvider provider = new ProjectCppAutoconfigTelemetryProvider(mock(DbClient.class));
-
- assertEquals("project_cpp_config_type", provider.getMetricKey());
- assertEquals(Dimension.PROJECT, provider.getDimension());
- assertEquals(Granularity.WEEKLY, provider.getGranularity());
- assertEquals(TelemetryDataType.STRING, provider.getType());
- }
-}