Search in sources :

Example 1 with SpanEncodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext 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);
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) ByteBuffer(java.nio.ByteBuffer) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) SpanEncodingContext(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext) SpanDecodingContext(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext) SpanEncoder(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoder) OffsetFixedBuffer(com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer) SpanEncoderV0(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoderV0) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) ByteBuffer(java.nio.ByteBuffer) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo) Test(org.junit.Test)

Example 2 with SpanEncodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext in project pinpoint by naver.

the class SpanEncoderV0 method encodeSpanColumnValue.

@Override
public ByteBuffer encodeSpanColumnValue(SpanEncodingContext<SpanBo> encodingContext) {
    final SpanBo span = encodingContext.getValue();
    final SpanBitFiled bitField = SpanBitFiled.build(span);
    final Buffer buffer = new AutomaticBuffer(256);
    final byte version = span.getRawVersion();
    buffer.putByte(version);
    // bit field
    buffer.putByte(bitField.getBitField());
    final short serviceType = span.getServiceType();
    buffer.putShort(serviceType);
    switch(bitField.getApplicationServiceTypeEncodingStrategy()) {
        case PREV_EQUALS:
            break;
        case RAW:
            buffer.putShort(span.getApplicationServiceType());
            break;
        default:
            throw new IllegalStateException("applicationServiceType");
    }
    // buffer.put(spanID);
    if (!bitField.isRoot()) {
        buffer.putLong(span.getParentSpanId());
    }
    // prevSpanEvent coding
    final long startTime = span.getStartTime();
    final long startTimeDelta = span.getCollectorAcceptTime() - startTime;
    buffer.putVLong(startTimeDelta);
    buffer.putVInt(span.getElapsed());
    buffer.putPrefixedString(span.getRpc());
    buffer.putPrefixedString(span.getEndPoint());
    buffer.putPrefixedString(span.getRemoteAddr());
    buffer.putSVInt(span.getApiId());
    // BIT flag
    if (bitField.isSetErrorCode()) {
        buffer.putInt(span.getErrCode());
    }
    if (bitField.isSetHasException()) {
        buffer.putSVInt(span.getExceptionId());
        buffer.putPrefixedString(span.getExceptionMessage());
    }
    if (bitField.isSetFlag()) {
        buffer.putShort(span.getFlag());
    }
    if (bitField.isSetLoggingTransactionInfo()) {
        buffer.putByte(span.getLoggingTransactionInfo());
    }
    buffer.putPrefixedString(span.getAcceptorHost());
    if (bitField.isSetAnnotation()) {
        List<AnnotationBo> annotationBoList = span.getAnnotationBoList();
        writeAnnotationList(buffer, annotationBoList, encodingContext);
    }
    final List<SpanEventBo> spanEventBoList = span.getSpanEventBoList();
    writeSpanEventList(buffer, spanEventBoList, encodingContext);
    return buffer.wrapByteBuffer();
}
Also used : Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) ByteBuffer(java.nio.ByteBuffer) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) AutomaticBuffer(com.navercorp.pinpoint.common.buffer.AutomaticBuffer) SpanBitFiled(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanBitFiled) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo)

Example 3 with SpanEncodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext in project pinpoint by naver.

the class SpanEncoderV0 method writeFirstSpanEvent.

public void writeFirstSpanEvent(Buffer buffer, SpanEventBo spanEventBo, SpanEncodingContext<?> encodingContext) {
    final SpanEventBitField bitField = SpanEventBitField.buildFirst(spanEventBo);
    final byte firstSpanBitField1 = (byte) bitField.getBitField();
    buffer.putByte(firstSpanBitField1);
    buffer.putVInt(spanEventBo.getStartElapsed());
    buffer.putVInt(spanEventBo.getEndElapsed());
    buffer.putShort(spanEventBo.getSequence());
    buffer.putSVInt(spanEventBo.getDepth());
    buffer.putShort(spanEventBo.getServiceType());
    if (bitField.isSetRpc()) {
        buffer.putPrefixedString(spanEventBo.getRpc());
    }
    if (bitField.isSetEndPoint()) {
        buffer.putPrefixedString(spanEventBo.getEndPoint());
    }
    if (bitField.isSetDestinationId()) {
        buffer.putPrefixedString(spanEventBo.getDestinationId());
    }
    buffer.putSVInt(spanEventBo.getApiId());
    if (bitField.isSetNextSpanId()) {
        buffer.putLong(spanEventBo.getNextSpanId());
    }
    if (bitField.isSetHasException()) {
        buffer.putSVInt(spanEventBo.getExceptionId());
        buffer.putPrefixedString(spanEventBo.getExceptionMessage());
    }
    if (bitField.isSetAnnotation()) {
        final List<AnnotationBo> annotationBoList = spanEventBo.getAnnotationBoList();
        writeAnnotationList(buffer, annotationBoList, encodingContext);
    }
    if (bitField.isSetNextAsyncId()) {
        buffer.putSVInt(spanEventBo.getNextAsyncId());
    }
//        if (bitField.isSetAsyncId()) {
//            buffer.putInt(spanEventBo.getAsyncId());
//            buffer.putVInt(spanEventBo.getAsyncSequence());
//        }
}
Also used : SpanEventBitField(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanEventBitField) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo)

Example 4 with SpanEncodingContext

use of com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext in project pinpoint by naver.

the class SpanEncoderV0 method writeNextSpanEvent.

public void writeNextSpanEvent(Buffer buffer, SpanEventBo spanEventBo, SpanEventBo prevSpanEvent, SpanEncodingContext<?> encodingContext) {
    final SpanEventBitField bitField = SpanEventBitField.build(spanEventBo, prevSpanEvent);
    buffer.putShort(bitField.getBitField());
    switch(bitField.getStartElapsedEncodingStrategy()) {
        case PREV_DELTA:
            final int startTimeDelta = spanEventBo.getStartElapsed() - prevSpanEvent.getStartElapsed();
            buffer.putVInt(startTimeDelta);
            break;
        case PREV_EQUALS:
            // skip bitfield
            break;
        default:
            throw new IllegalStateException("unsupported StartElapsedEncodingStrategy");
    }
    buffer.putVInt(spanEventBo.getEndElapsed());
    switch(bitField.getSequenceEncodingStrategy()) {
        case PREV_DELTA:
            final int sequenceDelta = spanEventBo.getSequence() - prevSpanEvent.getSequence();
            buffer.putVInt(sequenceDelta);
            break;
        case PREV_ADD1:
            // skip bitfield
            break;
        default:
            throw new IllegalStateException("unsupported SequenceEncodingStrategy");
    }
    switch(bitField.getDepthEncodingStrategy()) {
        case RAW:
            buffer.putSVInt(spanEventBo.getDepth());
            break;
        case PREV_EQUALS:
            // skip bitfield
            break;
        default:
            throw new IllegalStateException("unsupported DepthEncodingStrategy");
    }
    switch(bitField.getServiceTypeEncodingStrategy()) {
        case RAW:
            buffer.putShort(spanEventBo.getServiceType());
            break;
        case PREV_EQUALS:
            // skip bitfield
            break;
        default:
            throw new IllegalStateException("unsupported ServiceTypeEncodingStrategy");
    }
    buffer.putSVInt(spanEventBo.getApiId());
    if (bitField.isSetRpc()) {
        buffer.putPrefixedString(spanEventBo.getRpc());
    }
    if (bitField.isSetEndPoint()) {
        buffer.putPrefixedString(spanEventBo.getEndPoint());
    }
    if (bitField.isSetDestinationId()) {
        buffer.putPrefixedString(spanEventBo.getDestinationId());
    }
    if (bitField.isSetNextSpanId()) {
        buffer.putLong(spanEventBo.getNextSpanId());
    }
    if (bitField.isSetHasException()) {
        buffer.putSVInt(spanEventBo.getExceptionId());
        buffer.putPrefixedString(spanEventBo.getExceptionMessage());
    }
    if (bitField.isSetAnnotation()) {
        List<AnnotationBo> annotationBoList = spanEventBo.getAnnotationBoList();
        writeAnnotationList(buffer, annotationBoList, encodingContext);
    }
    if (bitField.isSetNextAsyncId()) {
        buffer.putSVInt(spanEventBo.getNextAsyncId());
    }
    if (bitField.isSetAsyncId()) {
        buffer.putInt(spanEventBo.getAsyncId());
        buffer.putVInt(spanEventBo.getAsyncSequence());
    }
}
Also used : SpanEventBitField(com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanEventBitField) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo)

Aggregations

AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)4 Buffer (com.navercorp.pinpoint.common.buffer.Buffer)2 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)2 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)2 SpanEventBitField (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanEventBitField)2 ByteBuffer (java.nio.ByteBuffer)2 AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)1 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)1 SpanDecodingContext (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanDecodingContext)1 SpanEncoder (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoder)1 SpanEncoderV0 (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncoderV0)1 SpanEncodingContext (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.SpanEncodingContext)1 SpanBitFiled (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanBitFiled)1 Test (org.junit.Test)1