Skip to content

Commit

Permalink
use clientFactory meterRegistry by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Apr 26, 2021
1 parent e32a68e commit 693f651
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.linecorp.centraldogma.internal.client.ReplicationLagTolerantCentralDogma;
import com.linecorp.centraldogma.internal.thrift.CentralDogmaService.AsyncIface;

import io.micrometer.core.instrument.MeterRegistry;
import io.netty.channel.EventLoopGroup;

/**
Expand Down Expand Up @@ -67,8 +68,10 @@ public CentralDogma build() throws UnknownHostException {

final EventLoopGroup executor = clientFactory().eventLoopGroup();
final int maxRetriesOnReplicationLag = maxNumRetriesOnReplicationLag();
final MeterRegistry meterRegistry = meterRegistry().orElse(clientFactory().meterRegistry());

final CentralDogma dogma = new LegacyCentralDogma(executor, builder.build(AsyncIface.class),
meterRegistry());
meterRegistry);
if (maxRetriesOnReplicationLag <= 0) {
return dogma;
} else {
Expand All @@ -79,7 +82,7 @@ executor, dogma, maxRetriesOnReplicationLag, retryIntervalOnReplicationLagMillis
// in Armeria: https://github.com/line/armeria/issues/760
final ClientRequestContext ctx = ClientRequestContext.currentOrNull();
return ctx != null ? ctx.remoteAddress() : null;
}, meterRegistry());
}, meterRegistry);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.linecorp.centraldogma.client.CentralDogma;
import com.linecorp.centraldogma.internal.client.ReplicationLagTolerantCentralDogma;

import io.micrometer.core.instrument.MeterRegistry;
import io.netty.channel.EventLoopGroup;

/**
Expand All @@ -45,9 +46,10 @@ public CentralDogma build() throws UnknownHostException {
newClientBuilder(scheme, endpointGroup, cb -> cb.decorator(DecodingClient.newDecorator()), "/");
final EventLoopGroup executor = clientFactory().eventLoopGroup();
final int maxRetriesOnReplicationLag = maxNumRetriesOnReplicationLag();
final MeterRegistry meterRegistry = meterRegistry().orElse(clientFactory().meterRegistry());
final CentralDogma dogma = new ArmeriaCentralDogma(executor,
builder.build(WebClient.class),
accessToken(), meterRegistry());
accessToken(), meterRegistry);
if (maxRetriesOnReplicationLag <= 0) {
return dogma;
} else {
Expand All @@ -58,7 +60,7 @@ executor, dogma, maxRetriesOnReplicationLag, retryIntervalOnReplicationLagMillis
// in Armeria: https://github.com/line/armeria/issues/760
final ClientRequestContext ctx = ClientRequestContext.currentOrNull();
return ctx != null ? ctx.remoteAddress() : null;
}, meterRegistry());
}, meterRegistry);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -73,7 +74,7 @@ public abstract class AbstractCentralDogmaBuilder<B extends AbstractCentralDogma
private int maxNumRetriesOnReplicationLag = DEFAULT_MAX_NUM_RETRIES_ON_REPLICATION_LAG;
private long retryIntervalOnReplicationLagMillis =
TimeUnit.SECONDS.toMillis(DEFAULT_RETRY_INTERVAL_ON_REPLICATION_LAG_SECONDS);
private MeterRegistry meterRegistry = Metrics.globalRegistry;
private Optional<MeterRegistry> meterRegistry = Optional.empty();

/**
* Returns {@code this}.
Expand Down Expand Up @@ -424,11 +425,11 @@ protected long retryIntervalOnReplicationLagMillis() {
* Sets the {@link MeterRegistry} used to collect metrics.
*/
public final B meterRegistry(MeterRegistry meterRegistry) {
this.meterRegistry = requireNonNull(meterRegistry, "meterRegistry");
this.meterRegistry = Optional.of(requireNonNull(meterRegistry, "meterRegistry"));
return self();
}

protected MeterRegistry meterRegistry() {
protected Optional<MeterRegistry> meterRegistry() {
return meterRegistry;
}
}

0 comments on commit 693f651

Please sign in to comment.