Search in sources :

Example 1 with PSpanMessage

use of com.navercorp.pinpoint.grpc.trace.PSpanMessage in project pinpoint by naver.

the class SpanClientMock method span.

public void span(int count) {
    final int size = 1000;
    final byte[] bytes = new byte[size];
    for (int i = 0; i < size; i++) {
        bytes[i] = (byte) i;
    }
    PAnnotationValue value = PAnnotationValue.newBuilder().setBinaryValue(ByteString.copyFrom(bytes)).build();
    PAnnotation annotation = PAnnotation.newBuilder().setValue(value).build();
    PSpanEvent spanEvent = PSpanEvent.newBuilder().addAnnotation(annotation).build();
    AtomicLong counter = new AtomicLong();
    service.execute(new Runnable() {

        @Override
        public void run() {
            // StreamObserver<PSpanMessage> requestObserver = spanStub.sendSpan(responseObserver);
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
            }
            for (int i = 0; i < count; i++) {
                final PSpan span = PSpan.newBuilder().setSpanId(i).addSpanEvent(spanEvent).build();
                final PSpanMessage spanMessage = PSpanMessage.newBuilder().setSpan(span).build();
                spanStream.onNext(spanMessage);
                // requestObserver.onNext(spanMessage);
                try {
                    TimeUnit.MILLISECONDS.sleep(10);
                } catch (InterruptedException e) {
                }
            // System.out.print("S");
            }
            spanStream.onCompleted();
        // requestObserver.onCompleted();
        }
    });
}
Also used : PAnnotationValue(com.navercorp.pinpoint.grpc.trace.PAnnotationValue) AtomicLong(java.util.concurrent.atomic.AtomicLong) PSpanMessage(com.navercorp.pinpoint.grpc.trace.PSpanMessage) PSpan(com.navercorp.pinpoint.grpc.trace.PSpan) PAnnotation(com.navercorp.pinpoint.grpc.trace.PAnnotation) PSpanEvent(com.navercorp.pinpoint.grpc.trace.PSpanEvent)

Example 2 with PSpanMessage

use of com.navercorp.pinpoint.grpc.trace.PSpanMessage in project pinpoint by naver.

the class SpanClientMock method newSpanStream.

private StreamObserver<PSpanMessage> newSpanStream() {
    System.out.println("### ");
    System.out.println("NEW SpanStream");
    System.out.println("###");
    StreamId spanId = StreamId.newStreamId("SpanStream");
    StreamEventListener<PSpanMessage> listener = new StreamEventListener<PSpanMessage>() {

        @Override
        public void start(ClientCallStreamObserver<PSpanMessage> requestStream) {
            spanStreamReconnector.reset();
        }

        @Override
        public void onError(Throwable t) {
            spanStreamReconnector.reconnect();
        }

        @Override
        public void onCompleted() {
            spanStreamReconnector.reconnect();
        }
    };
    ResponseStreamObserver<PSpanMessage, Empty> responseStreamObserver = new ResponseStreamObserver<PSpanMessage, Empty>(listener);
    return spanStub.sendSpan(responseStreamObserver);
}
Also used : StreamId(com.navercorp.pinpoint.profiler.sender.grpc.StreamId) Empty(com.google.protobuf.Empty) PSpanMessage(com.navercorp.pinpoint.grpc.trace.PSpanMessage) ClientCallStreamObserver(io.grpc.stub.ClientCallStreamObserver) ResponseStreamObserver(com.navercorp.pinpoint.profiler.sender.grpc.ResponseStreamObserver) StreamEventListener(com.navercorp.pinpoint.profiler.sender.grpc.StreamEventListener)

Example 3 with PSpanMessage

use of com.navercorp.pinpoint.grpc.trace.PSpanMessage in project pinpoint by naver.

the class ChannelFactoryTest method build.

@Test
public void build() throws InterruptedException {
    HeaderFactory headerFactory = new AgentHeaderFactory("agentId", "agentName", "appName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis());
    CountRecordClientInterceptor countRecordClientInterceptor = new CountRecordClientInterceptor();
    ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder(this.getClass().getSimpleName());
    channelFactoryBuilder.setHeaderFactory(headerFactory);
    channelFactoryBuilder.setNameResolverProvider(nameResolverProvider);
    channelFactoryBuilder.addClientInterceptor(countRecordClientInterceptor);
    channelFactoryBuilder.setClientOption(new ClientOption());
    ChannelFactory channelFactory = channelFactoryBuilder.build();
    ManagedChannel managedChannel = channelFactory.build("127.0.0.1", PORT);
    managedChannel.getState(false);
    SpanGrpc.SpanStub spanStub = SpanGrpc.newStub(managedChannel);
    final QueueingStreamObserver<Empty> responseObserver = new QueueingStreamObserver<>();
    logger.debug("sendSpan");
    StreamObserver<PSpanMessage> sendSpan = spanStub.sendSpan(responseObserver);
    PSpan pSpan = newSpan();
    PSpanMessage message = PSpanMessage.newBuilder().setSpan(pSpan).build();
    logger.debug("client-onNext");
    sendSpan.onNext(message);
    logger.debug("wait for response");
    Empty value = responseObserver.getValue();
    logger.debug("response:{}", value);
    logger.debug("client-onCompleted");
    sendSpan.onCompleted();
    Assert.assertEquals(1, countRecordClientInterceptor.getExecutedInterceptCallCount());
    logger.debug("state:{}", managedChannel.getState(true));
    spanService.awaitOnCompleted();
    logger.debug("managedChannel shutdown");
    managedChannel.shutdown();
    managedChannel.awaitTermination(1000, TimeUnit.MILLISECONDS);
    channelFactory.close();
}
Also used : HeaderFactory(com.navercorp.pinpoint.grpc.client.HeaderFactory) ChannelFactory(com.navercorp.pinpoint.grpc.client.ChannelFactory) ChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder) DefaultChannelFactoryBuilder(com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder) Empty(com.google.protobuf.Empty) PSpanMessage(com.navercorp.pinpoint.grpc.trace.PSpanMessage) PSpan(com.navercorp.pinpoint.grpc.trace.PSpan) ManagedChannel(io.grpc.ManagedChannel) SpanGrpc(com.navercorp.pinpoint.grpc.trace.SpanGrpc) ClientOption(com.navercorp.pinpoint.grpc.client.config.ClientOption) Test(org.junit.Test)

Example 4 with PSpanMessage

use of com.navercorp.pinpoint.grpc.trace.PSpanMessage in project pinpoint by naver.

the class SpanService method sendSpan.

@Override
public StreamObserver<PSpanMessage> sendSpan(final StreamObserver<Empty> responseObserver) {
    StreamObserver<PSpanMessage> observer = new StreamObserver<PSpanMessage>() {

        @Override
        public void onNext(PSpanMessage spanMessage) {
            if (isDebug) {
                logger.debug("Send PSpan={}", MessageFormatUtils.debugLog(spanMessage));
            }
            if (spanMessage.hasSpan()) {
                final Message<PSpan> message = newMessage(spanMessage.getSpan(), DefaultTBaseLocator.SPAN);
                send(message, responseObserver);
            } else if (spanMessage.hasSpanChunk()) {
                final Message<PSpanChunk> message = newMessage(spanMessage.getSpanChunk(), DefaultTBaseLocator.SPANCHUNK);
                send(message, responseObserver);
            } else {
                if (isDebug) {
                    logger.debug("Found empty span message {}", MessageFormatUtils.debugLog(spanMessage));
                }
            }
        }

        @Override
        public void onError(Throwable throwable) {
            com.navercorp.pinpoint.grpc.Header header = ServerContext.getAgentInfo();
            final StatusError statusError = StatusErrors.throwable(throwable);
            if (statusError.isSimpleError()) {
                logger.info("Failed to span stream, {} cause={}", header, statusError.getMessage(), statusError.getThrowable());
            } else {
                logger.warn("Failed to span stream, {} cause={}", header, statusError.getMessage(), statusError.getThrowable());
            }
        }

        @Override
        public void onCompleted() {
            com.navercorp.pinpoint.grpc.Header header = ServerContext.getAgentInfo();
            logger.info("onCompleted {}", header);
            Empty empty = Empty.newBuilder().build();
            responseObserver.onNext(empty);
            responseObserver.onCompleted();
        }
    };
    return observer;
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Empty(com.google.protobuf.Empty) PSpanMessage(com.navercorp.pinpoint.grpc.trace.PSpanMessage) PSpan(com.navercorp.pinpoint.grpc.trace.PSpan) Message(com.navercorp.pinpoint.io.request.Message) DefaultMessage(com.navercorp.pinpoint.io.request.DefaultMessage) PSpanMessage(com.navercorp.pinpoint.grpc.trace.PSpanMessage) StatusError(com.navercorp.pinpoint.grpc.StatusError)

Aggregations

PSpanMessage (com.navercorp.pinpoint.grpc.trace.PSpanMessage)4 Empty (com.google.protobuf.Empty)3 PSpan (com.navercorp.pinpoint.grpc.trace.PSpan)3 StatusError (com.navercorp.pinpoint.grpc.StatusError)1 ChannelFactory (com.navercorp.pinpoint.grpc.client.ChannelFactory)1 ChannelFactoryBuilder (com.navercorp.pinpoint.grpc.client.ChannelFactoryBuilder)1 DefaultChannelFactoryBuilder (com.navercorp.pinpoint.grpc.client.DefaultChannelFactoryBuilder)1 HeaderFactory (com.navercorp.pinpoint.grpc.client.HeaderFactory)1 ClientOption (com.navercorp.pinpoint.grpc.client.config.ClientOption)1 PAnnotation (com.navercorp.pinpoint.grpc.trace.PAnnotation)1 PAnnotationValue (com.navercorp.pinpoint.grpc.trace.PAnnotationValue)1 PSpanEvent (com.navercorp.pinpoint.grpc.trace.PSpanEvent)1 SpanGrpc (com.navercorp.pinpoint.grpc.trace.SpanGrpc)1 DefaultMessage (com.navercorp.pinpoint.io.request.DefaultMessage)1 Message (com.navercorp.pinpoint.io.request.Message)1 ResponseStreamObserver (com.navercorp.pinpoint.profiler.sender.grpc.ResponseStreamObserver)1 StreamEventListener (com.navercorp.pinpoint.profiler.sender.grpc.StreamEventListener)1 StreamId (com.navercorp.pinpoint.profiler.sender.grpc.StreamId)1 ManagedChannel (io.grpc.ManagedChannel)1 ClientCallStreamObserver (io.grpc.stub.ClientCallStreamObserver)1