aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-telemetry/src
diff options
context:
space:
mode:
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>2024-10-11 12:13:17 +0200
committersonartech <sonartech@sonarsource.com>2024-10-11 20:02:43 +0000
commit38a765efec578eadc53393e65f3b6b892ab83bcf (patch)
tree9b721284a44fdf5bc64a48a278fe0c8105f8c654 /server/sonar-telemetry/src
parent3f0a34901c55eb1e204fe4028d2773f8484b513f (diff)
downloadsonarqube-38a765efec578eadc53393e65f3b6b892ab83bcf.tar.gz
sonarqube-38a765efec578eadc53393e65f3b6b892ab83bcf.zip
SONAR-23327 Added support for sending telemetry data in compute engine process
Diffstat (limited to 'server/sonar-telemetry/src')
-rw-r--r--server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java10
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryClient.java135
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDaemon.java5
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsLoader.java4
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/TelemetryMetricsMapper.java10
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/BaseMessage.java98
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/InstallationMetric.java35
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/LanguageMetric.java46
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/Metric.java70
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/ProjectMetric.java47
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/UserMetric.java47
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/package-info.java23
-rw-r--r--server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/util/MessageSerializer.java42
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryClientCompressionTest.java1
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryClientTest.java109
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryDaemonTest.java1
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/TelemetryMetricsMapperTest.java10
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/BaseMessageTest.java105
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/InstallationMetricTest.java60
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/LanguageMetricTest.java41
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/ProjectMetricTest.java47
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/UserMetricTest.java47
-rw-r--r--server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/util/MessageSerializerTest.java13
23 files changed, 29 insertions, 977 deletions
diff --git a/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java b/server/sonar-telemetry/src/it/java/org/sonar/telemetry/metrics/TelemetryMetricsLoaderIT.java
index 67e2ea872e8..7587e7c3111 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
@@ -40,11 +40,11 @@ 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.BaseMessage;
-import org.sonar.telemetry.metrics.schema.InstallationMetric;
-import org.sonar.telemetry.metrics.schema.LanguageMetric;
-import org.sonar.telemetry.metrics.schema.ProjectMetric;
-import org.sonar.telemetry.metrics.schema.UserMetric;
+import org.sonar.telemetry.core.schema.BaseMessage;
+import org.sonar.telemetry.core.schema.InstallationMetric;
+import org.sonar.telemetry.core.schema.LanguageMetric;
+import org.sonar.telemetry.core.schema.ProjectMetric;
+import org.sonar.telemetry.core.schema.UserMetric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryClient.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryClient.java
deleted file mode 100644
index c1a0a94ec7d..00000000000
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryClient.java
+++ /dev/null
@@ -1,135 +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.io.IOException;
-import okhttp3.Call;
-import okhttp3.MediaType;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.RequestBody;
-import okhttp3.Response;
-import okio.BufferedSink;
-import okio.GzipSink;
-import okio.Okio;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.Startable;
-import org.sonar.api.config.Configuration;
-import org.sonar.api.server.ServerSide;
-
-import static org.sonar.process.ProcessProperties.Property.SONAR_TELEMETRY_COMPRESSION;
-import static org.sonar.process.ProcessProperties.Property.SONAR_TELEMETRY_URL;
-import static org.sonar.process.ProcessProperties.Property.SONAR_TELEMETRY_METRICS_URL;
-
-@ServerSide
-public class TelemetryClient implements Startable {
- private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
- private static final Logger LOG = LoggerFactory.getLogger(TelemetryClient.class);
-
- private final OkHttpClient okHttpClient;
- private final Configuration config;
- private String serverUrl;
- private String metricsServerUrl;
- private boolean compression;
-
- public TelemetryClient(OkHttpClient okHttpClient, Configuration config) {
- this.config = config;
- this.okHttpClient = okHttpClient;
- }
-
- void upload(String json) throws IOException {
- Request request = buildHttpRequest(serverUrl, json);
- execute(okHttpClient.newCall(request));
- }
-
- void uploadMetric(String json) throws IOException {
- Request request = buildHttpRequest(metricsServerUrl, json);
- execute(okHttpClient.newCall(request));
- }
-
- void optOut(String json) {
- Request.Builder request = new Request.Builder();
- request.url(serverUrl);
- RequestBody body = RequestBody.create(JSON, json);
- request.delete(body);
- try {
- execute(okHttpClient.newCall(request.build()));
- } catch (IOException e) {
- LOG.debug("Error when sending opt-out usage statistics: {}", e.getMessage());
- }
- }
-
- private Request buildHttpRequest(String serverUrl, String json) {
- Request.Builder request = new Request.Builder();
- request.addHeader("Content-Encoding", "gzip");
- request.addHeader("Content-Type", "application/json");
- request.url(serverUrl);
- RequestBody body = RequestBody.create(JSON, json);
- if (compression) {
- request.post(gzip(body));
- } else {
- request.post(body);
- }
- return request.build();
- }
-
- private static RequestBody gzip(final RequestBody body) {
- return new RequestBody() {
- @Override
- public MediaType contentType() {
- return body.contentType();
- }
-
- @Override
- public long contentLength() {
- // We don't know the compressed length in advance!
- return -1;
- }
-
- @Override
- public void writeTo(BufferedSink sink) throws IOException {
- BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
- body.writeTo(gzipSink);
- gzipSink.close();
- }
- };
- }
-
- private static void execute(Call call) throws IOException {
- try (Response ignored = call.execute()) {
- // auto close connection to avoid leaked connection
- }
- }
-
- @Override
- public void start() {
- this.serverUrl = config.get(SONAR_TELEMETRY_URL.getKey())
- .orElseThrow(() -> new IllegalStateException(String.format("Setting '%s' must be provided.", SONAR_TELEMETRY_URL)));
- this.metricsServerUrl = config.get(SONAR_TELEMETRY_METRICS_URL.getKey())
- .orElseThrow(() -> new IllegalStateException(String.format("Setting '%s' must be provided.", SONAR_TELEMETRY_METRICS_URL)));
- this.compression = config.getBoolean(SONAR_TELEMETRY_COMPRESSION.getKey()).orElse(true);
- }
-
- @Override
- public void stop() {
- // Nothing to do
- }
-}
diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDaemon.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDaemon.java
index 4f2c42689a0..821b0bbede8 100644
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDaemon.java
+++ b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/TelemetryDaemon.java
@@ -38,12 +38,13 @@ import org.sonar.db.DbSession;
import org.sonar.server.property.InternalProperties;
import org.sonar.server.util.AbstractStoppableScheduledExecutorServiceImpl;
import org.sonar.server.util.GlobalLockManager;
+import org.sonar.telemetry.core.TelemetryClient;
import org.sonar.telemetry.legacy.TelemetryData;
import org.sonar.telemetry.legacy.TelemetryDataJsonWriter;
import org.sonar.telemetry.legacy.TelemetryDataLoader;
import org.sonar.telemetry.metrics.TelemetryMetricsLoader;
-import org.sonar.telemetry.metrics.schema.BaseMessage;
-import org.sonar.telemetry.metrics.util.MessageSerializer;
+import org.sonar.telemetry.core.schema.BaseMessage;
+import org.sonar.telemetry.core.MessageSerializer;
import static org.sonar.process.ProcessProperties.Property.SONAR_TELEMETRY_ENABLE;
import static org.sonar.process.ProcessProperties.Property.SONAR_TELEMETRY_FREQUENCY_IN_SECONDS;
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 aeb5f3c3074..7909baaaa98 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
@@ -35,8 +35,8 @@ import org.sonar.db.DbSession;
import org.sonar.db.telemetry.TelemetryMetricsSentDto;
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.core.schema.BaseMessage;
+import org.sonar.telemetry.core.schema.Metric;
import org.sonar.telemetry.metrics.util.SentMetricsStorage;
public class TelemetryMetricsLoader {
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 d282608d9c2..b005743172c 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
@@ -25,11 +25,11 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.sonar.telemetry.core.Granularity;
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;
-import org.sonar.telemetry.metrics.schema.ProjectMetric;
-import org.sonar.telemetry.metrics.schema.UserMetric;
+import org.sonar.telemetry.core.schema.InstallationMetric;
+import org.sonar.telemetry.core.schema.LanguageMetric;
+import org.sonar.telemetry.core.schema.Metric;
+import org.sonar.telemetry.core.schema.ProjectMetric;
+import org.sonar.telemetry.core.schema.UserMetric;
public class TelemetryMetricsMapper {
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
deleted file mode 100644
index 451480a8a90..00000000000
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/BaseMessage.java
+++ /dev/null
@@ -1,98 +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.metrics.schema;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.util.Objects;
-import java.util.Set;
-import org.sonar.telemetry.core.Dimension;
-
-public class BaseMessage {
- @JsonProperty("message_uuid")
- private String messageUuid;
-
- @JsonProperty("installation_id")
- private String installationId;
-
- @JsonProperty("dimension")
- private Dimension dimension;
-
- @JsonProperty("metric_values")
- private Set<Metric> metrics;
-
- protected BaseMessage(String messageUuid, String installationId, Dimension dimension, Set<Metric> metrics) {
- this.messageUuid = messageUuid;
- this.installationId = installationId;
- this.dimension = dimension;
- this.metrics = metrics;
- }
-
- public String getMessageUuid() {
- return messageUuid;
- }
-
- public String getInstallationId() {
- return installationId;
- }
-
- public Dimension getDimension() {
- return dimension;
- }
-
- public Set<Metric> getMetrics() {
- return metrics;
- }
-
- public static class Builder {
- private String messageUuid;
- private String installationId;
- private Dimension dimension;
- private Set<Metric> metrics;
-
- public Builder setMessageUuid(String messageUuid) {
- this.messageUuid = messageUuid;
- return this;
- }
-
- public Builder setInstallationId(String installationId) {
- this.installationId = installationId;
- return this;
- }
-
- public Builder setDimension(Dimension dimension) {
- this.dimension = dimension;
- return this;
- }
-
- public Builder setMetrics(Set<Metric> metrics) {
- this.metrics = metrics;
- return this;
- }
-
- public BaseMessage build() {
- Objects.requireNonNull(messageUuid, "messageUuid must be specified");
- Objects.requireNonNull(installationId, "installationId must be specified");
- Objects.requireNonNull(dimension, "dimension must be specified");
- Objects.requireNonNull(metrics, "metrics must be specified");
-
- return new BaseMessage(messageUuid, installationId, dimension, metrics);
- }
- }
-}
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
deleted file mode 100644
index 68dc2e83590..00000000000
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/InstallationMetric.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.metrics.schema;
-
-import javax.annotation.Nullable;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-public class InstallationMetric extends Metric {
-
- public InstallationMetric(String key, @Nullable Object value, TelemetryDataType type, Granularity granularity) {
- this.key = key;
- this.value = value;
- this.type = type;
- this.granularity = granularity;
- }
-
-}
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
deleted file mode 100644
index 236c31d7d38..00000000000
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/LanguageMetric.java
+++ /dev/null
@@ -1,46 +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.metrics.schema;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-public class LanguageMetric extends Metric {
-
- @JsonProperty("language")
- private String language;
-
- public LanguageMetric(String key, Object value, String language, TelemetryDataType type, Granularity granularity) {
- this.key = key;
- this.value = value;
- this.language = language;
- this.type = type;
- this.granularity = granularity;
- }
-
- public String getLanguage() {
- return language;
- }
-
- public void setLanguage(String language) {
- this.language = language;
- }
-}
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
deleted file mode 100644
index ad5c17f5194..00000000000
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/Metric.java
+++ /dev/null
@@ -1,70 +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.metrics.schema;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-public abstract class Metric {
- @JsonProperty("key")
- protected String key;
-
- @JsonProperty("value")
- protected Object value;
-
- @JsonProperty("type")
- protected TelemetryDataType type;
-
- @JsonProperty("granularity")
- protected Granularity granularity;
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public Object getValue() {
- return value;
- }
-
- public void setValue(Object value) {
- this.value = value;
- }
-
- public TelemetryDataType getType() {
- return type;
- }
-
- public void setType(TelemetryDataType type) {
- this.type = type;
- }
-
- public Granularity getGranularity() {
- return granularity;
- }
-
- public void setGranularity(Granularity granularity) {
- this.granularity = granularity;
- }
-}
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
deleted file mode 100644
index fc9ff8e4cd4..00000000000
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/ProjectMetric.java
+++ /dev/null
@@ -1,47 +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.metrics.schema;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-public class ProjectMetric extends Metric {
-
- @JsonProperty("project_uuid")
- private String projectUuid;
-
- public ProjectMetric(String key, Object value, String projectUuid, TelemetryDataType type, Granularity granularity) {
- this.key = key;
- this.value = value;
- this.projectUuid = projectUuid;
- this.type = type;
- this.granularity = granularity;
- }
-
- public String getProjectUuid() {
- return projectUuid;
- }
-
- public void setProjectUuid(String projectUuid) {
- this.projectUuid = projectUuid;
- }
-
-}
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
deleted file mode 100644
index 2af08ca023e..00000000000
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/UserMetric.java
+++ /dev/null
@@ -1,47 +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.metrics.schema;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-public class UserMetric extends Metric {
-
- @JsonProperty("user_uuid")
- private String userUuid;
-
- public UserMetric(String key, Object value, String userUuid, TelemetryDataType type, Granularity granularity) {
- this.key = key;
- this.value = value;
- this.userUuid = userUuid;
- this.type = type;
- this.granularity = granularity;
- }
-
- public String getUserUuid() {
- return userUuid;
- }
-
- public void setUserUuid(String userUuid) {
- this.userUuid = userUuid;
- }
-
-}
diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/package-info.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/package-info.java
deleted file mode 100644
index d1b9bb184e6..00000000000
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/schema/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.metrics.schema;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/util/MessageSerializer.java b/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/util/MessageSerializer.java
deleted file mode 100644
index a55c771552c..00000000000
--- a/server/sonar-telemetry/src/main/java/org/sonar/telemetry/metrics/util/MessageSerializer.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.metrics.util;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
-import java.io.UncheckedIOException;
-import org.sonar.telemetry.metrics.schema.BaseMessage;
-
-public class MessageSerializer {
-
- private MessageSerializer() {
- throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
- }
-
- public static String serialize(BaseMessage message) {
- ObjectMapper mapper = new ObjectMapper();
- try {
- return mapper.writeValueAsString(message);
- } catch (IOException ioException) {
- throw new UncheckedIOException(ioException);
- }
- }
-
-}
diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryClientCompressionTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryClientCompressionTest.java
index 6ac5d708553..6297d2e8cea 100644
--- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryClientCompressionTest.java
+++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryClientCompressionTest.java
@@ -31,6 +31,7 @@ import okio.Okio;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.sonar.api.config.internal.MapSettings;
+import org.sonar.telemetry.core.TelemetryClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.process.ProcessProperties.Property.SONAR_TELEMETRY_METRICS_URL;
diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryClientTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryClientTest.java
deleted file mode 100644
index ffb94d77fac..00000000000
--- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryClientTest.java
+++ /dev/null
@@ -1,109 +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.io.IOException;
-import okhttp3.MediaType;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okio.Buffer;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.ArgumentCaptor;
-import org.sonar.api.config.internal.MapSettings;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.sonar.process.ProcessProperties.Property.SONAR_TELEMETRY_COMPRESSION;
-import static org.sonar.process.ProcessProperties.Property.SONAR_TELEMETRY_METRICS_URL;
-import static org.sonar.process.ProcessProperties.Property.SONAR_TELEMETRY_URL;
-
-class TelemetryClientTest {
-
- private static final String JSON = "{\"key\":\"value\"}";
- private static final String TELEMETRY_URL = "https://telemetry.com/url";
- private static final String METRICS_TELEMETRY_URL = "https://telemetry.com/url/metrics";
-
- private final OkHttpClient okHttpClient = mock(OkHttpClient.class, RETURNS_DEEP_STUBS);
- private final MapSettings settings = new MapSettings();
-
- private final TelemetryClient underTest = new TelemetryClient(okHttpClient, settings.asConfig());
-
- @BeforeEach
- void setProperties() {
- settings.setProperty(SONAR_TELEMETRY_URL.getKey(), TELEMETRY_URL);
- settings.setProperty(SONAR_TELEMETRY_METRICS_URL.getKey(), METRICS_TELEMETRY_URL);
- }
-
- @Test
- void upload() throws IOException {
- ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
- settings.setProperty(SONAR_TELEMETRY_COMPRESSION.getKey(), false);
- underTest.start();
-
- underTest.upload(JSON);
-
- verify(okHttpClient).newCall(requestCaptor.capture());
- Request request = requestCaptor.getValue();
- assertThat(request.method()).isEqualTo("POST");
- assertThat(request.body().contentType()).isEqualTo(MediaType.parse("application/json; charset=utf-8"));
- Buffer body = new Buffer();
- request.body().writeTo(body);
- assertThat(body.readUtf8()).isEqualTo(JSON);
- assertThat(request.url()).hasToString(TELEMETRY_URL);
- }
-
- @Test
- void uploadMetric() throws IOException {
- ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
- settings.setProperty(SONAR_TELEMETRY_COMPRESSION.getKey(), false);
- underTest.start();
-
- underTest.uploadMetric(JSON);
-
- verify(okHttpClient).newCall(requestCaptor.capture());
- Request request = requestCaptor.getValue();
- assertThat(request.method()).isEqualTo("POST");
- assertThat(request.body().contentType()).isEqualTo(MediaType.parse("application/json; charset=utf-8"));
- Buffer body = new Buffer();
- request.body().writeTo(body);
- assertThat(body.readUtf8()).isEqualTo(JSON);
- assertThat(request.url()).hasToString(METRICS_TELEMETRY_URL);
- }
-
- @Test
- void opt_out() throws IOException {
- ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
- underTest.start();
-
- underTest.optOut(JSON);
-
- verify(okHttpClient).newCall(requestCaptor.capture());
- Request request = requestCaptor.getValue();
- assertThat(request.method()).isEqualTo("DELETE");
- assertThat(request.body().contentType()).isEqualTo(MediaType.parse("application/json; charset=utf-8"));
- Buffer body = new Buffer();
- request.body().writeTo(body);
- assertThat(body.readUtf8()).isEqualTo(JSON);
- assertThat(request.url()).hasToString(TELEMETRY_URL);
- }
-}
diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryDaemonTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryDaemonTest.java
index bcee58e5c6f..0ae19fc5b24 100644
--- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryDaemonTest.java
+++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryDaemonTest.java
@@ -35,6 +35,7 @@ import org.sonar.server.property.InternalProperties;
import org.sonar.server.property.MapInternalProperties;
import org.sonar.server.util.GlobalLockManager;
import org.sonar.server.util.GlobalLockManagerImpl;
+import org.sonar.telemetry.core.TelemetryClient;
import org.sonar.telemetry.legacy.TelemetryData;
import org.sonar.telemetry.legacy.TelemetryDataJsonWriter;
import org.sonar.telemetry.legacy.TelemetryDataLoader;
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 d822623d167..d311a0e88a7 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
@@ -28,11 +28,11 @@ 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;
-import org.sonar.telemetry.metrics.schema.ProjectMetric;
-import org.sonar.telemetry.metrics.schema.UserMetric;
+import org.sonar.telemetry.core.schema.InstallationMetric;
+import org.sonar.telemetry.core.schema.LanguageMetric;
+import org.sonar.telemetry.core.schema.Metric;
+import org.sonar.telemetry.core.schema.ProjectMetric;
+import org.sonar.telemetry.core.schema.UserMetric;
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/BaseMessageTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/BaseMessageTest.java
deleted file mode 100644
index e702018f37e..00000000000
--- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/BaseMessageTest.java
+++ /dev/null
@@ -1,105 +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.metrics.schema;
-
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
-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.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;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-class BaseMessageTest {
-
- @Test
- void build() {
- BaseMessage message = new BaseMessage.Builder()
- .setMessageUuid("123e4567-e89b-12d3-a456-426614174000")
- .setInstallationId("installation-id")
- .setDimension(Dimension.INSTALLATION)
- .setMetrics(installationMetrics())
- .build();
-
- assertThat(message.getMessageUuid()).isEqualTo("123e4567-e89b-12d3-a456-426614174000");
- assertThat(message.getInstallationId()).isEqualTo("installation-id");
- assertThat(message.getDimension()).isEqualTo(Dimension.INSTALLATION);
- Set<InstallationMetric> installationMetrics = (Set<InstallationMetric>) (Set<?>) message.getMetrics();
- assertThat(installationMetrics)
- .extracting(InstallationMetric::getKey, InstallationMetric::getGranularity, InstallationMetric::getType, InstallationMetric::getValue)
- .containsExactlyInAnyOrder(
- tuple("key-0", Granularity.DAILY, TelemetryDataType.INTEGER, 0),
- tuple("key-1", Granularity.DAILY, TelemetryDataType.INTEGER, 1),
- tuple("key-2", Granularity.DAILY, TelemetryDataType.INTEGER, 2)
- );
- }
-
- @ParameterizedTest
- @MethodSource("invalidBaseMessageProvider")
- void build_invalidCases(BaseMessage.Builder builder, String expectedErrorMessage) {
- Exception exception = assertThrows(NullPointerException.class, builder::build);
- assertEquals(expectedErrorMessage, exception.getMessage());
- }
-
- private static Stream<Arguments> invalidBaseMessageProvider() {
- return Stream.of(
- Arguments.of(
- new BaseMessage.Builder()
- .setInstallationId("installation-id")
- .setDimension(Dimension.INSTALLATION)
- .setMetrics(installationMetrics()),
- "messageUuid must be specified"
- ),
- Arguments.of(
- new BaseMessage.Builder()
- .setMessageUuid("some-uuid")
- .setInstallationId("installation-id")
- .setMetrics(installationMetrics()),
- "dimension must be specified"
- ),
- Arguments.of(
- new BaseMessage.Builder()
- .setMessageUuid("some-uuid")
- .setDimension(Dimension.INSTALLATION)
- .setMetrics(installationMetrics()),
- "installationId must be specified"
- )
- );
- }
-
- private static Set<Metric> installationMetrics() {
- return IntStream.range(0, 3)
- .mapToObj(i -> new InstallationMetric(
- "key-" + i,
- i,
- TelemetryDataType.INTEGER,
- Granularity.DAILY
- )).collect(Collectors.toSet());
- }
-}
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
deleted file mode 100644
index b3ecd01b7a0..00000000000
--- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/InstallationMetricTest.java
+++ /dev/null
@@ -1,60 +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.metrics.schema;
-
-import org.junit.jupiter.api.Test;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-class InstallationMetricTest {
-
- @Test
- void constructor() {
- InstallationMetric metric = new InstallationMetric(
- "installation-key-1",
- "value",
- TelemetryDataType.STRING,
- Granularity.WEEKLY
- );
-
- assertThat(metric.getValue()).isEqualTo("value");
- assertThat(metric.getKey()).isEqualTo("installation-key-1");
- assertThat(metric.getGranularity()).isEqualTo(Granularity.WEEKLY);
- assertThat(metric.getType()).isEqualTo(TelemetryDataType.STRING);
- }
-
- @Test
- void constructor_shouldAcceptNullValue() {
- InstallationMetric metric = new InstallationMetric(
- "installation-key-1",
- null,
- TelemetryDataType.STRING,
- Granularity.WEEKLY
- );
-
- assertThat(metric.getValue()).isNull();
- assertThat(metric.getKey()).isEqualTo("installation-key-1");
- assertThat(metric.getGranularity()).isEqualTo(Granularity.WEEKLY);
- assertThat(metric.getType()).isEqualTo(TelemetryDataType.STRING);
- }
-
-}
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
deleted file mode 100644
index 832ec3d8f03..00000000000
--- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/LanguageMetricTest.java
+++ /dev/null
@@ -1,41 +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.metrics.schema;
-
-import org.junit.jupiter.api.Test;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-class LanguageMetricTest {
-
- @Test
- void gettersAndSetters() {
- LanguageMetric metric = new LanguageMetric("ncloc", 100, "java", TelemetryDataType.INTEGER, Granularity.MONTHLY);
-
- assertThat(metric.getLanguage()).isEqualTo("java");
- assertThat(metric.getValue()).isEqualTo(100);
- assertThat(metric.getKey()).isEqualTo("ncloc");
- assertThat(metric.getGranularity()).isEqualTo(Granularity.MONTHLY);
- assertThat(metric.getType()).isEqualTo(TelemetryDataType.INTEGER);
- }
-
-}
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
deleted file mode 100644
index 7eb23fcfcf1..00000000000
--- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/ProjectMetricTest.java
+++ /dev/null
@@ -1,47 +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.metrics.schema;
-
-import org.junit.jupiter.api.Test;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-class ProjectMetricTest {
-
- @Test
- void gettersAndSetters() {
- ProjectMetric metric = new ProjectMetric(
- "project-key-1",
- 1.0998,
- "project-uuid",
- TelemetryDataType.FLOAT,
- Granularity.DAILY
- );
-
- assertThat(metric.getValue()).isEqualTo(1.0998);
- assertThat(metric.getKey()).isEqualTo("project-key-1");
- assertThat(metric.getGranularity()).isEqualTo(Granularity.DAILY);
- assertThat(metric.getType()).isEqualTo(TelemetryDataType.FLOAT);
- assertThat(metric.getProjectUuid()).isEqualTo("project-uuid");
- }
-
-}
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
deleted file mode 100644
index 04466d0909f..00000000000
--- a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/metrics/schema/UserMetricTest.java
+++ /dev/null
@@ -1,47 +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.metrics.schema;
-
-import org.junit.jupiter.api.Test;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataType;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-class UserMetricTest {
-
- @Test
- void gettersAndSetters() {
- UserMetric metric = new UserMetric(
- "user-key-1",
- true,
- "user-uuid",
- TelemetryDataType.BOOLEAN,
- Granularity.DAILY
- );
-
- assertThat(metric.getValue()).isEqualTo(true);
- assertThat(metric.getKey()).isEqualTo("user-key-1");
- assertThat(metric.getGranularity()).isEqualTo(Granularity.DAILY);
- assertThat(metric.getType()).isEqualTo(TelemetryDataType.BOOLEAN);
- assertThat(metric.getUserUuid()).isEqualTo("user-uuid");
- }
-
-}
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 57aa2e858e0..b3563e54368 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
@@ -27,13 +27,14 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.sonar.telemetry.core.Dimension;
import org.sonar.telemetry.core.Granularity;
+import org.sonar.telemetry.core.MessageSerializer;
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;
-import org.sonar.telemetry.metrics.schema.Metric;
-import org.sonar.telemetry.metrics.schema.ProjectMetric;
-import org.sonar.telemetry.metrics.schema.UserMetric;
+import org.sonar.telemetry.core.schema.BaseMessage;
+import org.sonar.telemetry.core.schema.InstallationMetric;
+import org.sonar.telemetry.core.schema.LanguageMetric;
+import org.sonar.telemetry.core.schema.Metric;
+import org.sonar.telemetry.core.schema.ProjectMetric;
+import org.sonar.telemetry.core.schema.UserMetric;
import static org.sonar.test.JsonAssert.assertJson;