aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver/src
diff options
context:
space:
mode:
authorOrlovAlexander <35396155+OrlovAlexander85@users.noreply.github.com>2024-08-23 16:18:29 +0200
committersonartech <sonartech@sonarsource.com>2024-08-26 20:03:08 +0000
commit2715d0441a88972fe4c43de841c95d14c2eeff36 (patch)
tree121856b4eb586161249ac65948c837c4c90fcc9f /server/sonar-webserver/src
parentb7595e2634b4138d1e9a20620734247a13cf4d09 (diff)
downloadsonarqube-2715d0441a88972fe4c43de841c95d14c2eeff36.tar.gz
sonarqube-2715d0441a88972fe4c43de841c95d14c2eeff36.zip
SONAR-22730 Telemetry on legacy mode property
Diffstat (limited to 'server/sonar-webserver/src')
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java5
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProvider.java67
-rw-r--r--server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProviderTest.java71
3 files changed, 141 insertions, 2 deletions
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 03e3dd084cd..0e3a90538be 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
@@ -58,6 +58,7 @@ import org.sonar.core.component.DefaultResourceTypes;
import org.sonar.core.documentation.DefaultDocumentationLinkGenerator;
import org.sonar.core.extension.CoreExtensionsInstaller;
import org.sonar.core.language.LanguagesProvider;
+import org.sonar.core.metric.SoftwareQualitiesMetrics;
import org.sonar.core.platform.PlatformEditionProvider;
import org.sonar.core.platform.SpringComponentContainer;
import org.sonar.server.almintegration.ws.AlmIntegrationsWSModule;
@@ -159,7 +160,6 @@ import org.sonar.server.measure.index.ProjectsEsModule;
import org.sonar.server.measure.live.LiveMeasureModule;
import org.sonar.server.measure.ws.MeasuresWsModule;
import org.sonar.server.metric.IssueCountMetrics;
-import org.sonar.core.metric.SoftwareQualitiesMetrics;
import org.sonar.server.metric.UnanalyzedLanguageMetrics;
import org.sonar.server.metric.ws.MetricsWsModule;
import org.sonar.server.monitoring.ComputeEngineMetricStatusTask;
@@ -188,7 +188,7 @@ 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.TelemetryLegacyModePropertyProvider;
import org.sonar.server.platform.telemetry.TelemetryNclocProvider;
import org.sonar.server.platform.telemetry.TelemetryUserEnabledProvider;
import org.sonar.server.platform.telemetry.TelemetryVersionProvider;
@@ -669,6 +669,7 @@ public class PlatformLevel4 extends PlatformLevel {
// new telemetry metrics
ProjectCppAutoconfigTelemetryProvider.class,
TelemetryVersionProvider.class,
+ TelemetryLegacyModePropertyProvider.class,
TelemetryNclocProvider.class,
TelemetryUserEnabledProvider.class,
TelemetryFipsEnabledProvider.class,
diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProvider.java
new file mode 100644
index 00000000000..97c8bb80af7
--- /dev/null
+++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProvider.java
@@ -0,0 +1,67 @@
+/*
+ * 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.Optional;
+import org.sonar.db.DbClient;
+import org.sonar.db.property.PropertyDto;
+import org.sonar.telemetry.core.Dimension;
+import org.sonar.telemetry.core.Granularity;
+import org.sonar.telemetry.core.TelemetryDataProvider;
+import org.sonar.telemetry.core.TelemetryDataType;
+
+import static org.sonar.core.config.LegacyRatingConstants.LEGACY_RATING_MODE_ENABLED;
+import static org.sonar.telemetry.core.Dimension.INSTALLATION;
+import static org.sonar.telemetry.core.Granularity.WEEKLY;
+import static org.sonar.telemetry.core.TelemetryDataType.BOOLEAN;
+
+public class TelemetryLegacyModePropertyProvider implements TelemetryDataProvider<Boolean> {
+ private final DbClient dbClient;
+
+ public TelemetryLegacyModePropertyProvider(DbClient dbClient) {
+ this.dbClient = dbClient;
+ }
+
+ @Override
+ public String getMetricKey() {
+ return "legacy_rating_mode_enabled";
+ }
+
+ @Override
+ public Dimension getDimension() {
+ return INSTALLATION;
+ }
+
+ @Override
+ public Granularity getGranularity() {
+ return WEEKLY;
+ }
+
+ @Override
+ public TelemetryDataType getType() {
+ return BOOLEAN;
+ }
+
+ @Override
+ public Optional<Boolean> getValue() {
+ PropertyDto property = dbClient.propertiesDao().selectGlobalProperty(LEGACY_RATING_MODE_ENABLED);
+ return property == null ? Optional.of(false) : Optional.of(Boolean.valueOf(property.getValue()));
+ }
+}
diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProviderTest.java
new file mode 100644
index 00000000000..7a1aadac4f5
--- /dev/null
+++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProviderTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.Optional;
+import java.util.stream.Stream;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.sonar.db.DbClient;
+import org.sonar.db.property.PropertiesDao;
+import org.sonar.db.property.PropertyDto;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.core.config.LegacyRatingConstants.LEGACY_RATING_MODE_ENABLED;
+import static org.sonar.telemetry.core.Dimension.INSTALLATION;
+import static org.sonar.telemetry.core.Granularity.WEEKLY;
+import static org.sonar.telemetry.core.TelemetryDataType.BOOLEAN;
+
+class TelemetryLegacyModePropertyProviderTest {
+ private final DbClient dbClient = mock();
+ private final PropertiesDao propertiesDao = mock();
+ private final TelemetryLegacyModePropertyProvider underTest = new TelemetryLegacyModePropertyProvider(dbClient);
+
+ @ParameterizedTest
+ @MethodSource("getValues")
+ void getter_should_return_correct_values(Boolean value, Boolean expected) {
+ when(dbClient.propertiesDao()).thenReturn(propertiesDao);
+ if (value == null) {
+ when(dbClient.propertiesDao().selectGlobalProperty(LEGACY_RATING_MODE_ENABLED))
+ .thenReturn(null);
+ } else {
+ when(dbClient.propertiesDao().selectGlobalProperty(LEGACY_RATING_MODE_ENABLED))
+ .thenReturn(new PropertyDto().setValue(value.toString()));
+ }
+
+ assertEquals("legacy_rating_mode_enabled", underTest.getMetricKey());
+ assertEquals(INSTALLATION, underTest.getDimension());
+ assertEquals(WEEKLY, underTest.getGranularity());
+ assertEquals(BOOLEAN, underTest.getType());
+ assertEquals(Optional.of(expected), underTest.getValue());
+ }
+
+ public static Stream<Arguments> getValues() {
+ return Stream.of(
+ Arguments.of(true, true),
+ Arguments.of(false, false),
+ Arguments.of(null, false)
+ );
+ }
+
+}