diff options
author | Damien Urruty <damien.urruty@sonarsource.com> | 2024-10-14 12:07:33 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-10-15 20:03:07 +0000 |
commit | 86a67f6f7084e06119ce81765002a738d3d54757 (patch) | |
tree | 4f1756f058268934bf4bc9d5f70dd75581249a4c /server/sonar-server-common | |
parent | 33d6dff86f9fc395b82d06e1e031e1f5a889dc5f (diff) | |
download | sonarqube-86a67f6f7084e06119ce81765002a738d3d54757.tar.gz sonarqube-86a67f6f7084e06119ce81765002a738d3d54757.zip |
NO-JIRA Refactor v2 telemetry data provider
Introduce an abstract class to differentiate static characteristics (dimension, metric key, ...) and dynamic (the actual value) to better show how it is supposed to be used. It will also prevent future duplication reports on data providers
Diffstat (limited to 'server/sonar-server-common')
2 files changed, 6 insertions, 44 deletions
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() |