From: Alain Kermis Date: Wed, 17 Jul 2024 12:48:57 +0000 (+0200) Subject: SONAR-22479 Create telemetry-core module X-Git-Tag: 10.7.0.96327~329 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b128adde3ba0a0b20189f90fde15d94490c7de52;p=sonarqube.git SONAR-22479 Create telemetry-core module --- diff --git a/server/sonar-telemetry-core/build.gradle b/server/sonar-telemetry-core/build.gradle new file mode 100644 index 00000000000..010d750923a --- /dev/null +++ b/server/sonar-telemetry-core/build.gradle @@ -0,0 +1,24 @@ +description = 'Module providing the core classes and interfaces for telemetry metrics in SonarQube.' + +sonar { + properties { + property 'sonar.projectName', "${projectTitle} :: Server :: Telemetry Core" + } +} + +dependencies { + compileOnlyApi 'com.github.spotbugs:spotbugs-annotations' + + implementation 'com.fasterxml.jackson.core:jackson-databind' + + testImplementation(platform("org.junit:junit-bom:5.9.1")) + testImplementation 'org.assertj:assertj-core' + testImplementation 'org.junit.jupiter:junit-jupiter-api' + testImplementation 'org.junit.jupiter:junit-jupiter-params' + + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/Dimension.java b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/Dimension.java new file mode 100644 index 00000000000..96f9ce5b5fd --- /dev/null +++ b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/Dimension.java @@ -0,0 +1,54 @@ +/* + * 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.core; + +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-core/src/main/java/org/sonar/telemetry/core/Granularity.java b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/Granularity.java new file mode 100644 index 00000000000..be5cd22bb93 --- /dev/null +++ b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/Granularity.java @@ -0,0 +1,44 @@ +/* + * 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.core; + +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-core/src/main/java/org/sonar/telemetry/core/TelemetryDataProvider.java b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/TelemetryDataProvider.java new file mode 100644 index 00000000000..a464014e767 --- /dev/null +++ b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/TelemetryDataProvider.java @@ -0,0 +1,78 @@ +/* + * 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.core; + +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 type of the value provided by this instance. Should be either {@link Boolean}, {@link String}, + * {@link Integer} or {@link Float}. + */ +public interface TelemetryDataProvider { + + /** + * @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 getUuidValues() { + throw new IllegalStateException("Not implemented"); + } +} diff --git a/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/TelemetryDataType.java b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/TelemetryDataType.java new file mode 100644 index 00000000000..5f096d0dcfa --- /dev/null +++ b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/TelemetryDataType.java @@ -0,0 +1,44 @@ +/* + * 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.core; + +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-core/src/main/java/org/sonar/telemetry/core/package-info.java b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/package-info.java new file mode 100644 index 00000000000..1b573068f64 --- /dev/null +++ b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/package-info.java @@ -0,0 +1,23 @@ +/* + * 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.core; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/DimensionTest.java b/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/DimensionTest.java new file mode 100644 index 00000000000..6c2c74b5892 --- /dev/null +++ b/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/DimensionTest.java @@ -0,0 +1,56 @@ +/* + * 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.core; + +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-core/src/test/java/org/sonar/telemetry/core/GranularityTest.java b/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/GranularityTest.java new file mode 100644 index 00000000000..a4b01e93305 --- /dev/null +++ b/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/GranularityTest.java @@ -0,0 +1,35 @@ +/* + * 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.core; + +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-core/src/test/java/org/sonar/telemetry/core/TelemetryDataTypeTest.java b/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/TelemetryDataTypeTest.java new file mode 100644 index 00000000000..4749a858364 --- /dev/null +++ b/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/TelemetryDataTypeTest.java @@ -0,0 +1,35 @@ +/* + * 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.core; + +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/build.gradle b/server/sonar-telemetry/build.gradle index 4ab65454207..273895ca6db 100644 --- a/server/sonar-telemetry/build.gradle +++ b/server/sonar-telemetry/build.gradle @@ -7,6 +7,14 @@ sonar { } dependencies { + api project(':server:sonar-telemetry-core') + + implementation project(':server:sonar-process') + implementation project(':server:sonar-server-common') + implementation project(':server:sonar-webserver-core') + implementation project(':server:sonar-webserver-webapi') + implementation project(':sonar-core') + testImplementation(platform("org.junit:junit-bom:5.9.1")) testImplementation 'com.squareup.okhttp3:mockwebserver' testImplementation 'com.tngtech.java:junit-dataprovider' @@ -18,12 +26,6 @@ dependencies { testImplementation project(':sonar-testing-harness') testImplementation testFixtures(project(':server:sonar-server-common')) - api project(':server:sonar-process') - api project(':server:sonar-server-common') - api project(':server:sonar-webserver-core') - api project(':server:sonar-webserver-webapi') - api project(':sonar-core') - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' } 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 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 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 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 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 actualResult = underTest.getUuidValues(); - - assertThat(actualResult).hasSize(2); - assertThat(actualResult).containsExactlyInAnyOrderEntriesOf(Map.of(project1.getProjectDto().getUuid(), "BW_DEPRECATED", - project2.getProjectDto().getUuid(), "COMPDB")); - } - - private Consumer 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 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 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 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 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 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 type of the value provided by this instance. Should be either {@link Boolean}, {@link String}, - * {@link Integer} or {@link Float}. - */ -public interface TelemetryDataProvider { - - /** - * @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 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> 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 { - - 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 getUuidValues() { - Map 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 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 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 { - - 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 getUuidValues() { - Map result = new HashMap<>(); - int pageSize = 1000; - int page = 1; - try (DbSession dbSession = dbClient.openSession(false)) { - List 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 { 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); - } -} 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 new file mode 100644 index 00000000000..ee6c1f578e9 --- /dev/null +++ b/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java @@ -0,0 +1,136 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.telemetry; + +import java.util.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 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 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 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 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 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 actualResult = underTest.getUuidValues(); + + assertThat(actualResult).hasSize(2); + assertThat(actualResult).containsExactlyInAnyOrderEntriesOf(Map.of(project1.getProjectDto().getUuid(), "BW_DEPRECATED", + project2.getProjectDto().getUuid(), "COMPDB")); + } + + private Consumer 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 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-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 new file mode 100644 index 00000000000..f0466dac7a8 --- /dev/null +++ b/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java @@ -0,0 +1,95 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.telemetry; + +import java.util.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 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 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 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 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-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index aa63a07edd1..da7ff01ea80 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -184,7 +184,9 @@ import org.sonar.server.platform.PersistentSettings; import org.sonar.server.platform.SystemInfoWriterModule; import org.sonar.server.platform.WebCoreExtensionsInstaller; import org.sonar.server.platform.db.CheckAnyonePermissionsAtStartup; +import org.sonar.server.platform.telemetry.ProjectCppAutoconfigTelemetryProvider; import org.sonar.server.platform.telemetry.TelemetryNclocProvider; +import org.sonar.server.platform.telemetry.TelemetryUserEnabledProvider; import org.sonar.server.platform.telemetry.TelemetryVersionProvider; import org.sonar.server.platform.web.ActionDeprecationLoggerInterceptor; import org.sonar.server.platform.web.SonarLintConnectionFilter; @@ -290,8 +292,6 @@ import org.sonar.telemetry.legacy.QualityProfileDataProvider; import org.sonar.telemetry.legacy.TelemetryDataJsonWriter; import org.sonar.telemetry.legacy.TelemetryDataLoaderImpl; import org.sonar.telemetry.metrics.TelemetryMetricsLoader; -import org.sonar.telemetry.project.ProjectCppAutoconfigTelemetryProvider; -import org.sonar.telemetry.user.TelemetryUserEnabledProvider; import static org.sonar.core.extension.CoreExtensionsInstaller.noAdditionalSideFilter; import static org.sonar.core.extension.PlatformLevelPredicates.hasPlatformLevel4OrNone; 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 new file mode 100644 index 00000000000..6473c1238e2 --- /dev/null +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java @@ -0,0 +1,97 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.telemetry; + +import java.util.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.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataProvider; +import org.sonar.telemetry.core.TelemetryDataType; + +public class ProjectCppAutoconfigTelemetryProvider implements TelemetryDataProvider { + + 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 getUuidValues() { + Map 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 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 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-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 5e3fa11b544..81f683cb96a 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 @@ -27,10 +27,10 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.measure.ProjectLocDistributionDto; import org.sonar.db.metric.MetricDto; -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 static java.util.Arrays.asList; import static java.util.stream.Collectors.toMap; 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 new file mode 100644 index 00000000000..fa3aff0b38e --- /dev/null +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.telemetry; + +import java.util.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.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataProvider; +import org.sonar.telemetry.core.TelemetryDataType; + +public class TelemetryUserEnabledProvider implements TelemetryDataProvider { + + 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 getUuidValues() { + Map result = new HashMap<>(); + int pageSize = 1000; + int page = 1; + try (DbSession dbSession = dbClient.openSession(false)) { + List 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-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java index d76962b7cea..850190948ba 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java @@ -20,10 +20,10 @@ package org.sonar.server.platform.telemetry; import org.sonar.api.platform.Server; -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 TelemetryVersionProvider implements TelemetryDataProvider { diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java new file mode 100644 index 00000000000..295d03b07b1 --- /dev/null +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java @@ -0,0 +1,42 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.telemetry; + +import org.junit.jupiter.api.Test; +import org.sonar.db.DbClient; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.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-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 7c9752a8088..6bfd81a6e91 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 @@ -26,8 +26,8 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.measure.ProjectLocDistributionDto; import org.sonar.db.metric.MetricDto; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderTest.java new file mode 100644 index 00000000000..d8b2e91f52b --- /dev/null +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderTest.java @@ -0,0 +1,44 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.telemetry; + +import org.junit.jupiter.api.Test; +import org.sonar.db.DbClient; +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.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); + } +} 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 d5ea987eb6d..1a14d52bbf3 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 @@ -21,9 +21,9 @@ package org.sonar.server.platform.telemetry; import org.junit.jupiter.api.Test; import org.sonar.api.platform.Server; -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.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; diff --git a/settings.gradle b/settings.gradle index b2a54bb3716..6221bc05bc2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -45,6 +45,7 @@ include 'server:sonar-main' include 'server:sonar-process' include 'server:sonar-server-common' include 'server:sonar-telemetry' +include 'server:sonar-telemetry-core' include 'server:sonar-web' include 'server:sonar-web:design-system' include 'server:sonar-webserver'