diff options
author | Damien Urruty <damien.urruty@sonarsource.com> | 2024-10-14 12:07:33 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-10-15 20:03:07 +0000 |
commit | 86a67f6f7084e06119ce81765002a738d3d54757 (patch) | |
tree | 4f1756f058268934bf4bc9d5f70dd75581249a4c /server/sonar-telemetry-core/src | |
parent | 33d6dff86f9fc395b82d06e1e031e1f5a889dc5f (diff) | |
download | sonarqube-86a67f6f7084e06119ce81765002a738d3d54757.tar.gz sonarqube-86a67f6f7084e06119ce81765002a738d3d54757.zip |
NO-JIRA Refactor v2 telemetry data provider
Introduce an abstract class to differentiate static characteristics (dimension, metric key, ...) and dynamic (the actual value) to better show how it is supposed to be used. It will also prevent future duplication reports on data providers
Diffstat (limited to 'server/sonar-telemetry-core/src')
-rw-r--r-- | server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/AbstractTelemetryDataProvider.java (renamed from server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/DailyInstallationMetricProvider.java) | 33 | ||||
-rw-r--r-- | server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/TelemetryDataProvider.java | 4 | ||||
-rw-r--r-- | server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/AbstractTelemetryDataProviderTest.java (renamed from server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/package-info.java) | 25 |
3 files changed, 47 insertions, 15 deletions
diff --git a/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/DailyInstallationMetricProvider.java b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/AbstractTelemetryDataProvider.java index 79917f7166d..23667fd7dd1 100644 --- a/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/DailyInstallationMetricProvider.java +++ b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/AbstractTelemetryDataProvider.java @@ -17,25 +17,38 @@ * 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.common; +package org.sonar.telemetry.core; -import org.sonar.telemetry.core.Dimension; -import org.sonar.telemetry.core.Granularity; -import org.sonar.telemetry.core.TelemetryDataProvider; +public abstract class AbstractTelemetryDataProvider<T> implements TelemetryDataProvider<T> { + private final String metricKey; + private final Dimension dimension; + private final Granularity granularity; + private final TelemetryDataType type; -/** - * This class is used to provide daily installation metrics to the telemetry system. - */ -public abstract class DailyInstallationMetricProvider<T> implements TelemetryDataProvider<T> { + protected AbstractTelemetryDataProvider(String metricKey, Dimension dimension, Granularity granularity, TelemetryDataType type) { + this.metricKey = metricKey; + this.dimension = dimension; + this.granularity = granularity; + this.type = type; + } + + @Override + public String getMetricKey() { + return metricKey; + } @Override public Dimension getDimension() { - return Dimension.INSTALLATION; + return dimension; } @Override public Granularity getGranularity() { - return Granularity.DAILY; + return granularity; } + @Override + public TelemetryDataType getType() { + return type; + } } 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 index 8829701c4b1..679f2a8376a 100644 --- 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 @@ -25,8 +25,8 @@ import java.util.Optional; /** * 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. + * If you want to add a new metric to the telemetry system, you need to create a new implementation of this interface, or for convenience to subclass {@link AbstractTelemetryDataProvider} (recommended), + * and register it in the Spring context as a bean. * * @param <T> type of the value provided by this instance. Should be either {@link Boolean}, {@link String}, * {@link Integer} or {@link Float}. diff --git a/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/package-info.java b/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/AbstractTelemetryDataProviderTest.java index f1c0831d131..95e828c310c 100644 --- a/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/package-info.java +++ b/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/AbstractTelemetryDataProviderTest.java @@ -17,7 +17,26 @@ * 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.common; +package org.sonar.telemetry.core; -import javax.annotation.ParametersAreNonnullByDefault; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class AbstractTelemetryDataProviderTest { + + AbstractTelemetryDataProvider<Boolean> customProvider = new AbstractTelemetryDataProvider<>("key", Dimension.INSTALLATION, Granularity.ADHOC, TelemetryDataType.BOOLEAN) { + }; + + + @Test + void it_should_provide_configured_properties() { + assertThat(customProvider.getDimension()).isEqualTo(Dimension.INSTALLATION); + assertThat(customProvider.getMetricKey()).isEqualTo("key"); + assertThat(customProvider.getGranularity()).isEqualTo(Granularity.ADHOC); + assertThat(customProvider.getType()).isEqualTo(TelemetryDataType.BOOLEAN); + assertThat(customProvider.getValue()).isEmpty(); + assertThat(customProvider.getValues()).isEmpty(); + } + +} |