Search in sources :

Example 1 with Downstream

use of org.apache.skywalking.apm.network.proto.Downstream in project incubator-skywalking by apache.

the class GRPCNoServerTest method main.

public static void main(String[] args) throws InterruptedException {
    ManagedChannelBuilder<?> channelBuilder = NettyChannelBuilder.forAddress("127.0.0.1", 8080).nameResolverFactory(new DnsNameResolverProvider()).maxInboundMessageSize(1024 * 1024 * 50).usePlaintext(true);
    ManagedChannel channel = channelBuilder.build();
    TraceSegmentServiceGrpc.TraceSegmentServiceStub serviceStub = TraceSegmentServiceGrpc.newStub(channel);
    final Status[] status = { null };
    StreamObserver<UpstreamSegment> streamObserver = serviceStub.collect(new StreamObserver<Downstream>() {

        @Override
        public void onNext(Downstream value) {
        }

        @Override
        public void onError(Throwable t) {
            status[0] = ((StatusRuntimeException) t).getStatus();
        }

        @Override
        public void onCompleted() {
        }
    });
    streamObserver.onNext(null);
    streamObserver.onCompleted();
    Thread.sleep(2 * 1000);
    Assert.assertEquals(status[0].getCode(), Status.UNAVAILABLE.getCode());
}
Also used : Status(io.grpc.Status) UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) TraceSegmentServiceGrpc(org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc) DnsNameResolverProvider(io.grpc.internal.DnsNameResolverProvider) StatusRuntimeException(io.grpc.StatusRuntimeException) ManagedChannel(io.grpc.ManagedChannel) Downstream(org.apache.skywalking.apm.network.proto.Downstream)

Example 2 with Downstream

use of org.apache.skywalking.apm.network.proto.Downstream in project incubator-skywalking by apache.

the class TraceSegmentServiceClient method consume.

@Override
public void consume(List<TraceSegment> data) {
    if (CONNECTED.equals(status)) {
        final GRPCStreamServiceStatus status = new GRPCStreamServiceStatus(false);
        StreamObserver<UpstreamSegment> upstreamSegmentStreamObserver = serviceStub.collect(new StreamObserver<Downstream>() {

            @Override
            public void onNext(Downstream downstream) {
            }

            @Override
            public void onError(Throwable throwable) {
                status.finished();
                if (logger.isErrorEnable()) {
                    logger.error(throwable, "Send UpstreamSegment to collector fail with a grpc internal exception.");
                }
                ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(throwable);
            }

            @Override
            public void onCompleted() {
                status.finished();
            }
        });
        for (TraceSegment segment : data) {
            try {
                UpstreamSegment upstreamSegment = segment.transform();
                upstreamSegmentStreamObserver.onNext(upstreamSegment);
            } catch (Throwable t) {
                logger.error(t, "Transform and send UpstreamSegment to collector fail.");
            }
        }
        upstreamSegmentStreamObserver.onCompleted();
        if (status.wait4Finish(TIMEOUT)) {
            segmentUplinkedCounter += data.size();
        }
    } else {
        segmentAbandonedCounter += data.size();
    }
    printUplinkStatus();
}
Also used : UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) Downstream(org.apache.skywalking.apm.network.proto.Downstream) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)

Aggregations

Downstream (org.apache.skywalking.apm.network.proto.Downstream)2 UpstreamSegment (org.apache.skywalking.apm.network.proto.UpstreamSegment)2 ManagedChannel (io.grpc.ManagedChannel)1 Status (io.grpc.Status)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 DnsNameResolverProvider (io.grpc.internal.DnsNameResolverProvider)1 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)1 TraceSegmentServiceGrpc (org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc)1