Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/src/main/java/io/grpc/internal/ManagedChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ void handleUncaughtThrowable(Throwable t) {
@CheckForNull
private final ChannelTracer channelTracer;
private final Channelz channelz;
private Boolean zeroBackends; // a flag for doing channel tracing when flipped

// One instance per channel.
private final ChannelBufferMeter channelBufferUsed = new ChannelBufferMeter();
Expand Down Expand Up @@ -1246,12 +1247,13 @@ public void onAddresses(final List<EquivalentAddressGroup> servers, final Attrib
new Object[]{getLogId(), servers, config});
}

if (channelTracer != null) {
if (channelTracer != null && (zeroBackends == null || zeroBackends)) {
channelTracer.reportEvent(new ChannelTrace.Event.Builder()
.setDescription("Address resolved: " + servers)
.setSeverity(ChannelTrace.Event.Severity.CT_INFO)
.setTimestampNanos(timeProvider.currentTimeNanos())
.build());
zeroBackends = false;
}

final class NamesResolved implements Runnable {
Expand Down Expand Up @@ -1292,12 +1294,13 @@ public void onError(final Status error) {
checkArgument(!error.isOk(), "the error status must not be OK");
logger.log(Level.WARNING, "[{0}] Failed to resolve name. status={1}",
new Object[] {getLogId(), error});
if (channelTracer != null) {
if (channelTracer != null && (zeroBackends == null || !zeroBackends)) {
channelTracer.reportEvent(new ChannelTrace.Event.Builder()
.setDescription("Failed to resolve name")
.setSeverity(ChannelTrace.Event.Severity.CT_WARNING)
.setTimestampNanos(timeProvider.currentTimeNanos())
.build());
zeroBackends = true;
}
channelExecutor
.executeLater(
Expand Down
34 changes: 34 additions & 0 deletions core/src/test/java/io/grpc/internal/ManagedChannelImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,40 @@ public void channelTracing_nameResolvedEvent() throws Exception {
.build());
}

@Test
public void channelTracing_nameResolvedEvent_zeorAndNonzeroBackends() throws Exception {
timer.forwardNanos(1234);
channelBuilder.maxTraceEvents(10);
List<EquivalentAddressGroup> servers = new ArrayList<EquivalentAddressGroup>();
servers.add(new EquivalentAddressGroup(socketAddress));
FakeNameResolverFactory nameResolverFactory =
new FakeNameResolverFactory.Builder(expectedUri).setServers(servers).build();
channelBuilder.nameResolverFactory(nameResolverFactory);
createChannel();

int prevSize = getStats(channel).channelTrace.events.size();
nameResolverFactory.resolvers.get(0).listener.onAddresses(
Collections.singletonList(new EquivalentAddressGroup(
Arrays.asList(new SocketAddress() {}, new SocketAddress() {}))),
Attributes.EMPTY);
assertThat(getStats(channel).channelTrace.events).hasSize(prevSize);

prevSize = getStats(channel).channelTrace.events.size();
nameResolverFactory.resolvers.get(0).listener.onError(Status.INTERNAL);
assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);

prevSize = getStats(channel).channelTrace.events.size();
nameResolverFactory.resolvers.get(0).listener.onError(Status.INTERNAL);
assertThat(getStats(channel).channelTrace.events).hasSize(prevSize);

prevSize = getStats(channel).channelTrace.events.size();
nameResolverFactory.resolvers.get(0).listener.onAddresses(
Collections.singletonList(new EquivalentAddressGroup(
Arrays.asList(new SocketAddress() {}, new SocketAddress() {}))),
Attributes.EMPTY);
assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
}

@Test
public void channelTracing_stateChangeEvent() throws Exception {
channelBuilder.maxTraceEvents(10);
Expand Down