From 86a67f6f7084e06119ce81765002a738d3d54757 Mon Sep 17 00:00:00 2001 From: Damien Urruty Date: Mon, 14 Oct 2024 12:07:33 +0200 Subject: [PATCH] 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 --- ...emetryDbMigrationStepDurationProvider.java | 24 +++----------- .../TelemetryDbMigrationStepsProvider.java | 24 +++----------- .../TelemetryDbMigrationSuccessProvider.java | 24 +++----------- ...TelemetryDbMigrationTotalTimeProvider.java | 24 +++----------- ...mailConfigAuthMethodTelemetryProvider.java | 25 ++------------ .../EmailConfigHostTelemetryProvider.java | 25 ++------------ ...ava => AbstractTelemetryDataProvider.java} | 33 +++++++++++++------ .../telemetry/core/TelemetryDataProvider.java | 4 +-- .../AbstractTelemetryDataProviderTest.java} | 25 ++++++++++++-- ...ProjectCppAutoconfigTelemetryProvider.java | 25 ++------------ .../TelemetryFipsEnabledProvider.java | 16 ++++----- .../telemetry/TelemetryNclocProvider.java | 25 ++------------ ...etryPortfolioConfidentialFlagProvider.java | 29 ++-------------- .../TelemetryUserEnabledProvider.java | 25 ++------------ .../telemetry/TelemetryVersionProvider.java | 17 +++------- 15 files changed, 92 insertions(+), 253 deletions(-) rename server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/{common/DailyInstallationMetricProvider.java => AbstractTelemetryDataProvider.java} (56%) rename server/sonar-telemetry-core/src/{main/java/org/sonar/telemetry/core/common/package-info.java => test/java/org/sonar/telemetry/core/AbstractTelemetryDataProviderTest.java} (50%) diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProvider.java b/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProvider.java index 06ac499de9c..890bf784669 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProvider.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProvider.java @@ -21,33 +21,17 @@ package org.sonar.server.telemetry; import java.util.HashMap; import java.util.Map; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; 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 TelemetryDbMigrationStepDurationProvider implements TelemetryDataProvider { +public class TelemetryDbMigrationStepDurationProvider extends AbstractTelemetryDataProvider { private final Map dbMigrationStepDurations = new HashMap<>(); - @Override - public String getMetricKey() { - return "db_migration_step_duration"; - } - - @Override - public Dimension getDimension() { - return Dimension.INSTALLATION; - } - - @Override - public Granularity getGranularity() { - return Granularity.ADHOC; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.INTEGER; + public TelemetryDbMigrationStepDurationProvider() { + super("db_migration_step_duration", Dimension.INSTALLATION, Granularity.ADHOC, TelemetryDataType.INTEGER); } @Override diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepsProvider.java b/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepsProvider.java index ea400c355ec..bfa86b9c731 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepsProvider.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepsProvider.java @@ -20,33 +20,17 @@ package org.sonar.server.telemetry; import java.util.Optional; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; 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 TelemetryDbMigrationStepsProvider implements TelemetryDataProvider { +public class TelemetryDbMigrationStepsProvider extends AbstractTelemetryDataProvider { private Integer dbMigrationCompletedSteps = null; - @Override - public String getMetricKey() { - return "db_migration_completed_steps"; - } - - @Override - public Granularity getGranularity() { - return Granularity.ADHOC; - } - - @Override - public Dimension getDimension() { - return Dimension.INSTALLATION; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.INTEGER; + public TelemetryDbMigrationStepsProvider() { + super("db_migration_completed_steps", Dimension.INSTALLATION, Granularity.ADHOC, TelemetryDataType.INTEGER); } public void setDbMigrationCompletedSteps(Integer dbMigrationCompletedSteps) { diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationSuccessProvider.java b/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationSuccessProvider.java index b50d241f8a5..54adc5d1fe9 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationSuccessProvider.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationSuccessProvider.java @@ -20,33 +20,17 @@ package org.sonar.server.telemetry; import java.util.Optional; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; 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 TelemetryDbMigrationSuccessProvider implements TelemetryDataProvider { +public class TelemetryDbMigrationSuccessProvider extends AbstractTelemetryDataProvider { private Boolean dbMigrationSuccess = null; - @Override - public String getMetricKey() { - return "db_migration_success"; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.BOOLEAN; - } - - @Override - public Granularity getGranularity() { - return Granularity.ADHOC; - } - - @Override - public Dimension getDimension() { - return Dimension.INSTALLATION; + public TelemetryDbMigrationSuccessProvider() { + super("db_migration_success", Dimension.INSTALLATION, Granularity.ADHOC, TelemetryDataType.BOOLEAN); } public void setDbMigrationSuccess(Boolean dbMigrationSuccess) { diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationTotalTimeProvider.java b/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationTotalTimeProvider.java index 7fe57f03934..bb3b8419710 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationTotalTimeProvider.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationTotalTimeProvider.java @@ -20,33 +20,17 @@ package org.sonar.server.telemetry; import java.util.Optional; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; 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 TelemetryDbMigrationTotalTimeProvider implements TelemetryDataProvider { +public class TelemetryDbMigrationTotalTimeProvider extends AbstractTelemetryDataProvider { private Long dbMigrationTotalTime = null; - @Override - public String getMetricKey() { - return "db_migration_total_time_ms"; - } - - @Override - public Granularity getGranularity() { - return Granularity.ADHOC; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.INTEGER; - } - - @Override - public Dimension getDimension() { - return Dimension.INSTALLATION; + public TelemetryDbMigrationTotalTimeProvider() { + super("db_migration_total_time_ms", Dimension.INSTALLATION, Granularity.ADHOC, TelemetryDataType.INTEGER); } public void setDbMigrationTotalTime(Long dbMigrationTotalTime) { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java index 4ed588eb9b5..38f3dc73e39 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java @@ -22,40 +22,21 @@ package org.sonar.server.notification.email.telemetry; import java.util.Optional; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; 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 org.sonar.server.email.EmailSmtpConfiguration.EMAIL_CONFIG_SMTP_AUTH_METHOD; -public class EmailConfigAuthMethodTelemetryProvider implements TelemetryDataProvider { +public class EmailConfigAuthMethodTelemetryProvider extends AbstractTelemetryDataProvider { private final DbClient dbClient; public EmailConfigAuthMethodTelemetryProvider(DbClient dbClient) { + super("email_conf_auth_method", Dimension.INSTALLATION, Granularity.WEEKLY, TelemetryDataType.STRING); this.dbClient = dbClient; } - @Override - public String getMetricKey() { - return "email_conf_auth_method"; - } - - @Override - public Dimension getDimension() { - return Dimension.INSTALLATION; - } - - @Override - public Granularity getGranularity() { - return Granularity.WEEKLY; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.STRING; - } - @Override public Optional getValue() { try (DbSession dbSession = dbClient.openSession(false)) { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java index e2fe55be6af..ed3a3c9ad76 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java @@ -24,40 +24,21 @@ import java.util.Optional; import org.apache.commons.lang3.StringUtils; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; 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 org.sonar.server.email.EmailSmtpConfiguration.EMAIL_CONFIG_SMTP_HOST; -public class EmailConfigHostTelemetryProvider implements TelemetryDataProvider { +public class EmailConfigHostTelemetryProvider extends AbstractTelemetryDataProvider { private final DbClient dbClient; public EmailConfigHostTelemetryProvider(DbClient dbClient) { + super("email_conf_host", Dimension.INSTALLATION, Granularity.WEEKLY, TelemetryDataType.STRING); this.dbClient = dbClient; } - @Override - public String getMetricKey() { - return "email_conf_host"; - } - - @Override - public Dimension getDimension() { - return Dimension.INSTALLATION; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.STRING; - } - - @Override - public Granularity getGranularity() { - return Granularity.WEEKLY; - } - @Override public Optional getValue() { try (DbSession dbSession = dbClient.openSession(false)) { 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 similarity index 56% rename from server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/DailyInstallationMetricProvider.java rename to 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 implements TelemetryDataProvider { + 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 implements TelemetryDataProvider { + 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 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 similarity index 50% rename from server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/package-info.java rename to 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 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(); + } + +} diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java index fb83847c57a..79c36f92dac 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java @@ -29,39 +29,20 @@ import org.sonar.db.DbSession; import org.sonar.db.measure.ProjectMainBranchMeasureDto; import org.sonar.db.property.PropertyDto; import org.sonar.db.property.PropertyQuery; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; 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 { +public class ProjectCppAutoconfigTelemetryProvider extends AbstractTelemetryDataProvider { private final DbClient dbClient; public ProjectCppAutoconfigTelemetryProvider(DbClient dbClient) { + super("project_cpp_config_type", Dimension.PROJECT, Granularity.WEEKLY, TelemetryDataType.STRING); 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 getValues() { Map cppConfigTypePerProjectUuid = new HashMap<>(); diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProvider.java index ceb4fd3f04e..31a3ace0ca6 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProvider.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProvider.java @@ -21,19 +21,15 @@ package org.sonar.server.platform.telemetry; import java.util.Optional; import org.sonar.core.fips.FipsDetector; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; import org.sonar.telemetry.core.TelemetryDataType; -import org.sonar.telemetry.core.common.DailyInstallationMetricProvider; -public class TelemetryFipsEnabledProvider extends DailyInstallationMetricProvider { +public class TelemetryFipsEnabledProvider extends AbstractTelemetryDataProvider { - @Override - public String getMetricKey() { - return "is_fips_enabled"; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.BOOLEAN; + public TelemetryFipsEnabledProvider() { + super("is_fips_enabled", Dimension.INSTALLATION, Granularity.DAILY, TelemetryDataType.BOOLEAN); } @Override 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 d06d2f18bb3..332312d85f3 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 @@ -26,13 +26,13 @@ import java.util.Map; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.measure.ProjectLocDistributionDto; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; 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.legacy.ProjectLocDistributionDataProvider; -public class TelemetryNclocProvider implements TelemetryDataProvider { +public class TelemetryNclocProvider extends AbstractTelemetryDataProvider { public static final String METRIC_KEY = "ncloc_per_language"; @@ -40,30 +40,11 @@ public class TelemetryNclocProvider implements TelemetryDataProvider { private final ProjectLocDistributionDataProvider projectLocDistributionDataProvider; public TelemetryNclocProvider(DbClient dbClient, ProjectLocDistributionDataProvider projectLocDistributionDataProvider) { + super(METRIC_KEY, Dimension.LANGUAGE, Granularity.DAILY, TelemetryDataType.INTEGER); this.dbClient = dbClient; this.projectLocDistributionDataProvider = projectLocDistributionDataProvider; } - @Override - public String getMetricKey() { - return METRIC_KEY; - } - - @Override - public Dimension getDimension() { - return Dimension.LANGUAGE; - } - - @Override - public Granularity getGranularity() { - return Granularity.DAILY; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.INTEGER; - } - @Override public Map getValues() { try (DbSession dbSession = dbClient.openSession(false)) { diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java index 14e9bcf8049..e0351ae7917 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java @@ -22,42 +22,19 @@ package org.sonar.server.platform.telemetry; import java.util.Optional; import org.sonar.db.DbClient; import org.sonar.db.property.PropertyDto; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; 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 org.sonar.telemetry.core.Dimension.INSTALLATION; -import static org.sonar.telemetry.core.Granularity.WEEKLY; -import static org.sonar.telemetry.core.TelemetryDataType.BOOLEAN; - -public class TelemetryPortfolioConfidentialFlagProvider implements TelemetryDataProvider { +public class TelemetryPortfolioConfidentialFlagProvider extends AbstractTelemetryDataProvider { private final DbClient dbClient; public TelemetryPortfolioConfidentialFlagProvider(DbClient dbClient) { + super("portfolio_reports_confidential_flag", Dimension.INSTALLATION, Granularity.WEEKLY, TelemetryDataType.BOOLEAN); this.dbClient = dbClient; } - @Override - public String getMetricKey() { - return "portfolio_reports_confidential_flag"; - } - - @Override - public Dimension getDimension() { - return INSTALLATION; - } - - @Override - public Granularity getGranularity() { - return WEEKLY; - } - - @Override - public TelemetryDataType getType() { - return BOOLEAN; - } - @Override public Optional getValue() { PropertyDto property = dbClient.propertiesDao().selectGlobalProperty("sonar.portfolios.confidential.header"); diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java index 878fda62ba5..965ebbb4999 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java @@ -27,39 +27,20 @@ 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.AbstractTelemetryDataProvider; 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 { +public class TelemetryUserEnabledProvider extends AbstractTelemetryDataProvider { private final DbClient dbClient; public TelemetryUserEnabledProvider(DbClient dbClient) { + super("user_enabled", Dimension.USER, Granularity.DAILY, TelemetryDataType.BOOLEAN); 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 getValues() { Map result = new HashMap<>(); 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 01041ce6f97..cc8a71d8f44 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 @@ -21,27 +21,20 @@ package org.sonar.server.platform.telemetry; import java.util.Optional; import org.sonar.api.platform.Server; +import org.sonar.telemetry.core.AbstractTelemetryDataProvider; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; import org.sonar.telemetry.core.TelemetryDataType; -import org.sonar.telemetry.core.common.DailyInstallationMetricProvider; -public class TelemetryVersionProvider extends DailyInstallationMetricProvider { +public class TelemetryVersionProvider extends AbstractTelemetryDataProvider { private final Server server; public TelemetryVersionProvider(Server server) { + super("version", Dimension.INSTALLATION, Granularity.DAILY, TelemetryDataType.STRING); this.server = server; } - @Override - public String getMetricKey() { - return "version"; - } - - @Override - public TelemetryDataType getType() { - return TelemetryDataType.STRING; - } - @Override public Optional getValue() { return Optional.ofNullable(server.getVersion()); -- 2.39.5