-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1953 from emeroad/TraceV2/TraceFormatV2
#1819 trace format v2
- Loading branch information
Showing
4 changed files
with
341 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/RandomTSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.navercorp.pinpoint.common.server.bo; | ||
|
||
import com.navercorp.pinpoint.common.util.TransactionIdUtils; | ||
import com.navercorp.pinpoint.thrift.dto.TAnnotation; | ||
import com.navercorp.pinpoint.thrift.dto.TAnnotationValue; | ||
import com.navercorp.pinpoint.thrift.dto.TIntStringValue; | ||
import com.navercorp.pinpoint.thrift.dto.TSpan; | ||
import com.navercorp.pinpoint.thrift.dto.TSpanChunk; | ||
import com.navercorp.pinpoint.thrift.dto.TSpanEvent; | ||
import org.apache.commons.collections.CollectionUtils; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.apache.commons.lang3.RandomUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public class RandomTSpan { | ||
|
||
private final Random random = new Random(); | ||
|
||
public TSpan randomTSpan() { | ||
final TSpan tSpan = new TSpan(); | ||
tSpan.setAgentId("agentId"); | ||
tSpan.setApplicationName("appName"); | ||
tSpan.setAgentStartTime(System.currentTimeMillis()); | ||
|
||
tSpan.setTransactionId(TransactionIdUtils.formatByteBuffer("agent", System.currentTimeMillis(), RandomUtils.nextLong(0, Long.MAX_VALUE))); | ||
tSpan.setSpanId(random.nextLong()); | ||
tSpan.setParentSpanId(RandomUtils.nextInt(0, 100000)); | ||
tSpan.setStartTime(System.currentTimeMillis() + RandomUtils.nextInt(0, 1000)); | ||
tSpan.setElapsed(RandomUtils.nextInt(0, 2000)); | ||
tSpan.setRpc(RandomStringUtils.random(10)); | ||
|
||
tSpan.setServiceType(randomServerServiceType()); | ||
tSpan.setEndPoint(RandomStringUtils.random(20)); | ||
tSpan.setRemoteAddr(RandomStringUtils.random(20)); | ||
|
||
List<TAnnotation> tAnnotationList = randomTAnnotationList(); | ||
if (CollectionUtils.isNotEmpty(tAnnotationList)) { | ||
tSpan.setAnnotations(tAnnotationList); | ||
} | ||
tSpan.setFlag((short) RandomUtils.nextInt(0, 4)); | ||
tSpan.setErr((short) RandomUtils.nextInt(0, 1)); | ||
// tSpan.setSpanEventList() | ||
tSpan.setParentApplicationName("parentApp"); | ||
tSpan.setParentApplicationType(randomServerServiceType()); | ||
tSpan.setAcceptorHost("acceptHost"); | ||
tSpan.setApiId(RandomUtils.nextInt(0, 5000)); | ||
tSpan.setApplicationServiceType(randomServerServiceType()); | ||
if (random.nextBoolean()) { | ||
TIntStringValue exceptionInfo = new TIntStringValue(); | ||
exceptionInfo.setIntValue(RandomUtils.nextInt(0, 5000)); | ||
exceptionInfo.setStringValue(RandomStringUtils.random(100)); | ||
tSpan.setExceptionInfo(exceptionInfo); | ||
} | ||
tSpan.setLoggingTransactionInfo((byte) RandomUtils.nextInt(0, 256)); | ||
return tSpan; | ||
} | ||
|
||
private short randomServerServiceType() { | ||
// Server (1000 ~ 1899) | ||
return (short) RandomUtils.nextInt(1000, 1899); | ||
} | ||
|
||
public List<TAnnotation> randomTAnnotationList() { | ||
int annotationSize = RandomUtils.nextInt(0, 3); | ||
List<TAnnotation> result = new ArrayList<>(); | ||
for (int i = 0; i < annotationSize; i++) { | ||
result.add(randomTAnnotation(i)); | ||
} | ||
return result; | ||
} | ||
|
||
public TAnnotation randomTAnnotation(int key) { | ||
TAnnotation tAnnotation = new TAnnotation(); | ||
// sort order | ||
tAnnotation.setKey(key); | ||
TAnnotationValue tAnnotationValue = new TAnnotationValue(); | ||
tAnnotationValue.setStringValue(RandomStringUtils.random(10)); | ||
tAnnotation.setValue(tAnnotationValue); | ||
return tAnnotation; | ||
} | ||
|
||
public TSpanEvent randomTSpanEvent(TSpan tSpan, short sequence) { | ||
TSpanEvent tSpanEvent = new TSpanEvent(); | ||
// @deprecated | ||
// tSpanEvent.setSpanId(); | ||
tSpanEvent.setSequence(sequence); | ||
tSpanEvent.setStartElapsed(RandomUtils.nextInt(0, 1000)); | ||
tSpanEvent.setEndElapsed(RandomUtils.nextInt(0, 1000)); | ||
tSpanEvent.setRpc(RandomStringUtils.random(10)); | ||
// Database (2000 ~ 2899) | ||
tSpanEvent.setServiceType((short) RandomUtils.nextInt(2000, 2889)); | ||
tSpanEvent.setEndPoint(RandomStringUtils.random(10)); | ||
|
||
List<TAnnotation> tAnnotationList = randomTAnnotationList(); | ||
if (CollectionUtils.isNotEmpty(tAnnotationList)) { | ||
tSpan.setAnnotations(tAnnotationList); | ||
} | ||
tSpanEvent.setDepth(RandomUtils.nextInt(0, 256)); | ||
tSpanEvent.setNextSpanId(random.nextLong()); | ||
|
||
tSpanEvent.setDestinationId(RandomStringUtils.random(20)); | ||
tSpanEvent.setApiId(RandomUtils.nextInt(0, 65535)); | ||
|
||
tSpanEvent.setAsyncId(randomNegative(RandomUtils.nextInt(0, 10))); | ||
tSpanEvent.setNextAsyncId(random.nextInt()); | ||
tSpanEvent.setAsyncSequence((short) RandomUtils.nextInt(0, Short.MAX_VALUE)); | ||
|
||
return tSpanEvent; | ||
} | ||
|
||
private int randomNegative(int value) { | ||
if (random.nextBoolean()) { | ||
return -value; | ||
} | ||
return value; | ||
} | ||
|
||
public TSpanChunk randomTSpanChunk() { | ||
final TSpanChunk tSpanChunk = new TSpanChunk(); | ||
tSpanChunk.setAgentId("agentId"); | ||
tSpanChunk.setApplicationName("appName"); | ||
tSpanChunk.setAgentStartTime(System.currentTimeMillis()); | ||
|
||
tSpanChunk.setTransactionId(TransactionIdUtils.formatByteBuffer("agent", System.currentTimeMillis(), RandomUtils.nextLong(0, Long.MAX_VALUE))); | ||
tSpanChunk.setSpanId(random.nextLong()); | ||
|
||
tSpanChunk.setServiceType(randomServerServiceType()); | ||
tSpanChunk.setEndPoint(RandomStringUtils.random(20)); | ||
|
||
// tSpanChunk.setSpanEventList() | ||
tSpanChunk.setApplicationServiceType(randomServerServiceType()); | ||
return tSpanChunk; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/SpanFactoryAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.navercorp.pinpoint.common.server.bo; | ||
|
||
import com.navercorp.pinpoint.common.util.TransactionIdUtils; | ||
import com.navercorp.pinpoint.thrift.dto.TAnnotation; | ||
import com.navercorp.pinpoint.thrift.dto.TSpan; | ||
import com.navercorp.pinpoint.thrift.dto.TSpanChunk; | ||
import com.navercorp.pinpoint.thrift.dto.TSpanEvent; | ||
import org.apache.commons.collections.CollectionUtils; | ||
import org.junit.Assert; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public class SpanFactoryAssert { | ||
|
||
public void assertSpan(TSpan tSpan, SpanBo spanBo) { | ||
Assert.assertEquals(tSpan.getAgentId(), spanBo.getAgentId()); | ||
Assert.assertEquals(tSpan.getApplicationName(), spanBo.getApplicationId()); | ||
Assert.assertEquals(tSpan.getAgentStartTime(), spanBo.getAgentStartTime()); | ||
|
||
|
||
ByteBuffer byteBuffer = TransactionIdUtils.formatByteBuffer(spanBo.getTraceAgentId(), spanBo.getTraceAgentStartTime(), spanBo.getTraceTransactionSequence()); | ||
Assert.assertEquals(ByteBuffer.wrap(tSpan.getTransactionId()), byteBuffer); | ||
|
||
Assert.assertEquals(tSpan.getSpanId(), spanBo.getSpanId()); | ||
Assert.assertEquals(tSpan.getParentSpanId(), spanBo.getParentSpanId()); | ||
Assert.assertEquals(tSpan.getStartTime(), spanBo.getStartTime()); | ||
Assert.assertEquals(tSpan.getElapsed(), spanBo.getElapsed()); | ||
Assert.assertEquals(tSpan.getElapsed(), spanBo.getElapsed()); | ||
Assert.assertEquals(tSpan.getRpc(), spanBo.getRpc()); | ||
|
||
Assert.assertEquals(tSpan.getServiceType(), spanBo.getServiceType()); | ||
Assert.assertEquals(tSpan.getEndPoint(), spanBo.getEndPoint()); | ||
Assert.assertEquals(tSpan.getRemoteAddr(), spanBo.getRemoteAddr()); | ||
|
||
assertAnnotation(tSpan.getAnnotations(), spanBo.getAnnotationBoList()); | ||
|
||
Assert.assertEquals(tSpan.getFlag(), spanBo.getFlag()); | ||
Assert.assertEquals(tSpan.getErr(), spanBo.getErrCode()); | ||
|
||
Assert.assertEquals(tSpan.getParentApplicationName(), spanBo.getParentApplicationId()); | ||
Assert.assertEquals(tSpan.getParentApplicationType(), spanBo.getParentApplicationServiceType()); | ||
Assert.assertEquals(tSpan.getAcceptorHost(), spanBo.getAcceptorHost()); | ||
|
||
Assert.assertEquals(tSpan.getApiId(), spanBo.getApiId()); | ||
Assert.assertEquals(tSpan.getApplicationServiceType(), spanBo.getApplicationServiceType()); | ||
|
||
|
||
boolean hasException = tSpan.getExceptionInfo() != null; | ||
Assert.assertEquals(hasException, spanBo.hasException()); | ||
if (hasException) { | ||
Assert.assertEquals(tSpan.getExceptionInfo().getIntValue(), spanBo.getExceptionId()); | ||
Assert.assertEquals(tSpan.getExceptionInfo().getStringValue(), spanBo.getExceptionMessage()); | ||
} | ||
|
||
Assert.assertEquals(tSpan.getLoggingTransactionInfo(), spanBo.getLoggingTransactionInfo()); | ||
|
||
} | ||
|
||
public void assertAnnotation(List<TAnnotation> tAnnotationList, List<AnnotationBo> annotationBoList) { | ||
if (CollectionUtils.isEmpty(tAnnotationList) && CollectionUtils.isEmpty(annotationBoList)) { | ||
return; | ||
} | ||
Assert.assertEquals(tAnnotationList.size(), annotationBoList.size()); | ||
if (tAnnotationList.isEmpty()) { | ||
return; | ||
} | ||
|
||
|
||
for (int i = 0; i < tAnnotationList.size(); i++) { | ||
TAnnotation tAnnotation = tAnnotationList.get(i); | ||
AnnotationBo annotationBo = annotationBoList.get(i); | ||
|
||
Assert.assertEquals(tAnnotation.getKey(), annotationBo.getKey()); | ||
Assert.assertEquals(tAnnotation.getValue().getStringValue(), annotationBo.getValue()); | ||
} | ||
} | ||
|
||
public void assertSpanEvent(TSpanEvent tSpanEvent, SpanEventBo spanEventBo) { | ||
Assert.assertEquals(tSpanEvent.getSequence(), spanEventBo.getSequence()); | ||
Assert.assertEquals(tSpanEvent.getStartElapsed(), spanEventBo.getStartElapsed()); | ||
Assert.assertEquals(tSpanEvent.getEndElapsed(), spanEventBo.getEndElapsed()); | ||
|
||
Assert.assertEquals(tSpanEvent.getRpc(), spanEventBo.getRpc()); | ||
Assert.assertEquals(tSpanEvent.getServiceType(), spanEventBo.getServiceType()); | ||
Assert.assertEquals(tSpanEvent.getEndPoint(), spanEventBo.getEndPoint()); | ||
|
||
assertAnnotation(tSpanEvent.getAnnotations(), spanEventBo.getAnnotationBoList()); | ||
|
||
Assert.assertEquals(tSpanEvent.getDepth(), spanEventBo.getDepth()); | ||
Assert.assertEquals(tSpanEvent.getNextSpanId(), spanEventBo.getNextSpanId()); | ||
Assert.assertEquals(tSpanEvent.getDestinationId(), spanEventBo.getDestinationId()); | ||
|
||
Assert.assertEquals(tSpanEvent.getApiId(), spanEventBo.getApiId()); | ||
|
||
boolean hasException = tSpanEvent.getExceptionInfo() != null; | ||
Assert.assertEquals(hasException, spanEventBo.hasException()); | ||
if (hasException) { | ||
Assert.assertEquals(tSpanEvent.getExceptionInfo().getIntValue(), spanEventBo.getExceptionId()); | ||
Assert.assertEquals(tSpanEvent.getExceptionInfo().getStringValue(), spanEventBo.getExceptionMessage()); | ||
} | ||
|
||
Assert.assertEquals(tSpanEvent.getAsyncId(), spanEventBo.getAsyncId()); | ||
Assert.assertEquals(tSpanEvent.getNextAsyncId(), spanEventBo.getNextAsyncId()); | ||
Assert.assertEquals(tSpanEvent.getAsyncSequence(), spanEventBo.getAsyncSequence()); | ||
} | ||
|
||
|
||
public void assertSpanChunk(TSpanChunk tSpanChunk, SpanChunkBo spanChunkBo) { | ||
Assert.assertEquals(tSpanChunk.getAgentId(), spanChunkBo.getAgentId()); | ||
Assert.assertEquals(tSpanChunk.getApplicationName(), spanChunkBo.getApplicationId()); | ||
Assert.assertEquals(tSpanChunk.getAgentStartTime(), spanChunkBo.getAgentStartTime()); | ||
|
||
|
||
ByteBuffer byteBuffer = TransactionIdUtils.formatByteBuffer(spanChunkBo.getTraceAgentId(), spanChunkBo.getTraceAgentStartTime(), spanChunkBo.getTraceTransactionSequence()); | ||
Assert.assertEquals(ByteBuffer.wrap(tSpanChunk.getTransactionId()), byteBuffer); | ||
|
||
Assert.assertEquals(tSpanChunk.getSpanId(), spanChunkBo.getSpanId()); | ||
|
||
Assert.assertEquals(tSpanChunk.getServiceType(), spanChunkBo.getServiceType()); | ||
Assert.assertEquals(tSpanChunk.getEndPoint(), spanChunkBo.getEndPoint()); | ||
Assert.assertEquals(tSpanChunk.getApplicationServiceType(), spanChunkBo.getApplicationServiceType()); | ||
|
||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/SpanFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.navercorp.pinpoint.common.server.bo; | ||
|
||
import com.navercorp.pinpoint.thrift.dto.TSpan; | ||
import com.navercorp.pinpoint.thrift.dto.TSpanChunk; | ||
import com.navercorp.pinpoint.thrift.dto.TSpanEvent; | ||
import org.apache.commons.lang3.RandomUtils; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public class SpanFactoryTest { | ||
|
||
private final SpanFactory spanFactory = new SpanFactory(); | ||
|
||
private SpanFactoryAssert spanFactoryAssert = new SpanFactoryAssert(); | ||
|
||
private RandomTSpan random = new RandomTSpan(); | ||
|
||
|
||
@Test | ||
public void buildSpanBo() throws Exception { | ||
TSpan tSpan = random.randomTSpan(); | ||
|
||
SpanBo spanBo = spanFactory.newSpanBo(tSpan); | ||
|
||
spanFactoryAssert.assertSpan(tSpan, spanBo); | ||
} | ||
|
||
|
||
@Test | ||
public void buildSpanChunkBo() throws Exception { | ||
TSpanChunk tSpanChunk = random.randomTSpanChunk(); | ||
|
||
SpanChunkBo spanChunkBo = spanFactory.newSpanChunkBo(tSpanChunk); | ||
|
||
spanFactoryAssert.assertSpanChunk(tSpanChunk, spanChunkBo); | ||
|
||
} | ||
|
||
@Test | ||
public void newSpanEventBo() throws Exception { | ||
TSpan tSpan = random.randomTSpan(); | ||
SpanBo spanBo = spanFactory.newSpanBo(tSpan); | ||
|
||
TSpanEvent tSpanEvent = random.randomTSpanEvent(tSpan, (short) RandomUtils.nextInt(0, 100)); | ||
SpanEventBo spanEventBo = spanFactory.newSpanEventBo(spanBo, tSpanEvent); | ||
|
||
spanFactoryAssert.assertSpanEvent(tSpanEvent, spanEventBo); | ||
|
||
} | ||
|
||
} |