]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22891 added new telemetry metric
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>
Fri, 6 Sep 2024 06:47:33 +0000 (08:47 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 6 Sep 2024 20:02:37 +0000 (20:02 +0000)
21 files changed:
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImpl.java
server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProvider.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationContainerPopulatorImplTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/engine/MigrationEngineImplTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProviderTest.java [new file with mode: 0644]
server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/TelemetryDataProvider.java
server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java
server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java
server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java
server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TestTelemetryBean.java
server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java
server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java
server/sonar-webserver/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java
server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProviderTest.java
server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryNclocProviderTest.java
server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryVersionProviderTest.java

index bbccc564367bf9ef878920010135d88293604ad4..934b72022853de5eb41ee5766006a0ed7069cc35 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.core.platform.Container;
 import org.sonar.core.util.logs.Profiler;
 import org.sonar.server.platform.db.migration.MutableDatabaseMigrationState;
 import org.sonar.server.platform.db.migration.history.MigrationHistory;
+import org.sonar.server.telemetry.TelemetryDbMigrationStepDurationProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationSuccessProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationStepsProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationTotalTimeProvider;
@@ -45,16 +46,18 @@ public class MigrationStepsExecutorImpl implements MigrationStepsExecutor {
   private final TelemetryDbMigrationTotalTimeProvider telemetryDbMigrationTotalTimeProvider;
   private final TelemetryDbMigrationStepsProvider telemetryDbMigrationStepsProvider;
   private final TelemetryDbMigrationSuccessProvider telemetryDbMigrationSuccessProvider;
+  private final TelemetryDbMigrationStepDurationProvider telemetryDbMigrationStepDurationProvider;
 
   public MigrationStepsExecutorImpl(Container migrationContainer, MigrationHistory migrationHistory, MutableDatabaseMigrationState databaseMigrationState,
     TelemetryDbMigrationTotalTimeProvider telemetryDbMigrationTotalTimeProvider, TelemetryDbMigrationStepsProvider telemetryDbMigrationStepsProvider,
-    TelemetryDbMigrationSuccessProvider telemetryDbMigrationSuccessProvider) {
+    TelemetryDbMigrationSuccessProvider telemetryDbMigrationSuccessProvider, TelemetryDbMigrationStepDurationProvider stepDurationProvider) {
     this.migrationContainer = migrationContainer;
     this.migrationHistory = migrationHistory;
     this.databaseMigrationState = databaseMigrationState;
     this.telemetryDbMigrationTotalTimeProvider = telemetryDbMigrationTotalTimeProvider;
     this.telemetryDbMigrationStepsProvider = telemetryDbMigrationStepsProvider;
     this.telemetryDbMigrationSuccessProvider = telemetryDbMigrationSuccessProvider;
+    this.telemetryDbMigrationStepDurationProvider = stepDurationProvider;
   }
 
   @Override
@@ -109,11 +112,12 @@ public class MigrationStepsExecutorImpl implements MigrationStepsExecutor {
       throw new MigrationStepExecutionException(step, e);
     } finally {
       if (done) {
-        stepProfiler.stopInfo(STEP_STOP_PATTERN,
+        long durationInMiliseconds = stepProfiler.stopInfo(STEP_STOP_PATTERN,
           databaseMigrationState.getCompletedMigrations() + 1,
           databaseMigrationState.getTotalMigrations(),
           step,
           "success");
+        telemetryDbMigrationStepDurationProvider.addCompletedStep(step.getMigrationNumber(), durationInMiliseconds);
       } else {
         stepProfiler.stopError(STEP_STOP_PATTERN,
           databaseMigrationState.getCompletedMigrations() + 1,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProvider.java b/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProvider.java
new file mode 100644 (file)
index 0000000..06ac499
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.telemetry;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.sonar.telemetry.core.Dimension;
+import org.sonar.telemetry.core.Granularity;
+import org.sonar.telemetry.core.TelemetryDataProvider;
+import org.sonar.telemetry.core.TelemetryDataType;
+
+public class TelemetryDbMigrationStepDurationProvider implements TelemetryDataProvider<Long> {
+
+  private final Map<String, Long> dbMigrationStepDurations = new HashMap<>();
+
+  @Override
+  public String getMetricKey() {
+    return "db_migration_step_duration";
+  }
+
+  @Override
+  public Dimension getDimension() {
+    return Dimension.INSTALLATION;
+  }
+
+  @Override
+  public Granularity getGranularity() {
+    return Granularity.ADHOC;
+  }
+
+  @Override
+  public TelemetryDataType getType() {
+    return TelemetryDataType.INTEGER;
+  }
+
+  @Override
+  public Map<String, Long> getValues() {
+    return dbMigrationStepDurations;
+  }
+
+  @Override
+  public void after() {
+    dbMigrationStepDurations.clear();
+  }
+
+  public void addCompletedStep(Long migrationId, Long duration) {
+    dbMigrationStepDurations.put(migrationId.toString(), duration);
+  }
+}
index c1af7bacb2f86766ef38422dd6a2dbfdf63ff4b9..d74b459fa4b13be37e5044cc6bd0d0875d345651 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.server.platform.db.migration.step.MigrationStep;
 import org.sonar.server.platform.db.migration.step.MigrationSteps;
 import org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl;
 import org.sonar.server.platform.db.migration.step.RegisteredMigrationStep;
+import org.sonar.server.telemetry.TelemetryDbMigrationStepDurationProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationSuccessProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationStepsProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationTotalTimeProvider;
@@ -57,6 +58,7 @@ public class MigrationContainerPopulatorImplTest {
     migrationContainer.add(mock(TelemetryDbMigrationStepsProvider.class));
     migrationContainer.add(mock(TelemetryDbMigrationTotalTimeProvider.class));
     migrationContainer.add(mock(TelemetryDbMigrationSuccessProvider.class));
+    migrationContainer.add(mock(TelemetryDbMigrationStepDurationProvider.class));
 
     migrationContainer.startComponents();
     underTest.populateContainer(migrationContainer);
index db672f507fa29e46bf0f814f2e9b9ba2af773ef9..9462d6b7f49ec6610dde2bef55e6fc5b54b9a05a 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.server.platform.db.migration.step.MigrationStep;
 import org.sonar.server.platform.db.migration.step.MigrationSteps;
 import org.sonar.server.platform.db.migration.step.NoOpMigrationStatusListener;
 import org.sonar.server.platform.db.migration.step.RegisteredMigrationStep;
+import org.sonar.server.telemetry.TelemetryDbMigrationStepDurationProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationSuccessProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationStepsProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationTotalTimeProvider;
@@ -51,6 +52,7 @@ class MigrationEngineImplTest {
   private final TelemetryDbMigrationTotalTimeProvider telemetryDbMigrationTotalTimeProvider = new TelemetryDbMigrationTotalTimeProvider();
   private final TelemetryDbMigrationStepsProvider telemetryUpgradeStepsProvider = new TelemetryDbMigrationStepsProvider();
   private final TelemetryDbMigrationSuccessProvider telemetryDbMigrationSuccessProvider = new TelemetryDbMigrationSuccessProvider();
+  private final TelemetryDbMigrationStepDurationProvider telemetryDbMigrationStepDurationProvider = new TelemetryDbMigrationStepDurationProvider();
   private final MigrationEngineImpl underTest = new MigrationEngineImpl(migrationHistory, serverContainer, migrationSteps);
 
   @BeforeEach
@@ -62,6 +64,7 @@ class MigrationEngineImplTest {
     serverContainer.add(migrationHistory);
     serverContainer.add(stepRegistry);
     serverContainer.add(databaseMigrationState);
+    serverContainer.add(telemetryDbMigrationStepDurationProvider);
     serverContainer.startComponents();
   }
 
@@ -97,7 +100,7 @@ class MigrationEngineImplTest {
   private record TestMigrationStep(StepRegistry registry) implements MigrationStep {
 
     @Override
-    public void execute() throws SQLException {
+    public void execute() {
       registry.stepRan = true;
     }
   }
index 643bb332373c06bed49cec6179b6e857766d4659..a7a40fb45ce98e2d7469fb26fecd4cad6dd2a619 100644 (file)
@@ -35,6 +35,7 @@ import org.sonar.server.platform.db.migration.MutableDatabaseMigrationState;
 import org.sonar.server.platform.db.migration.engine.MigrationContainer;
 import org.sonar.server.platform.db.migration.engine.SimpleMigrationContainer;
 import org.sonar.server.platform.db.migration.history.MigrationHistory;
+import org.sonar.server.telemetry.TelemetryDbMigrationStepDurationProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationSuccessProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationStepsProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationTotalTimeProvider;
@@ -60,8 +61,9 @@ class MigrationStepsExecutorImplTest {
   private final TelemetryDbMigrationTotalTimeProvider telemetryDbMigrationTotalTimeProvider = new TelemetryDbMigrationTotalTimeProvider();
   private final TelemetryDbMigrationStepsProvider telemetryDbMigrationStepsProvider = new TelemetryDbMigrationStepsProvider();
   private final TelemetryDbMigrationSuccessProvider telemetryDbMigrationSuccessProvider = new TelemetryDbMigrationSuccessProvider();
+  private final TelemetryDbMigrationStepDurationProvider telemetryDbMigrationStepDurationProvider = new TelemetryDbMigrationStepDurationProvider();
   private final MigrationStepsExecutorImpl underTest = new MigrationStepsExecutorImpl(migrationContainer, migrationHistory, databaseMigrationState,
-    telemetryDbMigrationTotalTimeProvider, telemetryDbMigrationStepsProvider, telemetryDbMigrationSuccessProvider);
+    telemetryDbMigrationTotalTimeProvider, telemetryDbMigrationStepsProvider, telemetryDbMigrationSuccessProvider, telemetryDbMigrationStepDurationProvider);
   private final NoOpMigrationStatusListener migrationStatusListener = mock();
 
   @BeforeEach
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProviderTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProviderTest.java
new file mode 100644 (file)
index 0000000..7ef3335
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.telemetry;
+
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.telemetry.core.Dimension.INSTALLATION;
+import static org.sonar.telemetry.core.Granularity.ADHOC;
+import static org.sonar.telemetry.core.TelemetryDataType.INTEGER;
+
+class TelemetryDbMigrationStepDurationProviderTest {
+
+  @Test
+  void testGetters() {
+    TelemetryDbMigrationStepDurationProvider underTest = new TelemetryDbMigrationStepDurationProvider();
+
+    underTest.addCompletedStep(1L, 10L);
+    underTest.addCompletedStep(9L, 20L);
+
+    assertThat(underTest.getMetricKey()).isEqualTo("db_migration_step_duration");
+    assertThat(underTest.getGranularity()).isEqualTo(ADHOC);
+    assertThat(underTest.getDimension()).isEqualTo(INSTALLATION);
+    assertThat(underTest.getType()).isEqualTo(INTEGER);
+    assertThat(underTest.getValue()).isEmpty();
+    assertThat(underTest.getValues()).containsExactlyInAnyOrderEntriesOf(Map.of("1", 10L, "9", 20L));
+
+    underTest.after();
+
+    assertThat(underTest.getValues()).isEmpty();
+  }
+}
index b91453f3aa38345592440bcc310d6abee2b31e6c..8829701c4b10b4bd81c69e7c98d3d0411b0e14be 100644 (file)
@@ -58,23 +58,23 @@ public interface TelemetryDataProvider<T> {
 
   /**
    * The implementation of this method might often need to make a call to a database.
-   * For each metric either this method or {@link TelemetryDataProvider#getUuidValues()} should be implemented and used. Not both at once.
+   * For each metric either this method or {@link TelemetryDataProvider#getValues()} should be used. Not both at once.
    *
    * @return the value of the data provided by this instance.
    */
   default Optional<T> getValue() {
-    throw new IllegalStateException("Not implemented");
+    return Optional.empty();
   }
 
   /**
    * The implementation of this method might often need to make a call to a database.
-   * Similiar as {@link TelemetryDataProvider#getValue()} this method returns values of the metric. Some of the metrics
-   * associate a UUID with a value. This method is used to return all the values associated with the UUIDs.
+   * Similar as {@link TelemetryDataProvider#getValue()} this method returns values of the metric. Some of the metrics
+   * associate a key with a value. This method is used to return all the values associated with the keys.
    *
-   * @return map of UUIDs and their values.
+   * @return map of keys and their values.
    */
-  default Map<String, T> getUuidValues() {
-    throw new IllegalStateException("Not implemented");
+  default Map<String, T> getValues() {
+    return Map.of();
   }
 
   /**
index 6dc2f649365f31b90904b3cb01460f1a547ad519..67e2ea872e8fa460aa6be3693456f7c112bbf1af 100644 (file)
@@ -270,7 +270,7 @@ class TelemetryMetricsLoaderIT {
       }
 
       @Override
-      public Map<String, T> getUuidValues() {
+      public Map<String, T> getValues() {
         return Stream.of(keys)
           .collect(Collectors.toMap(
             key -> key,
index e3379e4772f707f6127333a11152ce8440e3624d..d282608d9c2425acdca6a0fc9072ee056abaa2af 100644 (file)
@@ -52,7 +52,20 @@ public class TelemetryMetricsMapper {
 
   private static Set<Metric> mapInstallationMetric(TelemetryDataProvider<?> provider) {
     Optional<?> optionalValue = provider.getValue();
-    if (provider.getGranularity() == Granularity.ADHOC && optionalValue.isEmpty()) {
+
+    Granularity granularity = provider.getGranularity();
+
+    if (granularity == Granularity.ADHOC && !provider.getValues().isEmpty()) {
+      return provider.getValues().entrySet().stream()
+        .map(entry -> new InstallationMetric(
+          provider.getMetricKey() + "." + entry.getKey(),
+          entry.getValue(),
+          provider.getType(),
+          granularity
+        )).collect(Collectors.toSet());
+    }
+
+    if (granularity == Granularity.ADHOC && optionalValue.isEmpty()) {
       return Collections.emptySet();
     }
 
@@ -60,12 +73,12 @@ public class TelemetryMetricsMapper {
       provider.getMetricKey(),
       optionalValue.orElse(null),
       provider.getType(),
-      provider.getGranularity()
+      granularity
     ));
   }
 
   private static Set<Metric> mapUserMetric(TelemetryDataProvider<?> provider) {
-    return provider.getUuidValues().entrySet().stream()
+    return provider.getValues().entrySet().stream()
       .map(entry -> new UserMetric(
         provider.getMetricKey(),
         entry.getValue(),
@@ -76,7 +89,7 @@ public class TelemetryMetricsMapper {
   }
 
   private static Set<Metric> mapProjectMetric(TelemetryDataProvider<?> provider) {
-    return provider.getUuidValues().entrySet().stream()
+    return provider.getValues().entrySet().stream()
       .map(entry -> new ProjectMetric(
         provider.getMetricKey(),
         entry.getValue(),
@@ -87,7 +100,7 @@ public class TelemetryMetricsMapper {
   }
 
   private static Set<Metric> mapLanguageMetric(TelemetryDataProvider<?> provider) {
-    return provider.getUuidValues().entrySet().stream()
+    return provider.getValues().entrySet().stream()
       .map(entry -> new LanguageMetric(
         provider.getMetricKey(),
         entry.getValue(),
index d2fa9f9533c2ae507b9923391eb00e9e0307cee8..d822623d1678aef59ad95ba9413bc1e886f66ec7 100644 (file)
@@ -53,6 +53,26 @@ class TelemetryMetricsMapperTest {
       );
   }
 
+  @Test
+  void mapFromDataProvider_whenInstallationProviderWithMultiValue() {
+    TelemetryDataProvider<String> provider = new TestTelemetryBean(Dimension.INSTALLATION) {
+      @Override
+      public Granularity getGranularity() {
+        return Granularity.ADHOC;
+      }
+    };
+
+    Set<Metric> metrics = TelemetryMetricsMapper.mapFromDataProvider(provider);
+    List<InstallationMetric> userMetrics = retrieveList(metrics);
+
+    assertThat(userMetrics)
+      .extracting(InstallationMetric::getKey, InstallationMetric::getType, InstallationMetric::getValue, InstallationMetric::getGranularity)
+      .containsExactlyInAnyOrder(
+        tuple("telemetry-bean-a.key-1", TelemetryDataType.STRING, "value-1", Granularity.ADHOC),
+        tuple("telemetry-bean-a.key-2", TelemetryDataType.STRING, "value-2", Granularity.ADHOC)
+      );
+  }
+
   @Test
   void mapFromDataProvider_whenUserProvider() {
     TelemetryDataProvider<String> provider = new TestTelemetryBean(Dimension.USER);
index 7aa64e464dc568b2f7e6ed57fd19c3767dd44847..f4c4c844d85e772ea242f8478d9314eecb6d6f12 100644 (file)
@@ -66,7 +66,7 @@ public class TestTelemetryBean implements TelemetryDataProvider<String> {
   }
 
   @Override
-  public Map<String, String> getUuidValues() {
+  public Map<String, String> getValues() {
     return METRIC_UUID_VALUES;
   }
 
index 666965be5cc16b1b9255fb52af43b347da653e6f..3ad5a8f3d6ac6075a86a648f62684283cbc2a5ff 100644 (file)
@@ -46,12 +46,12 @@ class ProjectCppAutoconfigTelemetryProviderIT {
   ProjectCppAutoconfigTelemetryProvider underTest = new ProjectCppAutoconfigTelemetryProvider(db.getDbClient());
 
   @Test
-  void getUuidValues_whenNoProjects_returnEmptyList() {
-    assertThat(underTest.getUuidValues()).isEmpty();
+  void getValues_whenNoProjects_returnEmptyList() {
+    assertThat(underTest.getValues()).isEmpty();
   }
 
   @Test
-  void getUuidValues_whenNoCppAndCProjects_returnEmptyMap() {
+  void getValues_whenNoCppAndCProjects_returnEmptyMap() {
     Consumer<MetricDto> configureMetric = metric -> metric
       .setValueType(STRING.name())
       .setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY);
@@ -65,11 +65,11 @@ class ProjectCppAutoconfigTelemetryProviderIT {
     insertLiveMeasure("cobol", metric).accept(project2);
 
 
-    assertThat(underTest.getUuidValues()).isEmpty();
+    assertThat(underTest.getValues()).isEmpty();
   }
 
   @Test
-  void getUuidValues_when1CppAnd1CProject_returnMapWithSize2AndAutoconfigByDefault() {
+  void getValues_when1CppAnd1CProject_returnMapWithSize2AndAutoconfigByDefault() {
     Consumer<MetricDto> configureMetric = metric -> metric
       .setValueType(STRING.name())
       .setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY);
@@ -86,7 +86,7 @@ class ProjectCppAutoconfigTelemetryProviderIT {
     insertLiveMeasure("java", metric).accept(project3);
     insertLiveMeasure("cobol", metric).accept(project4);
 
-    Map<String, String> actualResult = underTest.getUuidValues();
+    Map<String, String> actualResult = underTest.getValues();
 
     assertThat(actualResult).hasSize(2)
       .containsExactlyInAnyOrderEntriesOf(
@@ -95,7 +95,7 @@ class ProjectCppAutoconfigTelemetryProviderIT {
   }
 
   @Test
-  void getUuidValues_whenCAndCppProjectsWithDifferentConfig_returnMapWithSize2AndNotAutoconfig() {
+  void getValues_whenCAndCppProjectsWithDifferentConfig_returnMapWithSize2AndNotAutoconfig() {
     Consumer<MetricDto> configureMetric = metric -> metric
       .setValueType(STRING.name())
       .setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY);
@@ -115,7 +115,7 @@ class ProjectCppAutoconfigTelemetryProviderIT {
     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.getUuidValues();
+    Map<String, String> actualResult = underTest.getValues();
 
     assertThat(actualResult).hasSize(2)
       .containsExactlyInAnyOrderEntriesOf(
index f0466dac7a8495d460320d9e37ee90530d4225ef..fee743fd088c30e75a8c2da82e4be3088c2bbe0b 100644 (file)
@@ -47,19 +47,19 @@ class TelemetryUserEnabledProviderIT {
   }
 
   @Test
-  void getUuidValues_whenNoUsersInDatabase_shouldReturnEmptyMap() {
-    Map<String, Boolean> uuidValues = underTest.getUuidValues();
+  void getValues_whenNoUsersInDatabase_shouldReturnEmptyMap() {
+    Map<String, Boolean> uuidValues = underTest.getValues();
 
     assertThat(uuidValues).isEmpty();
   }
 
   @Test
-  void getUuidValues_whenSomeUsersActive_shouldReturnBothBooleanValues() {
+  void getValues_whenSomeUsersActive_shouldReturnBothBooleanValues() {
     db.users().insertUser(user -> user.setUuid("uuid1").setActive(true));
     db.users().insertUser(user -> user.setUuid("uuid1").setActive(false));
     db.getSession().commit();
 
-    Map<String, Boolean> uuidValues = underTest.getUuidValues();
+    Map<String, Boolean> uuidValues = underTest.getValues();
 
     assertThat(uuidValues).hasSize(2);
     assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(1);
@@ -67,25 +67,25 @@ class TelemetryUserEnabledProviderIT {
   }
 
   @Test
-  void getUuidValues_when10ActiveUsers_shouldReturn10BooleanValues() {
+  void getValues_when10ActiveUsers_shouldReturn10BooleanValues() {
     for (int i = 0; i < 10; i++) {
       db.users().insertUser(user -> user.setActive(true));
     }
     db.getSession().commit();
 
-    Map<String, Boolean> uuidValues = underTest.getUuidValues();
+    Map<String, Boolean> uuidValues = underTest.getValues();
 
     assertThat(uuidValues).hasSize(10);
     assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(10);
   }
 
   @Test
-  void getUuidValues_shouldAnonymizeUserUuids() {
+  void getValues_shouldAnonymizeUserUuids() {
     UserDto userDto1 = db.users().insertUser();
     UserDto userDto2 = db.users().insertUser();
     db.getSession().commit();
 
-    Map<String, Boolean> uuidValues = underTest.getUuidValues();
+    Map<String, Boolean> uuidValues = underTest.getValues();
 
     String anonymizedUser1 = DigestUtil.sha3_224Hex(userDto1.getUuid());
     String anonymizedUser2 = DigestUtil.sha3_224Hex(userDto2.getUuid());
index 18ad598623962f17c525a129625284160f0ef7b1..3bb99f3731fe74f6066acfd2bd2183707da48415 100644 (file)
@@ -36,6 +36,7 @@ import org.sonar.server.platform.db.migration.DatabaseMigrationStateImpl;
 import org.sonar.server.platform.db.migration.MigrationConfigurationModule;
 import org.sonar.server.platform.db.migration.charset.DatabaseCharsetChecker;
 import org.sonar.server.platform.db.migration.version.DatabaseVersion;
+import org.sonar.server.telemetry.TelemetryDbMigrationStepDurationProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationSuccessProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationStepsProvider;
 import org.sonar.server.telemetry.TelemetryDbMigrationTotalTimeProvider;
@@ -90,6 +91,7 @@ public class PlatformLevel2 extends PlatformLevel {
       TelemetryDbMigrationTotalTimeProvider.class,
       TelemetryDbMigrationStepsProvider.class,
       TelemetryDbMigrationSuccessProvider.class,
+      TelemetryDbMigrationStepDurationProvider.class,
       DatabaseMigrationStateImpl.class,
       DatabaseMigrationExecutorServiceImpl.class);
 
index 64f5130a3598f8f94b38f96d54bb74485bf96f42..51382bbebe91e6600e8b5a4ef1b62c9e0021b127 100644 (file)
@@ -62,7 +62,7 @@ public class ProjectCppAutoconfigTelemetryProvider implements TelemetryDataProvi
   }
 
   @Override
-  public Map<String, String> getUuidValues() {
+  public Map<String, String> getValues() {
     Map<String, String> cppConfigTypePerProjectUuid = new HashMap<>();
     try (DbSession dbSession = dbClient.openSession(true)) {
       // In the future ideally languages should be defined in the codebase as enums, using strings is error-prone
index 81f683cb96a8ecf8ee2176d2c3f95aa7a8303666..0d93c951d08150695b8169d536bf41ed9c9ef5f9 100644 (file)
@@ -68,7 +68,7 @@ public class TelemetryNclocProvider implements TelemetryDataProvider<Long> {
   }
 
   @Override
-  public Map<String, Long> getUuidValues() {
+  public Map<String, Long> getValues() {
     try (DbSession dbSession = dbClient.openSession(false)) {
       return getNclocDistribution(dbSession);
     }
index fa3aff0b38eb17c4730c0dfcc0c5a240589991cc..878fda62ba5065e4e7875b3b648b1b8634c81afa 100644 (file)
@@ -61,7 +61,7 @@ public class TelemetryUserEnabledProvider implements TelemetryDataProvider<Boole
   }
 
   @Override
-  public Map<String, Boolean> getUuidValues() {
+  public Map<String, Boolean> getValues() {
     Map<String, Boolean> result = new HashMap<>();
     int pageSize = 1000;
     int page = 1;
index cf7fb74b3149cf1fa5e054f9589a7615768897ad..d91e00f8d671dfdbbd7bc78dcc889ca78ff08cd2 100644 (file)
@@ -31,9 +31,9 @@ import org.sonar.server.platform.db.migration.charset.DatabaseCharsetChecker;
 import org.sonar.server.plugins.ServerPluginRepository;
 
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.atLeastOnce;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.sonar.process.ProcessProperties.Property.PATH_DATA;
@@ -73,7 +73,7 @@ public class PlatformLevel2Test {
 
     verify(container).add(ServerPluginRepository.class);
     verify(container).add(DatabaseCharsetChecker.class);
-    verify(container, times(24)).add(any());
+    verify(container, atLeastOnce()).add(any());
   }
 
   @Test
@@ -94,7 +94,7 @@ public class PlatformLevel2Test {
 
     verify(container).add(ServerPluginRepository.class);
     verify(container, never()).add(DatabaseCharsetChecker.class);
-    verify(container, times(22)).add(any());
+    verify(container, atLeastOnce()).add(any());
   }
 
 
index 40174aafa13879bf01be686dff6797cd2db5e677..78144729ddb4c0eaf1138603ddb9e91fa15b1e7f 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.telemetry.core.Granularity;
 import org.sonar.telemetry.core.TelemetryDataType;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assumptions.assumeFalse;
 import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
@@ -60,7 +59,6 @@ class TelemetryFipsEnabledProviderTest {
     assertEquals(Granularity.DAILY, telemetryVersionProvider.getGranularity());
     assertEquals(TelemetryDataType.BOOLEAN, telemetryVersionProvider.getType());
     assertEquals(Optional.of(expectedFipsEnabled), telemetryVersionProvider.getValue());
-    assertThrows(IllegalStateException.class, telemetryVersionProvider::getUuidValues);
   }
 
 }
index 6bfd81a6e91b38e65a295e405ac117209f4db762..5bab0a2cf3c48309f49025890640597cc304214d 100644 (file)
@@ -44,7 +44,7 @@ class TelemetryNclocProviderTest {
   private final DbSession dbSession = mock(DbSession.class);
 
   @Test
-  void getUuidValues_returnsTheRightLanguageDistribution() {
+  void getValues_returnsTheRightLanguageDistribution() {
     TelemetryNclocProvider telemetryNclocProvider = new TelemetryNclocProvider(dbClient);
 
     when(dbClient.openSession(false)).thenReturn(dbSession);
@@ -64,10 +64,10 @@ class TelemetryNclocProviderTest {
     assertEquals(Granularity.DAILY, telemetryNclocProvider.getGranularity());
     assertEquals(Dimension.LANGUAGE, telemetryNclocProvider.getDimension());
 
-    assertThat(telemetryNclocProvider.getUuidValues()).containsOnlyKeys("java", "xml", "csharp", "js");
-    assertThat(telemetryNclocProvider.getUuidValues()).containsEntry("java", 22000L);
-    assertThat(telemetryNclocProvider.getUuidValues()).containsEntry("xml", 1000L);
-    assertThat(telemetryNclocProvider.getUuidValues()).containsEntry("csharp", 2000L);
-    assertThat(telemetryNclocProvider.getUuidValues()).containsEntry("js", 1500L);
+    assertThat(telemetryNclocProvider.getValues()).containsOnlyKeys("java", "xml", "csharp", "js");
+    assertThat(telemetryNclocProvider.getValues()).containsEntry("java", 22000L);
+    assertThat(telemetryNclocProvider.getValues()).containsEntry("xml", 1000L);
+    assertThat(telemetryNclocProvider.getValues()).containsEntry("csharp", 2000L);
+    assertThat(telemetryNclocProvider.getValues()).containsEntry("js", 1500L);
   }
 }
\ No newline at end of file
index d13295312b84e074e863a44a4d4180e8a23c3fa2..b732036b23578b6eaee07272381048f6fea75c3e 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.telemetry.core.Granularity;
 import org.sonar.telemetry.core.TelemetryDataType;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -48,6 +47,5 @@ class TelemetryVersionProviderTest {
     assertEquals(Granularity.DAILY, telemetryVersionProvider.getGranularity());
     assertEquals(TelemetryDataType.STRING, telemetryVersionProvider.getType());
     assertEquals(Optional.of("10.6"), telemetryVersionProvider.getValue());
-    assertThrows(IllegalStateException.class, telemetryVersionProvider::getUuidValues);
   }
 }