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 | |
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')
15 files changed, 92 insertions, 253 deletions
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<Long> { +public class TelemetryDbMigrationStepDurationProvider extends AbstractTelemetryDataProvider<Long> { private final Map<String, Long> 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<Integer> { +public class TelemetryDbMigrationStepsProvider extends AbstractTelemetryDataProvider<Integer> { 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<Boolean> { +public class TelemetryDbMigrationSuccessProvider extends AbstractTelemetryDataProvider<Boolean> { 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<Long> { +public class TelemetryDbMigrationTotalTimeProvider extends AbstractTelemetryDataProvider<Long> { 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,41 +22,22 @@ 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<String> { +public class EmailConfigAuthMethodTelemetryProvider extends AbstractTelemetryDataProvider<String> { 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<String> getValue() { try (DbSession dbSession = dbClient.openSession(false)) { return Optional.of(dbClient.internalPropertiesDao().selectByKey(dbSession, EMAIL_CONFIG_SMTP_AUTH_METHOD).orElse("NOT_SET")); 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,41 +24,22 @@ 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<String> { +public class EmailConfigHostTelemetryProvider extends AbstractTelemetryDataProvider<String> { 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<String> getValue() { try (DbSession dbSession = dbClient.openSession(false)) { return Optional.of(dbClient.internalPropertiesDao() 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(); + } + +} 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,40 +29,21 @@ 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<String> { +public class ProjectCppAutoconfigTelemetryProvider extends AbstractTelemetryDataProvider<String> { 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<String, String> getValues() { Map<String, String> cppConfigTypePerProjectUuid = new HashMap<>(); try (DbSession dbSession = dbClient.openSession(true)) { 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<Boolean> { +public class TelemetryFipsEnabledProvider extends AbstractTelemetryDataProvider<Boolean> { - @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<Long> { +public class TelemetryNclocProvider extends AbstractTelemetryDataProvider<Long> { public static final String METRIC_KEY = "ncloc_per_language"; @@ -40,31 +40,12 @@ public class TelemetryNclocProvider implements TelemetryDataProvider<Long> { 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<String, Long> getValues() { try (DbSession dbSession = dbClient.openSession(false)) { return getNclocDistribution(dbSession); 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,43 +22,20 @@ 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<Boolean> { +public class TelemetryPortfolioConfidentialFlagProvider extends AbstractTelemetryDataProvider<Boolean> { 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<Boolean> getValue() { PropertyDto property = dbClient.propertiesDao().selectGlobalProperty("sonar.portfolios.confidential.header"); return property == null ? Optional.of(true) : Optional.of(Boolean.valueOf(property.getValue())); 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,40 +27,21 @@ 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<Boolean> { +public class TelemetryUserEnabledProvider extends AbstractTelemetryDataProvider<Boolean> { 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<String, Boolean> getValues() { Map<String, Boolean> result = new HashMap<>(); int pageSize = 1000; 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,28 +21,21 @@ 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<String> { +public class TelemetryVersionProvider extends AbstractTelemetryDataProvider<String> { 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<String> getValue() { return Optional.ofNullable(server.getVersion()); } |