aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver
diff options
context:
space:
mode:
authorDamien Urruty <damien.urruty@sonarsource.com>2024-10-14 12:07:33 +0200
committersonartech <sonartech@sonarsource.com>2024-10-15 20:03:07 +0000
commit86a67f6f7084e06119ce81765002a738d3d54757 (patch)
tree4f1756f058268934bf4bc9d5f70dd75581249a4c /server/sonar-webserver
parent33d6dff86f9fc395b82d06e1e031e1f5a889dc5f (diff)
downloadsonarqube-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-webserver')
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java25
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryFipsEnabledProvider.java16
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java25
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryPortfolioConfidentialFlagProvider.java29
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java25
-rw-r--r--server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java17
6 files changed, 23 insertions, 114 deletions
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());
}