Skip to content

Commit 527d243

Browse files
authored
core: more logs in ManagedChannelImpl. (grpc#2606)
They have already been added to ManagedChannelImpl2. Resolves grpc#2299
1 parent d59973c commit 527d243

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

core/src/main/java/io/grpc/internal/ManagedChannelImpl.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public void run() {
234234
IDLE_GRACE_PERIOD_MILLIS, TimeUnit.MILLISECONDS);
235235
return;
236236
}
237+
log.log(Level.FINE, "[{0}] Entering idle mode", getLogId());
237238
// Enter idle mode
238239
savedBalancer = graceLoadBalancer;
239240
graceLoadBalancer = null;
@@ -288,6 +289,7 @@ LoadBalancer<ClientTransport> exitIdleMode() {
288289
if (loadBalancer != null) {
289290
return loadBalancer;
290291
}
292+
log.log(Level.FINE, "[{0}] Exiting idle mode", getLogId());
291293
balancer = loadBalancerFactory.newLoadBalancer(nameResolver.getServiceAuthority(), tm);
292294
this.loadBalancer = balancer;
293295
resolver = this.nameResolver;
@@ -472,6 +474,7 @@ static NameResolver getNameResolver(String target, NameResolver.Factory nameReso
472474
*/
473475
@Override
474476
public ManagedChannelImpl shutdown() {
477+
log.log(Level.FINE, "[{0}] shutdown() called", getLogId());
475478
ArrayList<TransportSet> transportsCopy = new ArrayList<TransportSet>();
476479
ArrayList<DelayedClientTransport> delayedTransportsCopy =
477480
new ArrayList<DelayedClientTransport>();
@@ -483,6 +486,7 @@ public ManagedChannelImpl shutdown() {
483486
if (shutdown) {
484487
return this;
485488
}
489+
log.log(Level.FINE, "[{0}] Shutting down", getLogId());
486490
shutdown = true;
487491
// After shutdown there are no new calls, so no new cancellation tasks are needed
488492
scheduledExecutor = SharedResourceHolder.release(timerService, scheduledExecutor);
@@ -524,6 +528,7 @@ public ManagedChannelImpl shutdown() {
524528
*/
525529
@Override
526530
public ManagedChannelImpl shutdownNow() {
531+
log.log(Level.FINE, "[{0}] shutdownNow() called", getLogId());
527532
synchronized (lock) {
528533
// Short-circuiting not strictly necessary, but prevents transports from needing to handle
529534
// multiple shutdownNow invocations.
@@ -751,7 +756,7 @@ public LogId getLogId() {
751756
return logId;
752757
}
753758

754-
private static class NameResolverListenerImpl implements NameResolver.Listener {
759+
private class NameResolverListenerImpl implements NameResolver.Listener {
755760
final LoadBalancer<ClientTransport> balancer;
756761

757762
NameResolverListenerImpl(LoadBalancer<ClientTransport> balancer) {
@@ -764,10 +769,13 @@ public void onUpdate(List<ResolvedServerInfoGroup> servers, Attributes config) {
764769
onError(Status.UNAVAILABLE.withDescription("NameResolver returned an empty list"));
765770
return;
766771
}
772+
log.log(Level.FINE, "[{0}] resolved address: {1}, config={2}",
773+
new Object[] {getLogId(), servers, config});
767774

768775
try {
769776
balancer.handleResolvedAddresses(servers, config);
770777
} catch (Throwable e) {
778+
log.log(Level.WARNING, "[" + getLogId() + "] Unexpected exception from LoadBalancer", e);
771779
// It must be a bug! Push the exception back to LoadBalancer in the hope that it may be
772780
// propagated to the application.
773781
balancer.handleNameResolutionError(Status.INTERNAL.withCause(e)
@@ -778,6 +786,8 @@ public void onUpdate(List<ResolvedServerInfoGroup> servers, Attributes config) {
778786
@Override
779787
public void onError(Status error) {
780788
checkArgument(!error.isOk(), "the error status must not be OK");
789+
log.log(Level.WARNING, "[{0}] Failed to resolve name. status={1}",
790+
new Object[] {getLogId(), error});
781791
balancer.handleNameResolutionError(error);
782792
}
783793
}

core/src/main/java/io/grpc/internal/ManagedChannelImpl2.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,8 @@ public void run() {
764764
try {
765765
balancer.handleResolvedAddresses(servers, config);
766766
} catch (Throwable e) {
767-
log.log(Level.WARNING, "[" + getLogId() + "] Caught exception from LoadBalancer", e);
767+
log.log(
768+
Level.WARNING, "[" + getLogId() + "] Unexpected exception from LoadBalancer", e);
768769
// It must be a bug! Push the exception back to LoadBalancer in the hope that it may
769770
// be propagated to the application.
770771
balancer.handleNameResolutionError(Status.INTERNAL.withCause(e)

0 commit comments

Comments
 (0)