use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelLoggerImplTest method formatLogging.
@Test
public void formatLogging() {
ChannelTracer tracer = new ChannelTracer(logId, /* maxEvents= */
1, /* channelCreationTimeNanos= */
3L, "fooType");
ChannelLoggerImpl logger = new ChannelLoggerImpl(tracer, clock.getTimeProvider());
ChannelStats.Builder builder = new ChannelStats.Builder();
logs.clear();
clock.forwardNanos(100);
logger.log(ChannelLogLevel.ERROR, "Error message {0}", "foo");
tracer.updateBuilder(builder);
ChannelStats stats = builder.build();
Event event = new Event.Builder().setDescription("Error message foo").setSeverity(Severity.CT_ERROR).setTimestampNanos(100).build();
assertThat(stats.channelTrace.events).containsExactly(event);
assertThat(logs).contains("FINE: " + logPrefix + "Error message foo");
clock.forwardNanos(100);
logger.log(ChannelLogLevel.WARNING, "Warning message {0}, {1}", "foo", "bar");
tracer.updateBuilder(builder);
stats = builder.build();
event = new Event.Builder().setDescription("Warning message foo, bar").setSeverity(Severity.CT_WARNING).setTimestampNanos(200).build();
assertThat(stats.channelTrace.events).containsExactly(event);
assertThat(logs).contains("FINE: " + logPrefix + "Warning message foo, bar");
clock.forwardNanos(100);
logger.log(ChannelLogLevel.INFO, "Info message {0}", "bar");
tracer.updateBuilder(builder);
stats = builder.build();
event = new Event.Builder().setDescription("Info message bar").setSeverity(Severity.CT_INFO).setTimestampNanos(300).build();
assertThat(stats.channelTrace.events).containsExactly(event);
assertThat(logs).contains("FINER: " + logPrefix + "Info message bar");
clock.forwardNanos(100);
logger.log(ChannelLogLevel.DEBUG, "Debug message {0}", "foo");
tracer.updateBuilder(builder);
stats = builder.build();
// DEBUG level messages are not logged to channelz, thus channelz still has the
// last event.
assertThat(stats.channelTrace.events).containsExactly(event);
assertThat(logs).contains("FINEST: " + logPrefix + "Debug message foo");
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelzService method getChannel.
/**
* Returns a top level channel aka {@link io.grpc.ManagedChannel}.
*/
@Override
public void getChannel(GetChannelRequest request, StreamObserver<GetChannelResponse> responseObserver) {
InternalInstrumented<ChannelStats> s = channelz.getRootChannel(request.getChannelId());
if (s == null) {
responseObserver.onError(Status.NOT_FOUND.withDescription("Can't find channel " + request.getChannelId()).asRuntimeException());
return;
}
GetChannelResponse resp;
try {
resp = GetChannelResponse.newBuilder().setChannel(ChannelzProtoUtil.toChannel(s)).build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelzProtoUtilTest method channelTrace_withoutEvents.
@Test
public void channelTrace_withoutEvents() {
ChannelStats stats = toBuilder(channel.stats).setChannelTrace(new InternalChannelz.ChannelTrace.Builder().setNumEventsLogged(1234).setCreationTimeNanos(1000).build()).build();
ChannelData protoStats = channelData.toBuilder().setTrace(channelTrace).build();
assertEquals(ChannelzProtoUtil.extractChannelData(stats), protoStats);
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelzProtoUtilTest method toGetTopChannelsResponse.
@Test
public void toGetTopChannelsResponse() {
// empty results
assertEquals(GetTopChannelsResponse.newBuilder().setEnd(true).build(), ChannelzProtoUtil.toGetTopChannelResponse(new RootChannelList(Collections.<InternalInstrumented<ChannelStats>>emptyList(), true)));
// 1 result, paginated
assertEquals(GetTopChannelsResponse.newBuilder().addChannel(channelProto).build(), ChannelzProtoUtil.toGetTopChannelResponse(new RootChannelList(ImmutableList.<InternalInstrumented<ChannelStats>>of(channel), false)));
// 1 result, end
assertEquals(GetTopChannelsResponse.newBuilder().addChannel(channelProto).setEnd(true).build(), ChannelzProtoUtil.toGetTopChannelResponse(new RootChannelList(ImmutableList.<InternalInstrumented<ChannelStats>>of(channel), true)));
// 2 results, end
TestChannel channel2 = new TestChannel();
assertEquals(GetTopChannelsResponse.newBuilder().addChannel(channelProto).addChannel(ChannelzProtoUtil.toChannel(channel2)).setEnd(true).build(), ChannelzProtoUtil.toGetTopChannelResponse(new RootChannelList(ImmutableList.<InternalInstrumented<ChannelStats>>of(channel, channel2), true)));
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelzProtoUtil method toSubchannel.
static Subchannel toSubchannel(InternalInstrumented<ChannelStats> subchannel) {
ChannelStats stats = getFuture(subchannel.getStats());
Subchannel.Builder subchannelBuilder = Subchannel.newBuilder().setRef(toSubchannelRef(subchannel)).setData(extractChannelData(stats));
Preconditions.checkState(stats.sockets.isEmpty() || stats.subchannels.isEmpty());
for (InternalWithLogId childSocket : stats.sockets) {
subchannelBuilder.addSocketRef(toSocketRef(childSocket));
}
for (InternalWithLogId childSubchannel : stats.subchannels) {
subchannelBuilder.addSubchannelRef(toSubchannelRef(childSubchannel));
}
return subchannelBuilder.build();
}
Aggregations