use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext in project pinpoint by naver.
the class SpanDecoderV0 method readNextSpanEvent.
private SpanEventBo readNextSpanEvent(final Buffer buffer, final SpanEventBo prev, SpanDecodingContext decodingContext) {
final SpanEventBo spanEventBo = new SpanEventBo();
final SpanEventBitField bitField = new SpanEventBitField(buffer.readShort());
switch(bitField.getStartElapsedEncodingStrategy()) {
case PREV_DELTA:
int startTimeDelta = buffer.readVInt();
int startTime = startTimeDelta + prev.getStartElapsed();
spanEventBo.setStartElapsed(startTime);
break;
case PREV_EQUALS:
spanEventBo.setStartElapsed(prev.getStartElapsed());
break;
default:
throw new IllegalStateException("unsupported SequenceEncodingStrategy");
}
spanEventBo.setEndElapsed(buffer.readVInt());
switch(bitField.getSequenceEncodingStrategy()) {
case PREV_DELTA:
int sequenceDelta = buffer.readVInt();
final int sequence = sequenceDelta + prev.getSequence();
spanEventBo.setSequence((short) sequence);
break;
case PREV_ADD1:
spanEventBo.setSequence((short) (prev.getSequence() + 1));
break;
default:
throw new IllegalStateException("unsupported SequenceEncodingStrategy");
}
switch(bitField.getDepthEncodingStrategy()) {
case RAW:
spanEventBo.setDepth(buffer.readSVInt());
break;
case PREV_EQUALS:
spanEventBo.setDepth(prev.getDepth());
break;
default:
throw new IllegalStateException("unsupported DepthEncodingStrategy");
}
switch(bitField.getServiceTypeEncodingStrategy()) {
case RAW:
spanEventBo.setServiceType(buffer.readShort());
break;
case PREV_EQUALS:
spanEventBo.setServiceType(prev.getServiceType());
break;
default:
throw new IllegalStateException("unsupported ServiceTypeEncodingStrategy");
}
spanEventBo.setApiId(buffer.readSVInt());
if (bitField.isSetRpc()) {
spanEventBo.setRpc(buffer.readPrefixedString());
}
if (bitField.isSetEndPoint()) {
spanEventBo.setEndPoint(buffer.readPrefixedString());
}
if (bitField.isSetDestinationId()) {
spanEventBo.setDestinationId(buffer.readPrefixedString());
}
if (bitField.isSetNextSpanId()) {
spanEventBo.setNextSpanId(buffer.readLong());
}
if (bitField.isSetHasException()) {
int exceptionId = buffer.readSVInt();
String exceptionMessage = buffer.readPrefixedString();
spanEventBo.setExceptionInfo(exceptionId, exceptionMessage);
}
if (bitField.isSetAnnotation()) {
List<AnnotationBo> annotationBoList = readAnnotationList(buffer, decodingContext);
spanEventBo.setAnnotationBoList(annotationBoList);
}
if (bitField.isSetNextAsyncId()) {
spanEventBo.setNextAsyncId(buffer.readSVInt());
}
if (bitField.isSetAsyncId()) {
spanEventBo.setAsyncId(buffer.readInt());
spanEventBo.setAsyncSequence((short) buffer.readVInt());
}
return spanEventBo;
}
use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext in project pinpoint by naver.
the class SpanMapperV2 method mapRow.
@Override
public List<SpanBo> mapRow(Result result, int rowNum) throws Exception {
if (result.isEmpty()) {
return Collections.emptyList();
}
byte[] rowKey = result.getRow();
final TransactionId transactionId = this.rowKeyDecoder.decodeRowKey(rowKey);
final Cell[] rawCells = result.rawCells();
ListMultimap<AgentKey, SpanBo> spanMap = LinkedListMultimap.create();
List<SpanChunkBo> spanChunkList = new ArrayList<>();
final SpanDecodingContext decodingContext = new SpanDecodingContext();
decodingContext.setTransactionId(transactionId);
for (Cell cell : rawCells) {
SpanDecoder spanDecoder = null;
// only if family name is "span"
if (CellUtil.matchingFamily(cell, HBaseTables.TRACE_V2_CF_SPAN)) {
decodingContext.setCollectorAcceptedTime(cell.getTimestamp());
final Buffer qualifier = new OffsetFixedBuffer(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
final Buffer columnValue = new OffsetFixedBuffer(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
spanDecoder = resolveDecoder(columnValue);
final Object decodeObject = spanDecoder.decode(qualifier, columnValue, decodingContext);
if (decodeObject instanceof SpanBo) {
SpanBo spanBo = (SpanBo) decodeObject;
if (logger.isDebugEnabled()) {
logger.debug("spanBo:{}", spanBo);
}
AgentKey agentKey = newAgentKey(spanBo);
spanMap.put(agentKey, spanBo);
} else if (decodeObject instanceof SpanChunkBo) {
SpanChunkBo spanChunkBo = (SpanChunkBo) decodeObject;
if (logger.isDebugEnabled()) {
logger.debug("spanChunkBo:{}", spanChunkBo);
}
spanChunkList.add(spanChunkBo);
}
} else {
logger.warn("Unknown ColumnFamily :{}", Bytes.toStringBinary(CellUtil.cloneFamily(cell)));
}
nextCell(spanDecoder, decodingContext);
}
decodingContext.finish();
return buildSpanBoList(spanMap, spanChunkList);
}
use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext in project pinpoint by naver.
the class SpanMapperV2Test method test.
@Test
public void test() {
SpanBo span = new SpanBo();
span.setServiceType((short) 1000);
span.setExceptionInfo(1, "spanException");
SpanEventBo firstSpanEventBo = new SpanEventBo();
firstSpanEventBo.setExceptionInfo(2, "first");
firstSpanEventBo.setEndElapsed(100);
AnnotationBo annotationBo = newAnnotation(200, "annotation");
firstSpanEventBo.setAnnotationBoList(Lists.<AnnotationBo>newArrayList(annotationBo));
firstSpanEventBo.setServiceType((short) 1003);
firstSpanEventBo.setSequence((short) 0);
span.addSpanEvent(firstSpanEventBo);
//// next
SpanEventBo nextSpanEventBo = new SpanEventBo();
nextSpanEventBo.setEndElapsed(200);
nextSpanEventBo.setServiceType((short) 2003);
nextSpanEventBo.setSequence((short) 1);
span.addSpanEvent(nextSpanEventBo);
SpanEncodingContext<SpanBo> encodingContext = new SpanEncodingContext<>(span);
SpanEncoder encoder = new SpanEncoderV0();
ByteBuffer byteBuffer = encoder.encodeSpanColumnValue(encodingContext);
Buffer buffer = new OffsetFixedBuffer(byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.remaining());
SpanBo readSpan = new SpanBo();
SpanDecodingContext decodingContext = new SpanDecodingContext();
decoder.readSpanValue(buffer, readSpan, new SpanEventBo(), decodingContext);
Assert.assertEquals(readSpan.getSpanEventBoList().size(), 2);
// span
Assert.assertEquals(readSpan.getServiceType(), 1000);
Assert.assertEquals(readSpan.hasException(), true);
Assert.assertEquals(readSpan.getExceptionId(), 1);
Assert.assertEquals(readSpan.getExceptionMessage(), "spanException");
List<SpanEventBo> spanEventBoList = readSpan.getSpanEventBoList();
SpanEventBo readFirst = spanEventBoList.get(0);
SpanEventBo readNext = spanEventBoList.get(1);
Assert.assertEquals(readFirst.getEndElapsed(), 100);
Assert.assertEquals(readNext.getEndElapsed(), 200);
Assert.assertEquals(readFirst.getExceptionId(), 2);
Assert.assertEquals(readNext.hasException(), false);
Assert.assertEquals(readFirst.getServiceType(), 1003);
Assert.assertEquals(readNext.getServiceType(), 2003);
Assert.assertEquals(readFirst.getSequence(), 0);
Assert.assertEquals(readNext.getSequence(), 1);
}
use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext in project pinpoint by naver.
the class SpanDecoderV0 method readSpanValue.
public void readSpanValue(Buffer buffer, SpanBo span, SpanEventBo firstSpanEvent, SpanDecodingContext decodingContext) {
final byte version = buffer.readByte();
if (version != 0) {
throw new IllegalStateException("unknown version :" + version);
}
span.setVersion(version);
final SpanBitFiled bitFiled = new SpanBitFiled(buffer.readByte());
final short serviceType = buffer.readShort();
span.setServiceType(serviceType);
switch(bitFiled.getApplicationServiceTypeEncodingStrategy()) {
case PREV_EQUALS:
span.setApplicationServiceType(serviceType);
break;
case RAW:
span.setApplicationServiceType(buffer.readShort());
break;
default:
throw new IllegalStateException("applicationServiceType");
}
if (!bitFiled.isRoot()) {
span.setParentSpanId(buffer.readLong());
} else {
span.setParentSpanId(-1);
}
final long startTimeDelta = buffer.readVLong();
final long startTime = span.getCollectorAcceptTime() - startTimeDelta;
span.setStartTime(startTime);
span.setElapsed(buffer.readVInt());
span.setRpc(buffer.readPrefixedString());
span.setEndPoint(buffer.readPrefixedString());
span.setRemoteAddr(buffer.readPrefixedString());
span.setApiId(buffer.readSVInt());
if (bitFiled.isSetErrorCode()) {
span.setErrCode(buffer.readInt());
}
if (bitFiled.isSetHasException()) {
int exceptionId = buffer.readSVInt();
String exceptionMessage = buffer.readPrefixedString();
span.setExceptionInfo(exceptionId, exceptionMessage);
}
if (bitFiled.isSetFlag()) {
span.setFlag(buffer.readShort());
}
if (bitFiled.isSetLoggingTransactionInfo()) {
span.setLoggingTransactionInfo(buffer.readByte());
}
span.setAcceptorHost(buffer.readPrefixedString());
if (bitFiled.isSetAnnotation()) {
List<AnnotationBo> annotationBoList = readAnnotationList(buffer, decodingContext);
span.setAnnotationBoList(annotationBoList);
}
List<SpanEventBo> spanEventBoList = readSpanEvent(buffer, firstSpanEvent, decodingContext);
span.addSpanEventBoList(spanEventBoList);
}
use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext in project pinpoint by naver.
the class SpanDecoderV0 method readFirstSpanEvent.
private SpanEventBo readFirstSpanEvent(Buffer buffer, SpanEventBo firstSpanEvent, SpanDecodingContext decodingContext) {
SpanEventBitField bitField = new SpanEventBitField(buffer.readByte());
firstSpanEvent.setStartElapsed(buffer.readVInt());
firstSpanEvent.setEndElapsed(buffer.readVInt());
firstSpanEvent.setSequence(buffer.readShort());
firstSpanEvent.setDepth(buffer.readSVInt());
firstSpanEvent.setServiceType(buffer.readShort());
if (bitField.isSetRpc()) {
firstSpanEvent.setRpc(buffer.readPrefixedString());
}
if (bitField.isSetEndPoint()) {
firstSpanEvent.setEndPoint(buffer.readPrefixedString());
}
if (bitField.isSetDestinationId()) {
firstSpanEvent.setDestinationId(buffer.readPrefixedString());
}
firstSpanEvent.setApiId(buffer.readSVInt());
if (bitField.isSetNextSpanId()) {
firstSpanEvent.setNextSpanId(buffer.readLong());
}
if (bitField.isSetHasException()) {
int exceptionId = buffer.readSVInt();
String exceptionMessage = buffer.readPrefixedString();
firstSpanEvent.setExceptionInfo(exceptionId, exceptionMessage);
}
if (bitField.isSetAnnotation()) {
List<AnnotationBo> annotationBoList = readAnnotationList(buffer, decodingContext);
firstSpanEvent.setAnnotationBoList(annotationBoList);
}
if (bitField.isSetNextAsyncId()) {
firstSpanEvent.setNextAsyncId(buffer.readSVInt());
}
// }
return firstSpanEvent;
}
Aggregations