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();
}
});
}
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);
}
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();
}
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;
}
Aggregations