diff options
author | Alain Kermis <alain.kermis@sonarsource.com> | 2024-07-17 14:48:57 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-07-24 20:02:48 +0000 |
commit | b128adde3ba0a0b20189f90fde15d94490c7de52 (patch) | |
tree | d3531ec2233daad5a38f54a317cd9eaff0306be8 /server/sonar-telemetry/src | |
parent | ffb8e4af38b27af60d9ba3127f7925580c59ca3f (diff) | |
download | sonarqube-b128adde3ba0a0b20189f90fde15d94490c7de52.tar.gz sonarqube-b128adde3ba0a0b20189f90fde15d94490c7de52.zip |
SONAR-22479 Create telemetry-core module
Diffstat (limited to 'server/sonar-telemetry/src')
34 files changed, 42 insertions, 930 deletions
diff --git a/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java b/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java index 91743dc5fb0..f264fc8c107 100644 --- a/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java +++ b/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java @@ -25,9 +25,9 @@ import org.junit.jupiter.api.Test; import org.sonar.api.impl.utils.TestSystem2; import org.sonar.core.util.UuidFactory; import org.sonar.db.DbTester; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.TelemetryDataProvider; import org.sonar.telemetry.FakeServer; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.TelemetryDataProvider; import org.sonar.telemetry.metrics.schema.BaseMessage; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-telemetry/src/it/java/org/sonar/telemetry/project/ProjectCppAutoconfigTelemetryProviderIT.java b/server/sonar-telemetry/src/it/java/org/sonar/telemetry/project/ProjectCppAutoconfigTelemetryProviderIT.java deleted file mode 100644 index 1b9e7e2d0b3..00000000000 --- a/server/sonar-telemetry/src/it/java/org/sonar/telemetry/project/ProjectCppAutoconfigTelemetryProviderIT.java +++ /dev/null @@ -1,137 +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.telemetry.project; - -import java.util.Map; -import java.util.function.Consumer; -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.ComponentDto; -import org.sonar.db.component.ProjectData; -import org.sonar.db.measure.LiveMeasureDto; -import org.sonar.db.metric.MetricDto; -import org.sonar.db.project.ProjectDto; -import org.sonar.telemetry.project.ProjectCppAutoconfigTelemetryProvider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY; -import static org.sonar.api.measures.Metric.ValueType.STRING; - -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 getUuidValues_whenNoProjects_returnEmptyList() { - assertThat(underTest.getUuidValues()).isEmpty(); - } - - @Test - void getUuidValues_whenNoCppAndCProjects_returnEmptyMap() { - Consumer<MetricDto> configureMetric = metric -> metric - .setValueType(STRING.name()) - .setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY); - - MetricDto metric = db.measures().insertMetric(configureMetric); - - ProjectData project1 = db.components().insertPrivateProject(); - ProjectData project2 = db.components().insertPrivateProject(); - - insertLiveMeasure("java", metric).accept(project1); - insertLiveMeasure("cobol", metric).accept(project2); - - - assertThat(underTest.getUuidValues()).isEmpty(); - } - - @Test - void getUuidValues_when1CppAnd1CProject_returnMapWithSize2AndAutoconfigByDefault() { - Consumer<MetricDto> configureMetric = metric -> metric - .setValueType(STRING.name()) - .setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY); - - MetricDto metric = db.measures().insertMetric(configureMetric); - - ProjectData project1 = db.components().insertPrivateProject(); - ProjectData project2 = db.components().insertPrivateProject(); - ProjectData project3 = db.components().insertPrivateProject(); - ProjectData project4 = db.components().insertPrivateProject(); - - insertLiveMeasure("c", metric).accept(project1); - insertLiveMeasure("cpp", metric).accept(project2); - insertLiveMeasure("java", metric).accept(project3); - insertLiveMeasure("cobol", metric).accept(project4); - - Map<String, String> actualResult = underTest.getUuidValues(); - - assertThat(actualResult).hasSize(2); - assertThat(actualResult).containsExactlyInAnyOrderEntriesOf(Map.of(project1.getProjectDto().getUuid(), "AUTOCONFIG", - project2.getProjectDto().getUuid(), "AUTOCONFIG")); - } - - @Test - void getUuidValues_whenCAndCppProjectsWithDifferentConfig_returnMapWithSize2AndNotAutoconfig() { - Consumer<MetricDto> configureMetric = metric -> metric - .setValueType(STRING.name()) - .setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY); - - MetricDto metric = db.measures().insertMetric(configureMetric); - - ProjectData project1 = db.components().insertPrivateProject(); - ProjectData project2 = db.components().insertPrivateProject(); - ProjectData project3 = db.components().insertPrivateProject(); - ProjectData project4 = db.components().insertPrivateProject(); - - insertLiveMeasure("c", metric).accept(project1); - insertLiveMeasure("cpp", metric).accept(project2); - insertLiveMeasure("java", metric).accept(project3); - insertLiveMeasure("cobol", metric).accept(project4); - - 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(); - - assertThat(actualResult).hasSize(2); - assertThat(actualResult).containsExactlyInAnyOrderEntriesOf(Map.of(project1.getProjectDto().getUuid(), "BW_DEPRECATED", - project2.getProjectDto().getUuid(), "COMPDB")); - } - - private Consumer<LiveMeasureDto> configureLiveMeasure(String language, MetricDto metric, ProjectDto project, ComponentDto componentDto) { - return liveMeasure -> liveMeasure - .setMetricUuid(metric.getUuid()) - .setComponentUuid(componentDto.uuid()) - .setProjectUuid(project.getUuid()) - .setData(language + "=" + 100); - } - - private Consumer<ProjectData> insertLiveMeasure(String language, MetricDto metric) { - return projectData -> db.measures().insertLiveMeasure(projectData.getMainBranchComponent(), metric, - configureLiveMeasure(language, metric, projectData.getProjectDto(), projectData.getMainBranchComponent())); - } -} diff --git a/server/sonar-telemetry/src/it/java/org/sonar/telemetry/user/TelemetryUserEnabledProviderIT.java b/server/sonar-telemetry/src/it/java/org/sonar/telemetry/user/TelemetryUserEnabledProviderIT.java deleted file mode 100644 index aa8c502f110..00000000000 --- a/server/sonar-telemetry/src/it/java/org/sonar/telemetry/user/TelemetryUserEnabledProviderIT.java +++ /dev/null @@ -1,95 +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.telemetry.user; - -import java.util.Map; -import org.junit.Rule; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.sonar.api.impl.utils.AlwaysIncreasingSystem2; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; -import org.sonar.db.user.UserDto; -import org.sonar.server.util.DigestUtil; - -import static org.assertj.core.api.Assertions.assertThat; - -class TelemetryUserEnabledProviderIT { - - private final System2 system2 = new AlwaysIncreasingSystem2(); - - @Rule - public final DbTester db = DbTester.create(system2); - - - private final TelemetryUserEnabledProvider underTest = new TelemetryUserEnabledProvider(db.getDbClient()); - - @BeforeEach - public void beforeEach() { - db.executeUpdateSql("delete from users"); - } - - @Test - void getUuidValues_whenNoUsersInDatabase_shouldReturnEmptyMap() { - Map<String, Boolean> uuidValues = underTest.getUuidValues(); - - assertThat(uuidValues).isEmpty(); - } - - @Test - void getUuidValues_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(); - - assertThat(uuidValues).hasSize(2); - assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(1); - assertThat(uuidValues.values().stream().filter(b -> !b)).hasSize(1); - } - - @Test - void getUuidValues_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(); - - assertThat(uuidValues).hasSize(10); - assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(10); - } - - @Test - void getUuidValues_shouldAnonymizeUserUuids() { - UserDto userDto1 = db.users().insertUser(); - UserDto userDto2 = db.users().insertUser(); - db.getSession().commit(); - - Map<String, Boolean> uuidValues = underTest.getUuidValues(); - - String anonymizedUser1 = DigestUtil.sha3_224Hex(userDto1.getUuid()); - String anonymizedUser2 = DigestUtil.sha3_224Hex(userDto2.getUuid()); - assertThat(uuidValues.keySet()).containsExactlyInAnyOrder(anonymizedUser1, anonymizedUser2); - } - -} diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/Dimension.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/Dimension.java deleted file mode 100644 index b30efed0fca..00000000000 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/Dimension.java +++ /dev/null @@ -1,54 +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.telemetry; - -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * Represents the dimension of the data provided by a {@link TelemetryDataProvider}. - * {@link Dimension#PROJECT}, {@link Dimension#LANGUAGE} and {@link Dimension#USER} should not provide aggregated data. - * For aggregated data (i.e. average number of lines of code per project), use #INSTALLATION. - */ -public enum Dimension { - INSTALLATION("installation"), - USER("user"), - PROJECT("project"), - LANGUAGE("language"); - - private final String value; - - Dimension(String value) { - this.value = value; - } - - @JsonValue - public String getValue() { - return value; - } - - public static Dimension fromValue(String value) { - for (Dimension dimension : Dimension.values()) { - if (dimension.value.equalsIgnoreCase(value)) { - return dimension; - } - } - throw new IllegalArgumentException("Unknown dimension value: " + value); - } -} diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/Granularity.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/Granularity.java deleted file mode 100644 index 7c350868406..00000000000 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/Granularity.java +++ /dev/null @@ -1,44 +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.telemetry; - -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * Represent the granularity of the data provided by a {@link TelemetryDataProvider}. This both defines the time period between to pushes to - * telemetry server for a given metric and the time period that the data represents. - * Modifying this enum needs to be discussed beforehand with Data Platform team. - */ -public enum Granularity { - DAILY("daily"), - WEEKLY("weekly"), - MONTHLY("monthly"); - - private final String value; - - Granularity(String value) { - this.value = value; - } - - @JsonValue - public String getValue() { - return value; - } -} diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDataProvider.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDataProvider.java deleted file mode 100644 index fb0f7f8ebef..00000000000 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDataProvider.java +++ /dev/null @@ -1,78 +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.telemetry; - -import java.util.Map; - -/** - * This interface is used to provide data to the telemetry system. The telemetry system will call the methods of this interface to get the - * data that will be sent to the telemetry server. - * If you want to add new metric to the telemetry system, you need to create a new implementation of this interface and register it in the - * Spring context as a bean. - * - * @param <T> type of the value provided by this instance. Should be either {@link Boolean}, {@link String}, - * {@link Integer} or {@link Float}. - */ -public interface TelemetryDataProvider<T> { - - /** - * @return the key of the metric that will be used to store the value of the data provided by this instance. The combination of - * metric key and dimension needs to be universally unique. The metric key needs to be written in snake_case. - */ - String getMetricKey(); - - /** - * @return the dimension ("category") of the data provided by this instance. The combination of metric key and dimension needs to be - * universally unique. - */ - Dimension getDimension(); - - /** - * @return returns the granularity of this telemetry metric. - * @see Granularity - */ - Granularity getGranularity(); - - /** - * @return the type of the data provided by this instance. - */ - TelemetryDataType getType(); - - /** - * 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. - * - * @return the value of the data provided by this instance. - */ - default T getValue() { - throw new IllegalStateException("Not implemented"); - } - - /** - * 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. - * - * @return map of UUIDs and their values. - */ - default Map<String, T> getUuidValues() { - throw new IllegalStateException("Not implemented"); - } -} diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDataType.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDataType.java deleted file mode 100644 index a59bd03e34e..00000000000 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDataType.java +++ /dev/null @@ -1,44 +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.telemetry; - -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * Represents the type of the data provided by a {@link TelemetryDataProvider}. - * Modifying this enum needs to be discussed beforehand with Data Platform team. - */ -public enum TelemetryDataType { - BOOLEAN("boolean"), - STRING("string"), - INTEGER("integer"), - FLOAT("float"); - - private final String value; - - TelemetryDataType(String value) { - this.value = value; - } - - @JsonValue - public String getValue() { - return value; - } -} diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsLoader.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsLoader.java index e7cf201a73a..5cb2e69e242 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsLoader.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsLoader.java @@ -32,8 +32,8 @@ import org.sonar.core.util.UuidFactory; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.telemetry.TelemetryMetricsSentDto; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.TelemetryDataProvider; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.TelemetryDataProvider; import org.sonar.telemetry.metrics.schema.BaseMessage; import org.sonar.telemetry.metrics.schema.Metric; import org.sonar.telemetry.metrics.util.SentMetricsStorage; diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java index 645798bf721..f6ff629effb 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java @@ -22,7 +22,7 @@ package org.sonar.telemetry.metrics; import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; -import org.sonar.telemetry.TelemetryDataProvider; +import org.sonar.telemetry.core.TelemetryDataProvider; import org.sonar.telemetry.metrics.schema.InstallationMetric; import org.sonar.telemetry.metrics.schema.LanguageMetric; import org.sonar.telemetry.metrics.schema.Metric; diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/BaseMessage.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/BaseMessage.java index 2bbbbf2753f..2c4ad2b725d 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/BaseMessage.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/BaseMessage.java @@ -22,7 +22,7 @@ package org.sonar.telemetry.metrics.schema; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; import java.util.Set; -import org.sonar.telemetry.Dimension; +import org.sonar.telemetry.core.Dimension; public class BaseMessage { @JsonProperty("message_uuid") diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/InstallationMetric.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/InstallationMetric.java index 0c3eea43c09..0f0a2abc0fe 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/InstallationMetric.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/InstallationMetric.java @@ -19,8 +19,8 @@ */ package org.sonar.telemetry.metrics.schema; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; public class InstallationMetric extends Metric { diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/LanguageMetric.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/LanguageMetric.java index 766dcf9cbe6..236c31d7d38 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/LanguageMetric.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/LanguageMetric.java @@ -20,8 +20,8 @@ package org.sonar.telemetry.metrics.schema; import com.fasterxml.jackson.annotation.JsonProperty; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; public class LanguageMetric extends Metric { diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/Metric.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/Metric.java index efdf43d0dd7..ad5c17f5194 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/Metric.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/Metric.java @@ -20,8 +20,8 @@ package org.sonar.telemetry.metrics.schema; import com.fasterxml.jackson.annotation.JsonProperty; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; public abstract class Metric { @JsonProperty("key") diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/ProjectMetric.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/ProjectMetric.java index 421d2e79ca6..fc9ff8e4cd4 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/ProjectMetric.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/ProjectMetric.java @@ -20,8 +20,8 @@ package org.sonar.telemetry.metrics.schema; import com.fasterxml.jackson.annotation.JsonProperty; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; public class ProjectMetric extends Metric { diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/UserMetric.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/UserMetric.java index a9ff05657df..2af08ca023e 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/UserMetric.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/UserMetric.java @@ -20,8 +20,8 @@ package org.sonar.telemetry.metrics.schema; import com.fasterxml.jackson.annotation.JsonProperty; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; public class UserMetric extends Metric { diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/util/SentMetricsStorage.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/util/SentMetricsStorage.java index 36ab85505b1..3f8b7c73cc6 100644 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/util/SentMetricsStorage.java +++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/util/SentMetricsStorage.java @@ -29,8 +29,8 @@ import java.util.List; import java.util.Map; import java.util.Optional; import org.sonar.db.telemetry.TelemetryMetricsSentDto; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; public class SentMetricsStorage { private final Map<Dimension, Map<String, TelemetryMetricsSentDto>> dimensionMetricKeyMap = new EnumMap<>(Dimension.class); diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/project/ProjectCppAutoconfigTelemetryProvider.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/project/ProjectCppAutoconfigTelemetryProvider.java deleted file mode 100644 index caa0b900485..00000000000 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/project/ProjectCppAutoconfigTelemetryProvider.java +++ /dev/null @@ -1,97 +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.telemetry.project; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.project.ProjectDto; -import org.sonar.db.property.PropertyDto; -import org.sonar.db.property.PropertyQuery; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; -import org.sonar.telemetry.TelemetryDataProvider; - -public class ProjectCppAutoconfigTelemetryProvider implements TelemetryDataProvider<String> { - - private final DbClient dbClient; - - public ProjectCppAutoconfigTelemetryProvider(DbClient dbClient) { - this.dbClient = dbClient; - } - - @Override - public String getMetricKey() { - return "project_cpp_config_type"; - } - - @Override - public Dimension getDimension() { - return Dimension.PROJECT; - } - - @Override - public Granularity getGranularity() { - return Granularity.WEEKLY; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.STRING; - } - - @Override - public Map<String, String> getUuidValues() { - Map<String, String> cppConfigTypePerProjectUuid = new HashMap<>(); - try (DbSession dbSession = dbClient.openSession(true)) { - //TODO in the feature ideally languages should be defined in the codebase as enums, using strings is error-prone - List<ProjectDto> cppProjects = dbClient.projectDao().selectProjectsByLanguage(dbSession, Set.of("cpp", "c")); - for (ProjectDto cppProject : cppProjects) { - CppConfigType cppConfigType = getCppConfigType(cppProject, dbSession); - cppConfigTypePerProjectUuid.put(cppProject.getUuid(), cppConfigType.name()); - } - } - return cppConfigTypePerProjectUuid; - } - - private CppConfigType getCppConfigType(ProjectDto project, DbSession dbSession) { - List<PropertyDto> propertyDtos = dbClient.propertiesDao().selectByQuery(PropertyQuery - .builder() - .setEntityUuid(project.getUuid()) - .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-telemetry/src/main/java/org/sonar/telemetry/project/package-info.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/project/package-info.java deleted file mode 100644 index 3d6bbd23974..00000000000 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/project/package-info.java +++ /dev/null @@ -1,23 +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. - */ -@ParametersAreNonnullByDefault -package org.sonar.telemetry.project; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/user/TelemetryUserEnabledProvider.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/user/TelemetryUserEnabledProvider.java deleted file mode 100644 index fb7358e1ab6..00000000000 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/user/TelemetryUserEnabledProvider.java +++ /dev/null @@ -1,81 +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.telemetry.user; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.sonar.db.DbClient; -import org.sonar.db.DbSession; -import org.sonar.db.user.UserDto; -import org.sonar.db.user.UserQuery; -import org.sonar.server.util.DigestUtil; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataProvider; -import org.sonar.telemetry.TelemetryDataType; - -public class TelemetryUserEnabledProvider implements TelemetryDataProvider<Boolean> { - - private final DbClient dbClient; - - public TelemetryUserEnabledProvider(DbClient dbClient) { - this.dbClient = dbClient; - } - - @Override - public String getMetricKey() { - return "user_enabled"; - } - - @Override - public Dimension getDimension() { - return Dimension.USER; - } - - @Override - public Granularity getGranularity() { - return Granularity.DAILY; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.BOOLEAN; - } - - @Override - public Map<String, Boolean> getUuidValues() { - Map<String, Boolean> result = new HashMap<>(); - int pageSize = 1000; - int page = 1; - try (DbSession dbSession = dbClient.openSession(false)) { - List<UserDto> userDtos; - do { - userDtos = dbClient.userDao().selectUsers(dbSession, UserQuery.builder().build(), page, pageSize); - for (UserDto userDto : userDtos) { - String anonymizedUuid = DigestUtil.sha3_224Hex(userDto.getUuid()); - result.put(anonymizedUuid, userDto.isActive()); - } - page++; - } while (!userDtos.isEmpty()); - } - return result; - } -} diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/user/package-info.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/user/package-info.java deleted file mode 100644 index a8fd2a249b9..00000000000 --- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/user/package-info.java +++ /dev/null @@ -1,23 +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. - */ -@ParametersAreNonnullByDefault -package org.sonar.telemetry.user; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/DimensionTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/DimensionTest.java deleted file mode 100644 index 6c30ec72758..00000000000 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/DimensionTest.java +++ /dev/null @@ -1,56 +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.telemetry; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class DimensionTest { - @Test - void getValue() { - assertEquals("installation", Dimension.INSTALLATION.getValue()); - assertEquals("user", Dimension.USER.getValue()); - assertEquals("project", Dimension.PROJECT.getValue()); - assertEquals("language", Dimension.LANGUAGE.getValue()); - } - - @Test - void fromValue() { - assertEquals(Dimension.INSTALLATION, Dimension.fromValue("installation")); - assertEquals(Dimension.USER, Dimension.fromValue("user")); - assertEquals(Dimension.PROJECT, Dimension.fromValue("project")); - assertEquals(Dimension.LANGUAGE, Dimension.fromValue("language")); - - assertEquals(Dimension.INSTALLATION, Dimension.fromValue("INSTALLATION")); - assertEquals(Dimension.USER, Dimension.fromValue("USER")); - assertEquals(Dimension.PROJECT, Dimension.fromValue("PROJECT")); - assertEquals(Dimension.LANGUAGE, Dimension.fromValue("LANGUAGE")); - } - - @Test - void fromValue_whenInvalid() { - Exception exception = assertThrows(IllegalArgumentException.class, () -> { - Dimension.fromValue("invalid"); - }); - assertEquals("Unknown dimension value: invalid", exception.getMessage()); - } -} diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/GranularityTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/GranularityTest.java deleted file mode 100644 index dc3946d8a57..00000000000 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/GranularityTest.java +++ /dev/null @@ -1,35 +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.telemetry; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class GranularityTest { - - @Test - void getValue() { - assertEquals("daily", Granularity.DAILY.getValue()); - assertEquals("weekly", Granularity.WEEKLY.getValue()); - assertEquals("monthly", Granularity.MONTHLY.getValue()); - } - -} diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryDataTypeTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryDataTypeTest.java deleted file mode 100644 index 7d3a3cc19a5..00000000000 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryDataTypeTest.java +++ /dev/null @@ -1,35 +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.telemetry; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class TelemetryDataTypeTest { - @Test - void getValue() { - assertEquals("integer", TelemetryDataType.INTEGER.getValue()); - assertEquals("string", TelemetryDataType.STRING.getValue()); - assertEquals("boolean", TelemetryDataType.BOOLEAN.getValue()); - assertEquals("float", TelemetryDataType.FLOAT.getValue()); - } - -} diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java index 276948bd360..a4ef44b09c3 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java @@ -24,10 +24,10 @@ import java.util.List; import java.util.Set; import org.assertj.core.groups.Tuple; import org.junit.jupiter.api.Test; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataProvider; -import org.sonar.telemetry.TelemetryDataType; +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 org.sonar.telemetry.metrics.schema.InstallationMetric; import org.sonar.telemetry.metrics.schema.LanguageMetric; import org.sonar.telemetry.metrics.schema.Metric; diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TestTelemetryBean.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TestTelemetryBean.java index 876f6b025c1..e19824e84b0 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TestTelemetryBean.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TestTelemetryBean.java @@ -20,10 +20,10 @@ package org.sonar.telemetry.metrics; import java.util.Map; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataProvider; -import org.sonar.telemetry.TelemetryDataType; +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 TestTelemetryBean implements TelemetryDataProvider<String> { diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/BaseMessageTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/BaseMessageTest.java index dd50af1b46a..e702018f37e 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/BaseMessageTest.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/BaseMessageTest.java @@ -27,9 +27,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/InstallationMetricTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/InstallationMetricTest.java index 2a1215626e3..43408b7a2ba 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/InstallationMetricTest.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/InstallationMetricTest.java @@ -20,8 +20,8 @@ package org.sonar.telemetry.metrics.schema; import org.junit.jupiter.api.Test; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/LanguageMetricTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/LanguageMetricTest.java index 61c72956255..832ec3d8f03 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/LanguageMetricTest.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/LanguageMetricTest.java @@ -20,8 +20,8 @@ package org.sonar.telemetry.metrics.schema; import org.junit.jupiter.api.Test; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/ProjectMetricTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/ProjectMetricTest.java index cbcdb2c8180..7eb23fcfcf1 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/ProjectMetricTest.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/ProjectMetricTest.java @@ -20,8 +20,8 @@ package org.sonar.telemetry.metrics.schema; import org.junit.jupiter.api.Test; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/UserMetricTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/UserMetricTest.java index 2f171714b8e..04466d0909f 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/UserMetricTest.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/UserMetricTest.java @@ -20,8 +20,8 @@ package org.sonar.telemetry.metrics.schema; import org.junit.jupiter.api.Test; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/util/MessageSerializerTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/util/MessageSerializerTest.java index 098bb2dc82f..57aa2e858e0 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/util/MessageSerializerTest.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/util/MessageSerializerTest.java @@ -25,9 +25,9 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; import org.sonar.telemetry.metrics.schema.BaseMessage; import org.sonar.telemetry.metrics.schema.InstallationMetric; import org.sonar.telemetry.metrics.schema.LanguageMetric; diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/util/SentMetricsStorageTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/util/SentMetricsStorageTest.java index 8bced415452..ad2cf915d8b 100644 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/util/SentMetricsStorageTest.java +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/util/SentMetricsStorageTest.java @@ -28,8 +28,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.sonar.db.telemetry.TelemetryMetricsSentDto; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; public class SentMetricsStorageTest { diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/project/ProjectCppAutoconfigTelemetryProviderTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/project/ProjectCppAutoconfigTelemetryProviderTest.java deleted file mode 100644 index ccbf1bc9198..00000000000 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/project/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.telemetry.project; - -import org.junit.jupiter.api.Test; -import org.sonar.db.DbClient; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.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()); - } -} diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/user/TelemetryUserEnabledProviderTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/user/TelemetryUserEnabledProviderTest.java deleted file mode 100644 index 032065828ec..00000000000 --- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/user/TelemetryUserEnabledProviderTest.java +++ /dev/null @@ -1,44 +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.telemetry.user; - -import org.junit.jupiter.api.Test; -import org.sonar.db.DbClient; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -class TelemetryUserEnabledProviderTest { - - private final DbClient dbClient = mock(DbClient.class); - - private final TelemetryUserEnabledProvider underTest = new TelemetryUserEnabledProvider(dbClient); - - @Test - void testGetters() { - assertThat(underTest.getDimension()).isEqualTo(Dimension.USER); - assertThat(underTest.getGranularity()).isEqualTo(Granularity.DAILY); - assertThat(underTest.getMetricKey()).isEqualTo("user_enabled"); - assertThat(underTest.getType()).isEqualTo(TelemetryDataType.BOOLEAN); - } -} |