use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelTracerTest method channelTracerWithZeroMaxEvents.
@Test
public void channelTracerWithZeroMaxEvents() {
ChannelTracer channelTracer = new ChannelTracer(logId, /* maxEvents= */
0, /* channelCreationTimeNanos= */
3L, "fooType");
ChannelStats.Builder builder = new ChannelStats.Builder();
Event e1 = new Event.Builder().setDescription("e1").setSeverity(Severity.CT_ERROR).setTimestampNanos(1001).build();
channelTracer.reportEvent(e1);
channelTracer.updateBuilder(builder);
ChannelStats stats = builder.build();
assertThat(stats.channelTrace).isNull();
assertThat(logs).hasSize(2);
LogRecord log = logs.remove(0);
assertThat(log.getMessage()).isEqualTo(logPrefix + "fooType created");
assertThat(log.getLevel()).isEqualTo(Level.FINEST);
log = logs.remove(0);
assertThat(log.getMessage()).isEqualTo(logPrefix + "e1");
assertThat(log.getLevel()).isEqualTo(Level.FINE);
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelLoggerImplTest method logging.
@Test
public void logging() {
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");
tracer.updateBuilder(builder);
ChannelStats stats = builder.build();
Event event = new Event.Builder().setDescription("Error message").setSeverity(Severity.CT_ERROR).setTimestampNanos(100).build();
assertThat(stats.channelTrace.events).containsExactly(event);
assertThat(logs).contains("FINE: " + logPrefix + "Error message");
clock.forwardNanos(100);
logger.log(ChannelLogLevel.WARNING, "Warning message");
tracer.updateBuilder(builder);
stats = builder.build();
event = new Event.Builder().setDescription("Warning message").setSeverity(Severity.CT_WARNING).setTimestampNanos(200).build();
assertThat(stats.channelTrace.events).containsExactly(event);
assertThat(logs).contains("FINE: " + logPrefix + "Warning message");
clock.forwardNanos(100);
logger.log(ChannelLogLevel.INFO, "Info message");
tracer.updateBuilder(builder);
stats = builder.build();
event = new Event.Builder().setDescription("Info message").setSeverity(Severity.CT_INFO).setTimestampNanos(300).build();
assertThat(stats.channelTrace.events).containsExactly(event);
assertThat(logs).contains("FINER: " + logPrefix + "Info message");
clock.forwardNanos(100);
logger.log(ChannelLogLevel.DEBUG, "Debug message");
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");
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelzProtoUtil method toChannel.
static Channel toChannel(InternalInstrumented<ChannelStats> channel) {
ChannelStats stats = getFuture(channel.getStats());
Channel.Builder channelBuilder = Channel.newBuilder().setRef(toChannelRef(channel)).setData(extractChannelData(stats));
for (InternalWithLogId subchannel : stats.subchannels) {
channelBuilder.addSubchannelRef(toSubchannelRef(subchannel));
}
return channelBuilder.build();
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelzProtoUtilTest method channelTrace_withEvents.
@Test
public void channelTrace_withEvents() {
Event event1 = new Event.Builder().setDescription("event1").setSeverity(Severity.CT_ERROR).setTimestampNanos(12).setSubchannelRef(subchannel).build();
Event event2 = new Event.Builder().setDescription("event2").setTimestampNanos(34).setSeverity(Severity.CT_INFO).setChannelRef(channel).build();
ChannelStats stats = toBuilder(channel.stats).setChannelTrace(new InternalChannelz.ChannelTrace.Builder().setNumEventsLogged(1234).setCreationTimeNanos(1000).setEvents(Arrays.asList(event1, event2)).build()).build();
ChannelTraceEvent protoEvent1 = ChannelTraceEvent.newBuilder().setDescription("event1").setTimestamp(Timestamps.fromNanos(12)).setSeverity(ChannelTraceEvent.Severity.CT_ERROR).setSubchannelRef(subchannelRef).build();
ChannelTraceEvent protoEvent2 = ChannelTraceEvent.newBuilder().setDescription("event2").setTimestamp(Timestamps.fromNanos(34)).setSeverity(ChannelTraceEvent.Severity.CT_INFO).setChannelRef(channelRef).build();
ChannelData protoStats = channelData.toBuilder().setTrace(channelTrace.toBuilder().addAllEvents(Arrays.asList(protoEvent1, protoEvent2)).build()).build();
assertEquals(ChannelzProtoUtil.extractChannelData(stats), protoStats);
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelzService method getSubchannel.
/**
* Returns a subchannel.
*/
@Override
public void getSubchannel(GetSubchannelRequest request, StreamObserver<GetSubchannelResponse> responseObserver) {
InternalInstrumented<ChannelStats> s = channelz.getSubchannel(request.getSubchannelId());
if (s == null) {
responseObserver.onError(Status.NOT_FOUND.withDescription("Can't find subchannel " + request.getSubchannelId()).asRuntimeException());
return;
}
GetSubchannelResponse resp;
try {
resp = GetSubchannelResponse.newBuilder().setSubchannel(ChannelzProtoUtil.toSubchannel(s)).build();
} catch (StatusRuntimeException e) {
responseObserver.onError(e);
return;
}
responseObserver.onNext(resp);
responseObserver.onCompleted();
}
Aggregations