diff options
author | lukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com> | 2024-09-06 08:47:33 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-09-06 20:02:37 +0000 |
commit | cd40a38f951a1355c086b99017401b93bd203558 (patch) | |
tree | b8c9fe11385b7951a637cf2a5ce6c4ab091f38bc /server/sonar-webserver/src | |
parent | 0996c6186cfeb8e2c763d2f174b26ab276b232f7 (diff) | |
download | sonarqube-cd40a38f951a1355c086b99017401b93bd203558.tar.gz sonarqube-cd40a38f951a1355c086b99017401b93bd203558.zip |
SONAR-22891 added new telemetry metric
Diffstat (limited to 'server/sonar-webserver/src')
10 files changed, 30 insertions, 32 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 index 666965be5cc..3ad5a8f3d6a 100644 --- 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 @@ -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( diff --git a/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java b/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java index f0466dac7a8..fee743fd088 100644 --- a/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java +++ b/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java @@ -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()); diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java index 18ad5986239..3bb99f3731f 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java @@ -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); 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 index 64f5130a359..51382bbebe9 100644 --- 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 @@ -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 diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java index 81f683cb96a..0d93c951d08 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java @@ -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); } diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java index fa3aff0b38e..878fda62ba5 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java @@ -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; diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java index cf7fb74b314..d91e00f8d67 100644 --- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/platformlevel/PlatformLevel2Test.java @@ -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()); } diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProviderTest.java index 40174aafa13..78144729ddb 100644 --- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProviderTest.java +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProviderTest.java @@ -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); } } diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryNclocProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryNclocProviderTest.java index 6bfd81a6e91..5bab0a2cf3c 100644 --- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryNclocProviderTest.java +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryNclocProviderTest.java @@ -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 diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryVersionProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryVersionProviderTest.java index d13295312b8..b732036b235 100644 --- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryVersionProviderTest.java +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryVersionProviderTest.java @@ -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); } } |