]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22730 Telemetry on legacy mode property
authorOrlovAlexander <35396155+OrlovAlexander85@users.noreply.github.com>
Fri, 23 Aug 2024 14:18:29 +0000 (16:18 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 26 Aug 2024 20:03:08 +0000 (20:03 +0000)
server/sonar-webserver/build.gradle
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProvider.java [new file with mode: 0644]
server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryLegacyModePropertyProviderTest.java [new file with mode: 0644]

index 6b055e5d06accac9dd3f21234325250093797e5a..9a0e75999715d252708cc5d63ef21c0133c616d8 100644 (file)
@@ -33,6 +33,7 @@ dependencies {
   testImplementation 'com.github.spotbugs:spotbugs-annotations'
   testImplementation 'com.tngtech.java:junit-dataprovider'
   testImplementation 'org.junit.jupiter:junit-jupiter-api'
+  testImplementation 'org.junit.jupiter:junit-jupiter-params'
   testImplementation 'org.mockito:mockito-core'
   testImplementation 'org.eclipse.jetty:jetty-server'
   testImplementation 'org.eclipse.jetty:jetty-servlet'
index 03e3dd084cd9e12f2441bf7854e24b163e2b13f9..0e3a90538be4820226449c6051d6364a823f4a77 100644 (file)
@@ -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 (file)
index 0000000..97c8bb8
--- /dev/null
@@ -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 (file)
index 0000000..7a1aada
--- /dev/null
@@ -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)
+    );
+  }
+
+}