Skip to content

Commit

Permalink
FINERACT-2081: Make MeterRegistry optional
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaghy committed Jan 10, 2025
1 parent 100405a commit aae6d3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.zaxxer.hikari.HikariConfig;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.micrometer.core.instrument.MeterRegistry;
import java.util.Optional;
import javax.sql.DataSource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class DataSourcePerTenantServiceFactory {
private final HikariDataSourceFactory hikariDataSourceFactory;

private final DatabasePasswordEncryptor databasePasswordEncryptor;
private final MeterRegistry meterRegistry;
private final Optional<MeterRegistry> meterRegistry;

@SuppressFBWarnings(value = "SLF4J_SIGN_ONLY_FORMAT")
public DataSource createNewDataSourceFor(FineractPlatformTenant tenant, FineractPlatformTenantConnection tenantConnection) {
Expand Down Expand Up @@ -97,7 +98,9 @@ public DataSource createNewDataSourceFor(FineractPlatformTenant tenant, Fineract

// https://github.com/brettwooldridge/HikariCP/wiki/MBean-(JMX)-Monitoring-and-Management
config.setRegisterMbeans(true);
config.setMetricsTrackerFactory(new TenantConnectionPoolMetricsTrackerFactory(tenant.getTenantIdentifier(), meterRegistry));
meterRegistry.ifPresent(registry -> {
config.setMetricsTrackerFactory(new TenantConnectionPoolMetricsTrackerFactory(tenant.getTenantIdentifier(), registry));
});

// https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
// These are the properties for each Tenant DB; the same configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import io.micrometer.core.instrument.MeterRegistry;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Optional;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.fineract.infrastructure.core.config.FineractProperties;
Expand Down Expand Up @@ -113,6 +115,9 @@ public class DataSourcePerTenantServiceFactoryTest {
@Mock
private DatabasePasswordEncryptor databasePasswordEncryptor;

@Mock
private Optional<MeterRegistry> meterRegistry;

@InjectMocks
private DataSourcePerTenantServiceFactory underTest;

Expand Down

0 comments on commit aae6d3a

Please sign in to comment.