Search in sources :

Example 1 with Subchannel

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

Example 2 with Subchannel

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

Example 3 with Subchannel

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

Example 4 with Subchannel

use of io.grpc.channelz.v1.Subchannel 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)4 InternalWithLogId (io.grpc.InternalWithLogId)2 InternalChannelz (io.grpc.InternalChannelz)1 Event (io.grpc.InternalChannelz.ChannelTrace.Event)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 Channel (io.grpc.channelz.v1.Channel)1 ChannelData (io.grpc.channelz.v1.ChannelData)1 ChannelTraceEvent (io.grpc.channelz.v1.ChannelTraceEvent)1 GetSubchannelResponse (io.grpc.channelz.v1.GetSubchannelResponse)1 Subchannel (io.grpc.channelz.v1.Subchannel)1 Test (org.junit.Test)1