Skip to content

Commit 62d26a2

Browse files
committed
Fix DI
1 parent ecccf2e commit 62d26a2

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

src/main/java/io/getunleash/metric/UnleashMetricServiceImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.getunleash.engine.UnleashEngine;
55
import io.getunleash.impactmetrics.CollectedMetric;
66
import io.getunleash.impactmetrics.ImpactMetricsDataSource;
7-
import io.getunleash.impactmetrics.InMemoryMetricRegistry;
87
import io.getunleash.util.Throttler;
98
import io.getunleash.util.UnleashConfig;
109
import io.getunleash.util.UnleashScheduledExecutor;
@@ -48,9 +47,7 @@ public UnleashMetricServiceImpl(
4847
300,
4948
unleashConfig.getUnleashURLs().getClientMetricsURL());
5049
this.engine = engine;
51-
ImpactMetricsDataSource configuredRegistry = unleashConfig.getImpactMetricsRegistry();
52-
this.impactMetricsRegistry =
53-
configuredRegistry != null ? configuredRegistry : new InMemoryMetricRegistry();
50+
this.impactMetricsRegistry = unleashConfig.getImpactMetricsRegistry();
5451
long metricsInterval = unleashConfig.getSendMetricsInterval();
5552

5653
executor.setInterval(sendMetrics(), metricsInterval, metricsInterval);

src/main/java/io/getunleash/util/UnleashConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class UnleashConfig {
7474
@Nullable private final ToggleBootstrapProvider toggleBootstrapProvider;
7575
@Nullable private final Proxy proxy;
7676
@Nullable private final Consumer<UnleashException> startupExceptionHandler;
77-
@Nullable private final ImpactMetricsDataSource impactMetricsRegistry;
77+
private final ImpactMetricsDataSource impactMetricsRegistry;
7878

7979
private UnleashConfig(
8080
@Nullable URI unleashAPI,
@@ -109,7 +109,7 @@ private UnleashConfig(
109109
@Nullable Proxy proxy,
110110
@Nullable Authenticator proxyAuthenticator,
111111
@Nullable Consumer<UnleashException> startupExceptionHandler,
112-
@Nullable ImpactMetricsDataSource impactMetricsRegistry) {
112+
ImpactMetricsDataSource impactMetricsRegistry) {
113113

114114
if (appName == null) {
115115
throw new IllegalStateException("You are required to specify the unleash appName");
@@ -356,7 +356,6 @@ public Proxy getProxy() {
356356
return proxy;
357357
}
358358

359-
@Nullable
360359
public ImpactMetricsDataSource getImpactMetricsRegistry() {
361360
return impactMetricsRegistry;
362361
}
@@ -766,7 +765,8 @@ public UnleashConfig build() {
766765
proxy,
767766
proxyAuthenticator,
768767
startupExceptionHandler,
769-
impactMetricsRegistry);
768+
Optional.ofNullable(impactMetricsRegistry)
769+
.orElseGet(io.getunleash.impactmetrics.InMemoryMetricRegistry::new));
770770
}
771771

772772
public String getDefaultSdkVersion() {

0 commit comments

Comments
 (0)