]> source.dussan.org Git - sonarqube.git/commitdiff
NO-JIRA Refactor v2 telemetry data provider master
authorDamien Urruty <damien.urruty@sonarsource.com>
Mon, 14 Oct 2024 10:07:33 +0000 (12:07 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 15 Oct 2024 20:03:07 +0000 (20:03 +0000)
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

17 files changed:
server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepDurationProvider.java
server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationStepsProvider.java
server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationSuccessProvider.java
server/sonar-db-migration/src/main/java/org/sonar/server/telemetry/TelemetryDbMigrationTotalTimeProvider.java
server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigAuthMethodTelemetryProvider.java
server/sonar-server-common/src/main/java/org/sonar/server/notification/email/telemetry/EmailConfigHostTelemetryProvider.java
server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/AbstractTelemetryDataProvider.java [new file with mode: 0644]
server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/TelemetryDataProvider.java
server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/DailyInstallationMetricProvider.java [deleted file]
server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/package-info.java [deleted file]
server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/AbstractTelemetryDataProviderTest.java [new file with mode: 0644]
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProvider.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java

index 06ac499de9c62b4db8db385d7656618a6469f96a..890bf784669d9fa50d198ecb2212b6eed1f0da99 100644 (file)
@@ -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
index ea400c355ec16dd332dfff8873dbbdf0d2886359..bfa86b9c731f9b8058756832d643c7281fa35b93 100644 (file)
 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) {
index b50d241f8a5ac43f8271818c3ed953f4b404eee4..54adc5d1fe9f5753ae1fee5c36d5e7a0192a4101 100644 (file)
 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) {
index 7fe57f039342494b230738eb6ba56eb300a97cc3..bb3b8419710b2fd9781f803b67c4221e5098177b 100644 (file)
 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) {
index 4ed588eb9b510a3864fe23c5ffd5500451f57e4d..38f3dc73e39b3f2074f8f4cde95341c189f7b73e 100644 (file)
@@ -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<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)) {
index e2fe55be6af03ea77d6948a31134ccd782c107d0..ed3a3c9ad76f575bf20b86f4e8ec5cef42b3958e 100644 (file)
@@ -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<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)) {
diff --git a/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/AbstractTelemetryDataProvider.java b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/AbstractTelemetryDataProvider.java
new file mode 100644 (file)
index 0000000..23667fd
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.telemetry.core;
+
+public abstract class AbstractTelemetryDataProvider<T> implements TelemetryDataProvider<T> {
+  private final String metricKey;
+  private final Dimension dimension;
+  private final Granularity granularity;
+  private final TelemetryDataType type;
+
+  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;
+  }
+
+  @Override
+  public Granularity getGranularity() {
+    return granularity;
+  }
+
+  @Override
+  public TelemetryDataType getType() {
+    return type;
+  }
+}
index 8829701c4b10b4bd81c69e7c98d3d0411b0e14be..679f2a8376ae97c50c624c3c486af9dd22164065 100644 (file)
@@ -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/DailyInstallationMetricProvider.java b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/DailyInstallationMetricProvider.java
deleted file mode 100644 (file)
index 79917f7..0000000
+++ /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.core.common;
-
-import org.sonar.telemetry.core.Dimension;
-import org.sonar.telemetry.core.Granularity;
-import org.sonar.telemetry.core.TelemetryDataProvider;
-
-/**
- * This class is used to provide daily installation metrics to the telemetry system.
- */
-public abstract class DailyInstallationMetricProvider<T> implements TelemetryDataProvider<T> {
-
-  @Override
-  public Dimension getDimension() {
-    return Dimension.INSTALLATION;
-  }
-
-  @Override
-  public Granularity getGranularity() {
-    return Granularity.DAILY;
-  }
-
-}
diff --git a/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/package-info.java b/server/sonar-telemetry-core/src/main/java/org/sonar/telemetry/core/common/package-info.java
deleted file mode 100644 (file)
index f1c0831..0000000
+++ /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.core.common;
-
-import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/AbstractTelemetryDataProviderTest.java b/server/sonar-telemetry-core/src/test/java/org/sonar/telemetry/core/AbstractTelemetryDataProviderTest.java
new file mode 100644 (file)
index 0000000..95e828c
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.telemetry.core;
+
+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();
+  }
+
+}
index fb83847c57aab4138f730e8ade352707b31559b9..79c36f92dac426aaf2918d953f397ee38e431542 100644 (file)
@@ -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<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<>();
index ceb4fd3f04e30f6b7973f8b83f310f1de24fb817..31a3ace0ca661af9a5a57d960ad2c64c34d76cac 100644 (file)
@@ -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
index d06d2f18bb3d7fdcb7a60d8dd6ae100d73248a6c..332312d85f33e37d48ce00ceb07ba0d7b49d3f46 100644 (file)
@@ -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,30 +40,11 @@ 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)) {
index 14e9bcf804945947f6f7d42a1eb0e599a774ec4a..e0351ae7917bae157b0a2e0ff4ce77b2619157c2 100644 (file)
@@ -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<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");
index 878fda62ba5065e4e7875b3b648b1b8634c81afa..965ebbb49997b24ed347de8f81c648365daa6692 100644 (file)
@@ -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<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<>();
index 01041ce6f979d2fd8b4e1e9c003dcb95c0b35d22..cc8a71d8f443850ff52bf51d986044705960b5c4 100644 (file)
@@ -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<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());