Search in sources :

Example 11 with ChannelStats

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");
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) Event(io.grpc.InternalChannelz.ChannelTrace.Event) Test(org.junit.Test)

Example 12 with ChannelStats

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();
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) StatusRuntimeException(io.grpc.StatusRuntimeException) GetChannelResponse(io.grpc.channelz.v1.GetChannelResponse)

Example 13 with ChannelStats

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);
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) ChannelData(io.grpc.channelz.v1.ChannelData) ChannelTrace(io.grpc.channelz.v1.ChannelTrace) Test(org.junit.Test)

Example 14 with ChannelStats

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)));
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) RootChannelList(io.grpc.InternalChannelz.RootChannelList) TestChannel(io.grpc.protobuf.services.ChannelzTestHelper.TestChannel) Test(org.junit.Test)

Example 15 with ChannelStats

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();
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) Subchannel(io.grpc.channelz.v1.Subchannel) InternalWithLogId(io.grpc.InternalWithLogId)

Aggregations

ChannelStats (io.grpc.InternalChannelz.ChannelStats)15 Test (org.junit.Test)11 Event (io.grpc.InternalChannelz.ChannelTrace.Event)5 RootChannelList (io.grpc.InternalChannelz.RootChannelList)5 InternalWithLogId (io.grpc.InternalWithLogId)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 ChannelData (io.grpc.channelz.v1.ChannelData)2 LogRecord (java.util.logging.LogRecord)2 InternalChannelz (io.grpc.InternalChannelz)1 Channel (io.grpc.channelz.v1.Channel)1 ChannelTrace (io.grpc.channelz.v1.ChannelTrace)1 ChannelTraceEvent (io.grpc.channelz.v1.ChannelTraceEvent)1 GetChannelResponse (io.grpc.channelz.v1.GetChannelResponse)1 GetSubchannelResponse (io.grpc.channelz.v1.GetSubchannelResponse)1 Subchannel (io.grpc.channelz.v1.Subchannel)1 TestChannel (io.grpc.protobuf.services.ChannelzTestHelper.TestChannel)1