Search in sources :

Example 21 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo 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(Collections.singletonList(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, 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 22 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo in project pinpoint by naver.

the class SpanServiceImpl method transitionCachedString.

private void transitionCachedString(List<SpanAlign> spans) {
    this.transitionAnnotation(spans, new AnnotationReplacementCallback() {

        @Override
        public void replacement(SpanAlign spanAlign, List<AnnotationBo> annotationBoList) {
            List<AnnotationBo> cachedStringAnnotation = findCachedStringAnnotation(annotationBoList);
            if (cachedStringAnnotation.isEmpty()) {
                return;
            }
            for (AnnotationBo annotationBo : cachedStringAnnotation) {
                final int cachedArgsKey = annotationBo.getKey();
                int stringMetaDataId = (Integer) annotationBo.getValue();
                List<StringMetaDataBo> stringMetaList = stringMetaDataDao.getStringMetaData(spanAlign.getAgentId(), spanAlign.getAgentStartTime(), stringMetaDataId);
                int size = stringMetaList.size();
                if (size == 0) {
                    logger.warn("StringMetaData not Found {}/{}/{}", spanAlign.getAgentId(), stringMetaDataId, spanAlign.getAgentStartTime());
                    AnnotationBo api = new AnnotationBo();
                    api.setKey(AnnotationKey.ERROR_API_METADATA_NOT_FOUND.getCode());
                    api.setValue("CACHED-STRING-ID not found. stringId:" + cachedArgsKey);
                    annotationBoList.add(api);
                } else if (size >= 1) {
                    // key collision shouldn't really happen (probability too low)
                    StringMetaDataBo stringMetaDataBo = stringMetaList.get(0);
                    AnnotationBo stringMetaData = new AnnotationBo();
                    stringMetaData.setKey(AnnotationKeyUtils.cachedArgsToArgs(cachedArgsKey));
                    stringMetaData.setValue(stringMetaDataBo.getStringValue());
                    annotationBoList.add(stringMetaData);
                    if (size > 1) {
                        logger.warn("stringMetaData size not 1 :{}", stringMetaList);
                    }
                }
            }
        }
    });
}
Also used : SpanAlign(com.navercorp.pinpoint.web.calltree.span.SpanAlign) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) ArrayList(java.util.ArrayList) List(java.util.List) StringMetaDataBo(com.navercorp.pinpoint.common.server.bo.StringMetaDataBo)

Example 23 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo in project pinpoint by naver.

the class SpanServiceImpl method transitionDynamicApiId.

private void transitionDynamicApiId(List<SpanAlign> spans) {
    this.transitionAnnotation(spans, new AnnotationReplacementCallback() {

        @Override
        public void replacement(SpanAlign spanAlign, List<AnnotationBo> annotationBoList) {
            final int apiId = spanAlign.getApiId();
            if (apiId == 0) {
                String apiString = AnnotationUtils.findApiAnnotation(annotationBoList);
                // annotation base api
                if (apiString != null) {
                    ApiMetaDataBo apiMetaDataBo = new ApiMetaDataBo(spanAlign.getAgentId(), spanAlign.getStartTime(), apiId);
                    apiMetaDataBo.setApiInfo(apiString);
                    apiMetaDataBo.setLineNumber(-1);
                    apiMetaDataBo.setMethodTypeEnum(MethodTypeEnum.DEFAULT);
                    AnnotationBo apiAnnotation = new AnnotationBo();
                    apiAnnotation.setKey(AnnotationKey.API_METADATA.getCode());
                    apiAnnotation.setValue(apiMetaDataBo);
                    annotationBoList.add(apiAnnotation);
                    return;
                }
            }
            // may be able to get a more accurate data using agentIdentifier.
            List<ApiMetaDataBo> apiMetaDataList = apiMetaDataDao.getApiMetaData(spanAlign.getAgentId(), spanAlign.getAgentStartTime(), apiId);
            int size = apiMetaDataList.size();
            if (size == 0) {
                AnnotationBo api = new AnnotationBo();
                api.setKey(AnnotationKey.ERROR_API_METADATA_NOT_FOUND.getCode());
                api.setValue("API-DynamicID not found. api:" + apiId);
                annotationBoList.add(api);
            } else if (size == 1) {
                ApiMetaDataBo apiMetaDataBo = apiMetaDataList.get(0);
                AnnotationBo apiMetaData = new AnnotationBo();
                apiMetaData.setKey(AnnotationKey.API_METADATA.getCode());
                apiMetaData.setValue(apiMetaDataBo);
                annotationBoList.add(apiMetaData);
                if (apiMetaDataBo.getMethodTypeEnum() == MethodTypeEnum.DEFAULT) {
                    AnnotationBo apiAnnotation = new AnnotationBo();
                    apiAnnotation.setKey(AnnotationKey.API.getCode());
                    String apiInfo = getApiInfo(apiMetaDataBo);
                    apiAnnotation.setValue(apiInfo);
                    annotationBoList.add(apiAnnotation);
                } else {
                    AnnotationBo apiAnnotation = new AnnotationBo();
                    apiAnnotation.setKey(AnnotationKey.API_TAG.getCode());
                    apiAnnotation.setValue(getApiTagInfo(apiMetaDataBo));
                    annotationBoList.add(apiAnnotation);
                }
            } else {
                AnnotationBo apiAnnotation = new AnnotationBo();
                apiAnnotation.setKey(AnnotationKey.ERROR_API_METADATA_DID_COLLSION.getCode());
                String collisionMessage = collisionApiDidMessage(apiId, apiMetaDataList);
                apiAnnotation.setValue(collisionMessage);
                annotationBoList.add(apiAnnotation);
            }
        }
    });
}
Also used : SpanAlign(com.navercorp.pinpoint.web.calltree.span.SpanAlign) AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) ApiMetaDataBo(com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo in project pinpoint by naver.

the class SpanMapperV2Test method newAnnotation.

private AnnotationBo newAnnotation(int key, Object value) {
    AnnotationBo annotationBo = new AnnotationBo();
    annotationBo.setKey(key);
    annotationBo.setValue(value);
    return annotationBo;
}
Also used : AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo)

Example 25 with AnnotationBo

use of com.navercorp.pinpoint.common.server.bo.AnnotationBo in project pinpoint by naver.

the class AnnotationBoDecoder method decodeAnnotation.

private AnnotationBo decodeAnnotation(Buffer buffer) {
    final AnnotationBo annotation = new AnnotationBo();
    final byte version = buffer.readByte();
    if (version != VERSION) {
        throw new IllegalStateException("unknown version:" + version);
    }
    annotation.setKey(buffer.readSVInt());
    byte valueType = buffer.readByte();
    byte[] byteValue = buffer.readPrefixedBytes();
    Object decodeObject = transcoder.decode(valueType, byteValue);
    annotation.setValue(decodeObject);
    return annotation;
}
Also used : AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo)

Aggregations

AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)55 ArrayList (java.util.ArrayList)17 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)14 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)13 ApiMetaDataBo (com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo)7 Test (org.junit.Test)7 List (java.util.List)6 Buffer (com.navercorp.pinpoint.common.buffer.Buffer)5 TransactionId (com.navercorp.pinpoint.common.profiler.util.TransactionId)5 SpanEventBitField (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanEventBitField)5 AnnotationKey (com.navercorp.pinpoint.common.trace.AnnotationKey)5 Align (com.navercorp.pinpoint.web.calltree.span.Align)4 SpanAlign (com.navercorp.pinpoint.web.calltree.span.SpanAlign)4 ByteBuffer (java.nio.ByteBuffer)4 AutomaticBuffer (com.navercorp.pinpoint.common.buffer.AutomaticBuffer)3 SpanBitFiled (com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanBitFiled)3 ServiceType (com.navercorp.pinpoint.common.trace.ServiceType)3 OffsetFixedBuffer (com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer)2 SqlMetaDataBo (com.navercorp.pinpoint.common.server.bo.SqlMetaDataBo)2 StringMetaDataBo (com.navercorp.pinpoint.common.server.bo.StringMetaDataBo)2