Skip to content

Commit

Permalink
Merge pull request #2014 from emeroad/TraceV2/TraceFormatV2
Browse files Browse the repository at this point in the history
#1819 trace format v2
  • Loading branch information
emeroad authored Aug 25, 2016
2 parents b905ee4 + c5e47d1 commit 7c396bc
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void addColumn(Put put, BasicSpan basicSpan, SpanEventBo spanEventBo) {
if (!spanEventFilter.filter(spanEventBo)) {
return;
}
SpanEventEncodingContext spanEventEncodingContext = new SpanEventEncodingContext(basicSpan.getSpanId(), spanEventBo);
SpanEventEncodingContext spanEventEncodingContext = new SpanEventEncodingContext(basicSpan, spanEventBo);
this.spanEventSerializer.serialize(spanEventEncodingContext, put, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import java.util.List;

import com.navercorp.pinpoint.common.util.TransactionId;

/**
* @author emeroad
* @author jaehong.kim
Expand All @@ -30,12 +28,6 @@ public class SpanEventBo implements Event {

private byte version = 0;

private String agentId;
private String applicationId;
private long agentStartTime;

private TransactionId transactionId;

private short sequence;

private int startElapsed;
Expand Down Expand Up @@ -76,39 +68,6 @@ public void setVersion(byte version) {
this.version = version;
}

public String getAgentId() {
return agentId;
}

public void setAgentId(String agentId) {
this.agentId = agentId;
}

public String getApplicationId() {
return applicationId;
}

public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}

public long getAgentStartTime() {
return this.agentStartTime;
}

public void setAgentStartTime(long agentStartTime) {
this.agentStartTime = agentStartTime;
}

public TransactionId getTransactionId() {
return transactionId;
}

public void setTransactionId(TransactionId transactionId) {
this.transactionId = transactionId;
}


public short getSequence() {
return sequence;
}
Expand Down Expand Up @@ -263,14 +222,6 @@ public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("{version=");
builder.append(version);
builder.append(", agentId=");
builder.append(agentId);
builder.append(", applicationId=");
builder.append(applicationId);
builder.append(", agentStartTime=");
builder.append(agentStartTime);
builder.append(", transactionId=");
builder.append(transactionId);
builder.append(", sequence=");
builder.append(sequence);
builder.append(", startElapsed=");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public SpanBo buildSpanBo(TSpan tSpan) {
final SpanBo spanBo = newSpanBo(tSpan);

List<TSpanEvent> spanEventList = tSpan.getSpanEventList();
List<SpanEventBo> spanEventBoList = buildSpanEventBoList(spanBo, spanEventList);
List<SpanEventBo> spanEventBoList = buildSpanEventBoList(spanEventList);
spanBo.addSpanEventBoList(spanEventBoList);

long acceptedTime = acceptedTimeService.getAcceptedTime();
Expand Down Expand Up @@ -117,28 +117,6 @@ SpanBo newSpanBo(TSpan tSpan) {
}


// for test
SpanEventBo newSpanEventBo(BasicSpan basicSpan, TSpanEvent tSpanEvent) {
if (basicSpan == null) {
throw new NullPointerException("basicSpan must not be null");
}
if (tSpanEvent == null) {
throw new NullPointerException("tSpanEvent must not be null");
}

final SpanEventBo spanEvent = new SpanEventBo();
spanEvent.setAgentId(basicSpan.getAgentId());
spanEvent.setApplicationId(basicSpan.getApplicationId());
spanEvent.setAgentStartTime(basicSpan.getAgentStartTime());
// spanEvent.setSpanId(basicSpan.getSpanId());

TransactionId transactionId = basicSpan.getTransactionId();
spanEvent.setTransactionId(transactionId);

bind(spanEvent, tSpanEvent);
return spanEvent;
}

private void bind(SpanEventBo spanEvent, TSpanEvent tSpanEvent) {

spanEvent.setSequence(tSpanEvent.getSequence());
Expand Down Expand Up @@ -190,7 +168,7 @@ public SpanChunkBo buildSpanChunkBo(TSpanChunk tSpanChunk) {
final SpanChunkBo spanChunkBo = newSpanChunkBo(tSpanChunk);

List<TSpanEvent> spanEventList = tSpanChunk.getSpanEventList();
List<SpanEventBo> spanEventBoList = buildSpanEventBoList(spanChunkBo, spanEventList);
List<SpanEventBo> spanEventBoList = buildSpanEventBoList(spanEventList);
spanChunkBo.addSpanEventBoList(spanEventBoList);


Expand Down Expand Up @@ -233,13 +211,13 @@ private TransactionId newTransactionId(byte[] transactionIdBytes, BasicSpan basi
}


private List<SpanEventBo> buildSpanEventBoList(BasicSpan basicSpan, List<TSpanEvent> spanEventList) {
private List<SpanEventBo> buildSpanEventBoList(List<TSpanEvent> spanEventList) {
if (CollectionUtils.isEmpty(spanEventList)) {
return new ArrayList<>();
}
List<SpanEventBo> spanEventBoList = new ArrayList<>(spanEventList.size());
for (TSpanEvent tSpanEvent : spanEventList) {
final SpanEventBo spanEventBo = newSpanEventBo(basicSpan, tSpanEvent);
final SpanEventBo spanEventBo = buildSpanEventBo(tSpanEvent);
if (!spanEventFilter.filter(spanEventBo)) {
continue;
}
Expand All @@ -265,9 +243,14 @@ private List<AnnotationBo> buildAnnotationList(List<TAnnotation> tAnnotationList
}

// for test
public SpanEventBo buildSpanEventBo(TSpan tSpan, TSpanEvent tSpanEvent) {
SpanBo spanBo = newSpanBo(tSpan);
return newSpanEventBo(spanBo, tSpanEvent);
public SpanEventBo buildSpanEventBo(TSpanEvent tSpanEvent) {
if (tSpanEvent == null) {
throw new NullPointerException("tSpanEvent must not be null");
}

final SpanEventBo spanEvent = new SpanEventBo();
bind(spanEvent, tSpanEvent);
return spanEvent;
}

private AnnotationBo newAnnotationBo(TAnnotation tAnnotation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ int readSpan(SpanBo span, Buffer buffer) {
}

public SpanEventBo decodeSpanEventBo(Buffer qualifier, Buffer valueBuffer, SpanDecodingContext decodingContext) {
TransactionId transactionId = decodingContext.getTransactionId();
SpanEventBo spanEventBo = new SpanEventBo();
spanEventBo.setTransactionId(transactionId);

long spanId = qualifier.readLong();
decodingContext.setSpanId(spanId);
Expand All @@ -112,21 +110,21 @@ public SpanEventBo decodeSpanEventBo(Buffer qualifier, Buffer valueBuffer, SpanD
spanEventBo.setAsyncId(asyncId);
spanEventBo.setAsyncSequence(asyncSequence);

readSpanEvent(spanEventBo, valueBuffer);
readSpanEvent(spanEventBo, valueBuffer, decodingContext);
if (logger.isDebugEnabled()) {
logger.debug("read spanEvent :{}", spanEventBo);
}
return spanEventBo;
}

// for test
int readSpanEvent(final SpanEventBo spanEvent, Buffer buffer) {
int readSpanEvent(final SpanEventBo spanEvent, Buffer buffer, SpanDecodingContext decodingContext) {

spanEvent.setVersion(buffer.readByte());

spanEvent.setAgentId(buffer.readPrefixedString());
spanEvent.setApplicationId(buffer.readPrefixedString());
spanEvent.setAgentStartTime(buffer.readVLong());
decodingContext.setAgentId(buffer.readPrefixedString());
decodingContext.setApplicationId(buffer.readPrefixedString());
decodingContext.setAgentStartTime(buffer.readVLong());

spanEvent.setStartElapsed(buffer.readVInt());
spanEvent.setEndElapsed(buffer.readVInt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,37 @@
*/
public class SpanDecodingContext {

private String agentId;
private String applicationId;
private long agentStartTime;

private long spanId;
private long collectorAcceptedTime;
private TransactionId transactionId;

public String getAgentId() {
return agentId;
}

public void setAgentId(String agentId) {
this.agentId = agentId;
}

public String getApplicationId() {
return applicationId;
}

public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}

public long getAgentStartTime() {
return agentStartTime;
}

public void setAgentStartTime(long agentStartTime) {
this.agentStartTime = agentStartTime;
}

public long getSpanId() {
return spanId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package com.navercorp.pinpoint.common.server.bo.serializer.trace.v1;

import com.navercorp.pinpoint.common.server.bo.BasicSpan;
import com.navercorp.pinpoint.common.server.bo.SpanEventBo;

/**
* @author Woonduk Kang(emeroad)
*/
public class SpanEventEncodingContext {
private final long spanId;
private final BasicSpan basicSpan;
private final SpanEventBo spanEventBo;

public SpanEventEncodingContext(long spanId, SpanEventBo spanEventBo) {
this.spanId = spanId;
public SpanEventEncodingContext(BasicSpan basicSpan, SpanEventBo spanEventBo) {
if (basicSpan == null) {
throw new NullPointerException("basicSpan must not be null");
}
if (spanEventBo == null) {
throw new NullPointerException("spanEventBo must not be null");
}
this.basicSpan = basicSpan;
this.spanEventBo = spanEventBo;
}

public long getSpanId() {
return spanId;
public BasicSpan getBasicSpan() {
return basicSpan;
}

public SpanEventBo getSpanEventBo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.navercorp.pinpoint.common.buffer.AutomaticBuffer;
import com.navercorp.pinpoint.common.buffer.Buffer;
import com.navercorp.pinpoint.common.server.bo.AnnotationBo;
import com.navercorp.pinpoint.common.server.bo.BasicSpan;
import com.navercorp.pinpoint.common.server.bo.SpanEventBo;
import com.navercorp.pinpoint.common.server.bo.serializer.HbaseSerializer;
import com.navercorp.pinpoint.common.server.bo.serializer.SerializationContext;
Expand Down Expand Up @@ -43,8 +44,10 @@ public void serialize(SpanEventEncodingContext spanEventEncodingContext, Put put

private ByteBuffer writeQualifier(SpanEventEncodingContext spanEventEncodingContext) {
SpanEventBo spanEventBo = spanEventEncodingContext.getSpanEventBo();
BasicSpan basicSpan = spanEventEncodingContext.getBasicSpan();

final Buffer rowId = new AutomaticBuffer();
rowId.putLong(spanEventEncodingContext.getSpanId());
rowId.putLong(basicSpan.getSpanId());
rowId.putShort(spanEventBo.getSequence());
rowId.putInt(spanEventBo.getAsyncId());
rowId.putShort(spanEventBo.getAsyncSequence());
Expand All @@ -53,13 +56,15 @@ private ByteBuffer writeQualifier(SpanEventEncodingContext spanEventEncodingCont

public ByteBuffer writeValue(SpanEventEncodingContext spanEventEncodingContext) {
SpanEventBo spanEventBo = spanEventEncodingContext.getSpanEventBo();
BasicSpan basicSpan = spanEventEncodingContext.getBasicSpan();

final Buffer buffer = new AutomaticBuffer(512);

buffer.putByte(spanEventBo.getVersion());

buffer.putPrefixedString(spanEventBo.getAgentId());
buffer.putPrefixedString(spanEventBo.getApplicationId());
buffer.putVLong(spanEventBo.getAgentStartTime());
buffer.putPrefixedString(basicSpan.getAgentId());
buffer.putPrefixedString(basicSpan.getApplicationId());
buffer.putVLong(basicSpan.getAgentStartTime());

buffer.putVInt(spanEventBo.getStartElapsed());
buffer.putVInt(spanEventBo.getEndElapsed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ public void testNewSpanChunkBo_N() throws Exception {

@Test
public void testNewSpanEventBo() throws Exception {
TSpan tSpan = random.randomTSpan();
SpanBo spanBo = spanFactory.newSpanBo(tSpan);

TSpanEvent tSpanEvent = random.randomTSpanEvent((short) RandomUtils.nextInt(0, 100));
SpanEventBo spanEventBo = spanFactory.newSpanEventBo(spanBo, tSpanEvent);
SpanEventBo spanEventBo = spanFactory.buildSpanEventBo(tSpanEvent);

spanFactoryAssert.assertSpanEvent(tSpanEvent, spanEventBo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import com.navercorp.pinpoint.common.buffer.Buffer;
import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer;
import com.navercorp.pinpoint.common.server.bo.SpanBo;
import com.navercorp.pinpoint.common.server.bo.SpanEventBo;
import com.navercorp.pinpoint.common.trace.ServiceType;

import com.navercorp.pinpoint.common.util.TransactionId;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -48,9 +48,13 @@ public void setUp() throws Exception {

@Test
public void testSerialize() throws Exception {
SpanBo spanBo = new SpanBo();
spanBo.setAgentId("testAgent");
spanBo.setApplicationId("testApp");
spanBo.setAgentStartTime(1);
spanBo.setSpanId(12);

SpanEventBo spanEventBo = new SpanEventBo();
spanEventBo.setAgentId("test");
spanEventBo.setAgentStartTime(1);
spanEventBo.setDepth(3);
spanEventBo.setDestinationId("testdest");
spanEventBo.setEndElapsed(2);
Expand All @@ -63,17 +67,19 @@ public void testSerialize() throws Exception {
spanEventBo.setStartElapsed(100);
spanEventBo.setNextAsyncId(1000);

SpanEventEncodingContext spanEventEncodingContext = new SpanEventEncodingContext(12, spanEventBo);
SpanEventEncodingContext spanEventEncodingContext = new SpanEventEncodingContext(spanBo, spanEventBo);
ByteBuffer bytes = serializer.writeValue(spanEventEncodingContext);

SpanEventBo newSpanEventBo = new SpanEventBo();
SpanDecodingContext spanDecodingContext = new SpanDecodingContext();
Buffer buffer = new OffsetFixedBuffer(bytes.array(), bytes.arrayOffset(), bytes.remaining());
int i = spanDecoder.readSpanEvent(newSpanEventBo, buffer);
int i = spanDecoder.readSpanEvent(newSpanEventBo, buffer, spanDecodingContext);
Assert.assertEquals(bytes.limit(), i);


Assert.assertEquals(spanEventBo.getAgentId(), newSpanEventBo.getAgentId());
Assert.assertEquals(spanEventBo.getAgentStartTime(), newSpanEventBo.getAgentStartTime());
Assert.assertEquals(spanBo.getAgentId(), spanDecodingContext.getAgentId());
Assert.assertEquals(spanBo.getApplicationId(), spanDecodingContext.getApplicationId());
Assert.assertEquals(spanBo.getAgentStartTime(), spanDecodingContext.getAgentStartTime());
Assert.assertEquals(spanEventBo.getDepth(), newSpanEventBo.getDepth());
Assert.assertEquals(spanEventBo.getDestinationId(), newSpanEventBo.getDestinationId());
Assert.assertEquals(spanEventBo.getEndElapsed(), newSpanEventBo.getEndElapsed());
Expand All @@ -87,11 +93,6 @@ public void testSerialize() throws Exception {

Assert.assertEquals(spanEventBo.getNextAsyncId(), newSpanEventBo.getNextAsyncId());

TransactionId transactionId = new TransactionId("test", 3, 1);
spanEventBo.setTransactionId(transactionId);
newSpanEventBo.setTransactionId(transactionId);
Assert.assertEquals(spanEventBo.getTransactionId(), newSpanEventBo.getTransactionId());

spanEventBo.setSequence((short) 3);
newSpanEventBo.setSequence((short) 3);
Assert.assertEquals(spanEventBo.getSequence(), newSpanEventBo.getSequence());
Expand Down
Loading

0 comments on commit 7c396bc

Please # to comment.