diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/AnnotationBo.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/AnnotationBo.java index 7de049a7a4bd..50be9f904b4a 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/AnnotationBo.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/AnnotationBo.java @@ -16,44 +16,19 @@ package com.navercorp.pinpoint.common.server.bo; -import com.navercorp.pinpoint.common.util.AnnotationTranscoder; - /** * @author emeroad */ public class AnnotationBo { - @Deprecated - private static final AnnotationTranscoder transcoder = new AnnotationTranscoder(); - - private byte version = 0; - private int key; - - private byte valueType; - private byte[] byteValue; private Object value; + private boolean isAuthorized = true; public AnnotationBo() { } - public int getVersion() { - return version & 0xFF; - } - - public byte getRawVersion() { - return version; - } - - public void setVersion(int version) { - if (version < 0 || version > 255) { - throw new IllegalArgumentException("out of range (0~255) " + version); - } - // check range - this.version = (byte) (version & 0xFF); - } - public int getKey() { return key; } @@ -64,26 +39,6 @@ public void setKey(int key) { } - public int getValueType() { - return valueType; - } - - public byte getRawValueType() { - return valueType; - } - - public void setValueType(byte valueType) { - this.valueType = valueType; - } - - public byte[] getByteValue() { - return byteValue; - } - - public void setByteValue(byte[] byteValue) { - this.byteValue = byteValue; - } - public Object getValue() { return value; } @@ -103,10 +58,10 @@ public void setAuthorized(boolean isAuthorized) { @Override public String toString() { - if (value == null) { - return "AnnotationBo{" + "version=" + version + ", key='" + key + '\'' + ", valueType=" + valueType + '}'; - } - return "AnnotationBo{" + "version=" + version + ", key='" + key + '\'' + ", value=" + value + '}'; + return "AnnotationBo{" + + "key=" + key + + ", value=" + value + + ", isAuthorized=" + isAuthorized + + '}'; } - } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanFactory.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanFactory.java index b141f297968f..01280481591b 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanFactory.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SpanFactory.java @@ -279,12 +279,7 @@ private AnnotationBo newAnnotationBo(TAnnotation tAnnotation) { annotationBo.setKey(tAnnotation.getKey()); Object value = transcoder.getMappingValue(tAnnotation); - byte typeCode = transcoder.getTypeCode(value); - byte[] encodeObject = transcoder.encode(value, typeCode); - annotationBo.setValue(value); - annotationBo.setValueType(typeCode); - annotationBo.setByteValue(encodeObject); return annotationBo; } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationBoDecoder.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationBoDecoder.java index d507688d94f9..bd6244c1be92 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationBoDecoder.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationBoDecoder.java @@ -13,6 +13,7 @@ public class AnnotationBoDecoder { private final AnnotationTranscoder transcoder = new AnnotationTranscoder(); + private static final byte VERSION = AnnotationSerializer.VERSION; public List decode(Buffer qualifier, Buffer valueBuffer, SpanDecodingContext decodingContext) { @@ -48,14 +49,14 @@ private AnnotationBo decodeAnnotation(Buffer buffer) { final AnnotationBo annotation = new AnnotationBo(); - annotation.setVersion(buffer.readByte()); + final byte version = buffer.readByte(); + if (version != VERSION) { + throw new IllegalStateException("unknown version:" + version); + } annotation.setKey(buffer.readSVInt()); byte valueType = buffer.readByte(); - annotation.setValueType(valueType); - byte[] byteValue = buffer.readPrefixedBytes(); - annotation.setByteValue(byteValue); Object decodeObject = transcoder.decode(valueType, byteValue); annotation.setValue(decodeObject); diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationSerializer.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationSerializer.java index fdc67a7890a6..76a97315f673 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationSerializer.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationSerializer.java @@ -6,6 +6,7 @@ import com.navercorp.pinpoint.common.server.bo.SpanBo; import com.navercorp.pinpoint.common.server.bo.serializer.HbaseSerializer; import com.navercorp.pinpoint.common.server.bo.serializer.SerializationContext; +import com.navercorp.pinpoint.common.util.AnnotationTranscoder; import org.apache.commons.collections.CollectionUtils; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.util.Bytes; @@ -23,6 +24,8 @@ @Component public class AnnotationSerializer implements HbaseSerializer { + private static final AnnotationTranscoder transcoder = new AnnotationTranscoder(); + public static final byte VERSION = 0; @Override public void serialize(SpanBo spanBo, Put put, SerializationContext context) { @@ -63,12 +66,16 @@ public ByteBuffer writeAnnotationList(List annotationList, Buffer // for test public void writeAnnotation(AnnotationBo annotationBo, Buffer puffer) { - // int key; // required 4 - // int valueTypeCode; // required 4 - // ByteBuffer value; // optional 4 + buf.length - puffer.putByte(annotationBo.getRawVersion()); + + puffer.putByte(VERSION); puffer.putSVInt(annotationBo.getKey()); - puffer.putByte(annotationBo.getRawValueType()); - puffer.putPrefixedBytes(annotationBo.getByteValue()); + + Object value = annotationBo.getValue(); + + byte typeCode = transcoder.getTypeCode(value); + byte[] bytes = transcoder.encode(value, typeCode); + + puffer.putByte(typeCode); + puffer.putPrefixedBytes(bytes); } } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanDecoderV0.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanDecoderV0.java index 3b459efb9860..d5e7df9846cc 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanDecoderV0.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanDecoderV0.java @@ -358,7 +358,6 @@ private AnnotationBo readFirstAnnotationBo(Buffer buffer) { byte[] valueBytes = buffer.readPrefixedBytes(); Object value = transcoder.decode(valueType, valueBytes); - current.setValueType(valueType); current.setValue(value); return current; } @@ -373,7 +372,7 @@ private AnnotationBo readDeltaAnnotationBo(Buffer buffer, AnnotationBo prev) { byte valueType = buffer.readByte(); byte[] valueBytes = buffer.readPrefixedBytes(); Object value = transcoder.decode(valueType, valueBytes); - annotation.setValueType(valueType); + annotation.setValue(value); return annotation; } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderV0.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderV0.java index 05bd0a5e7813..163660abad4d 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderV0.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderV0.java @@ -9,6 +9,7 @@ import com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanBitFiled; import com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanEventBitField; import com.navercorp.pinpoint.common.server.bo.serializer.trace.v2.bitfield.SpanEventQualifierBitField; +import com.navercorp.pinpoint.common.util.AnnotationTranscoder; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; @@ -21,6 +22,8 @@ @Component public class SpanEncoderV0 implements SpanEncoder { + private static final AnnotationTranscoder transcoder = new AnnotationTranscoder(); + @Override public ByteBuffer encodeSpanQualifier(SpanEncodingContext encodingContext) { final SpanBo spanBo = encodingContext.getValue(); @@ -353,8 +356,13 @@ private void writeAnnotationList(Buffer buffer, List annotationBoL // first annotation buffer.putSVInt(current.getKey()); - buffer.putByte(current.getRawValueType()); - buffer.putPrefixedBytes(current.getByteValue()); + + Object value = current.getValue(); + byte valueTypeCode = transcoder.getTypeCode(value); + byte[] valueBytes = transcoder.encode(value, valueTypeCode); + + buffer.putByte(valueTypeCode); + buffer.putPrefixedBytes(valueBytes); // else { // writeDeltaAnnotationBo(buffer, prev, current); // } @@ -374,8 +382,13 @@ private void writeDeltaAnnotationBo(Buffer buffer, AnnotationBo prev, Annotation final int prevKey = prev.getKey(); final int currentKey = current.getKey(); buffer.putSVInt(currentKey - prevKey); - buffer.putByte(current.getRawValueType()); - buffer.putPrefixedBytes(current.getByteValue()); + + Object value = current.getValue(); + byte valueTypeCode = transcoder.getTypeCode(value); + byte[] valueBytes = transcoder.encode(value, valueTypeCode); + + buffer.putByte(valueTypeCode); + buffer.putPrefixedBytes(valueBytes); } diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationBoDecoderTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationBoDecoderTest.java index 2d6871904b14..9c66c7fb7b1c 100644 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationBoDecoderTest.java +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v1/AnnotationBoDecoderTest.java @@ -37,8 +37,6 @@ */ public class AnnotationBoDecoderTest { - private static final Charset UTF_8 = Charset.forName("UTF-8"); - private AnnotationSerializer serializer = new AnnotationSerializer(); private AnnotationBoDecoder annotationBoDecoder = new AnnotationBoDecoder(); @@ -52,7 +50,7 @@ public void testWriteValue() throws Exception { annotation.setKey(AnnotationKey.API.getCode()); final String value = RandomStringUtils.random(RandomUtils.nextInt(20)); - annotation.setByteValue(value.getBytes(UTF_8)); + annotation.setValue(value); final Buffer buffer = new AutomaticBuffer(128); this.serializer.writeAnnotationList(Lists.newArrayList(annotation), buffer); @@ -62,8 +60,7 @@ public void testWriteValue() throws Exception { Assert.assertEquals(decode.size(), 1); AnnotationBo decodedAnnotation = decode.get(0); Assert.assertEquals(annotation.getKey(), decodedAnnotation.getKey()); - Assert.assertEquals(annotation.getValueType(), decodedAnnotation.getValueType()); - Assert.assertArrayEquals(annotation.getByteValue(), decodedAnnotation.getByteValue()); + Assert.assertEquals(annotation.getValue(), decodedAnnotation.getValue()); } diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderTest.java index c2ed8499e045..065f23e7a271 100644 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderTest.java +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/trace/v2/SpanEncoderTest.java @@ -54,10 +54,12 @@ public void encodeSpanColumnValue() throws Exception { logger.debug("span dump \noriginal spanBo:{} \ndecode spanBo:{} ", spanBo, decode); - // TODO check annotationBoList List excludeField = Lists.newArrayList("parentApplicationId", "parentApplicationServiceType", "annotationBoList"); Assert.assertTrue(EqualsBuilder.reflectionEquals(decode, spanBo, excludeField)); + logger.debug("{} {}", spanBo.getAnnotationBoList(), decode.getAnnotationBoList()); + Assert.assertTrue("annotation", EqualsBuilder.reflectionEquals(spanBo.getAnnotationBoList(), decode.getAnnotationBoList())); + } private long getCollectorAcceptTime() { diff --git a/web/src/test/java/com/navercorp/pinpoint/web/mapper/SpanMapperV2Test.java b/web/src/test/java/com/navercorp/pinpoint/web/mapper/SpanMapperV2Test.java index 50dc8d8497ad..0c36dd8fffcc 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/mapper/SpanMapperV2Test.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/mapper/SpanMapperV2Test.java @@ -26,7 +26,6 @@ public class SpanMapperV2Test { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private final AnnotationTranscoder transcoder = new AnnotationTranscoder(); private final SpanDecoderV0 decoder = new SpanDecoderV0(); @Test @@ -96,11 +95,7 @@ public void test() { private AnnotationBo newAnnotation(int key, Object value) { AnnotationBo annotationBo = new AnnotationBo(); annotationBo.setKey(key); - - byte typeCode = transcoder.getTypeCode(value); - byte[] encode = transcoder.encode(value, typeCode); annotationBo.setValue(value); - annotationBo.setByteValue(encode); return annotationBo; }