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