use of com.navercorp.pinpoint.common.server.bo.SpanEventBo in project pinpoint by naver.
the class CallTreeTest method makeSpanAlign.
private Align makeSpanAlign(SpanBo span, final boolean async, final short sequence, int nextAsyncId, final int asyncId, int startElapsed, int endElapsed) {
SpanEventBo event = new SpanEventBo();
event.setAsyncId(async ? 1 : -1);
event.setSequence(sequence);
event.setNextAsyncId(nextAsyncId);
event.setAsyncId(asyncId);
event.setStartElapsed(startElapsed);
event.setEndElapsed(endElapsed);
return new SpanEventAlign(span, event);
}
use of com.navercorp.pinpoint.common.server.bo.SpanEventBo in project pinpoint by naver.
the class FilteredMapServiceImplTest method twoTier.
/**
* USER -> ROOT_APP -> APP_A -> CACHE
*/
@Test
public void twoTier() {
// Given
Range originalRange = Range.newRange(1000, 2000);
Range scanRange = Range.newRange(1000, 2000);
final TimeWindow timeWindow = new TimeWindow(originalRange, TimeWindowDownSampler.SAMPLER);
// root app span
long rootSpanId = RANDOM.nextLong();
long rootSpanStartTime = 1000L;
long rootSpanCollectorAcceptTime = 1210L;
int rootSpanElapsed = 200;
SpanBo rootSpan = new TestTraceUtils.SpanBuilder("ROOT_APP", "root-agent").spanId(rootSpanId).startTime(rootSpanStartTime).collectorAcceptTime(rootSpanCollectorAcceptTime).elapsed(rootSpanElapsed).build();
// app A span
long appASpanId = RANDOM.nextLong();
long appASpanStartTime = 1020L;
long appASpanCollectorAcceptTime = 1090L;
int appASpanElapsed = 160;
SpanBo appASpan = new TestTraceUtils.SpanBuilder("APP_A", "app-a").spanId(appASpanId).parentSpan(rootSpan).startTime(appASpanStartTime).collectorAcceptTime(appASpanCollectorAcceptTime).elapsed(appASpanElapsed).build();
// root app -> app A rpc span event
SpanEventBo rootRpcSpanEvent = new TestTraceUtils.RpcSpanEventBuilder("www.foo.com/bar", 10, 190).nextSpanId(appASpanId).build();
rootSpan.addSpanEvent(rootRpcSpanEvent);
// app A -> cache span event
int cacheStartElapsed = 20;
int cacheEndElapsed = 130;
SpanEventBo appACacheSpanEvent = new TestTraceUtils.CacheSpanEventBuilder("CacheName", "1.1.1.1", cacheStartElapsed, cacheEndElapsed).build();
appASpan.addSpanEvent(appACacheSpanEvent);
when(traceDao.selectAllSpans(anyList(), isNull())).thenReturn(Collections.singletonList(Arrays.asList(rootSpan, appASpan)));
// When
final FilteredMapServiceOption option = new FilteredMapServiceOption.Builder(Collections.emptyList(), originalRange, scanRange, 1, 1, Filter.acceptAllFilter(), 0).build();
ApplicationMap applicationMap = filteredMapService.selectApplicationMapWithScatterData(option);
// Then
Collection<Node> nodes = applicationMap.getNodes();
Assert.assertEquals(4, nodes.size());
for (Node node : nodes) {
Application application = node.getApplication();
if (application.getName().equals("ROOT_APP") && application.getServiceType().getCode() == TestTraceUtils.USER_TYPE_CODE) {
// USER node
NodeHistogram nodeHistogram = node.getNodeHistogram();
// histogram
Histogram applicationHistogram = nodeHistogram.getApplicationHistogram();
assertHistogram(applicationHistogram, 1, 0, 0, 0, 0);
Map<String, Histogram> agentHistogramMap = nodeHistogram.getAgentHistogramMap();
Assert.assertTrue(agentHistogramMap.isEmpty());
// time histogram
HistogramSchema histogramSchema = node.getServiceType().getHistogramSchema();
List<ResponseTimeViewModel.TimeCount> expectedTimeCounts = Collections.singletonList(new ResponseTimeViewModel.TimeCount(timeWindow.refineTimestamp(rootSpanCollectorAcceptTime), 1));
List<TimeViewModel> applicationTimeHistogram = nodeHistogram.getApplicationTimeHistogram(node.getTimeHistogramFormat());
assertTimeHistogram(applicationTimeHistogram, histogramSchema.getFastSlot(), expectedTimeCounts);
AgentResponseTimeViewModelList agentTimeHistogram = nodeHistogram.getAgentTimeHistogram(TimeHistogramFormat.V1);
Assert.assertTrue(agentTimeHistogram.getAgentResponseTimeViewModelList().isEmpty());
} else if (application.getName().equals("ROOT_APP") && application.getServiceType().getCode() == TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE) {
// ROOT_APP node
NodeHistogram nodeHistogram = node.getNodeHistogram();
// histogram
Histogram applicationHistogram = nodeHistogram.getApplicationHistogram();
assertHistogram(applicationHistogram, 1, 0, 0, 0, 0);
Map<String, Histogram> agentHistogramMap = nodeHistogram.getAgentHistogramMap();
assertAgentHistogram(agentHistogramMap, "root-agent", 1, 0, 0, 0, 0);
// time histogram
HistogramSchema histogramSchema = node.getServiceType().getHistogramSchema();
List<ResponseTimeViewModel.TimeCount> expectedTimeCounts = Collections.singletonList(new ResponseTimeViewModel.TimeCount(timeWindow.refineTimestamp(rootSpanCollectorAcceptTime), 1));
List<TimeViewModel> applicationTimeHistogram = nodeHistogram.getApplicationTimeHistogram(node.getTimeHistogramFormat());
assertTimeHistogram(applicationTimeHistogram, histogramSchema.getFastSlot(), expectedTimeCounts);
AgentResponseTimeViewModelList agentTimeHistogram = nodeHistogram.getAgentTimeHistogram(TimeHistogramFormat.V1);
assertAgentTimeHistogram(agentTimeHistogram.getAgentResponseTimeViewModelList(), "root-agent", histogramSchema.getFastSlot(), expectedTimeCounts);
} else if (application.getName().equals("APP_A") && application.getServiceType().getCode() == TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE) {
// APP_A node
NodeHistogram nodeHistogram = node.getNodeHistogram();
// histogram
Histogram applicationHistogram = nodeHistogram.getApplicationHistogram();
assertHistogram(applicationHistogram, 1, 0, 0, 0, 0);
Map<String, Histogram> agentHistogramMap = nodeHistogram.getAgentHistogramMap();
assertAgentHistogram(agentHistogramMap, "app-a", 1, 0, 0, 0, 0);
// time histogram
HistogramSchema histogramSchema = node.getServiceType().getHistogramSchema();
List<ResponseTimeViewModel.TimeCount> expectedTimeCounts = Collections.singletonList(new ResponseTimeViewModel.TimeCount(timeWindow.refineTimestamp(appASpanCollectorAcceptTime), 1));
List<TimeViewModel> applicationTimeHistogram = nodeHistogram.getApplicationTimeHistogram(node.getTimeHistogramFormat());
assertTimeHistogram(applicationTimeHistogram, histogramSchema.getFastSlot(), expectedTimeCounts);
AgentResponseTimeViewModelList agentTimeHistogram = nodeHistogram.getAgentTimeHistogram(TimeHistogramFormat.V1);
assertAgentTimeHistogram(agentTimeHistogram.getAgentResponseTimeViewModelList(), "app-a", histogramSchema.getFastSlot(), expectedTimeCounts);
} else if (application.getName().equals("CacheName") && application.getServiceType().getCode() == TestTraceUtils.CACHE_TYPE_CODE) {
// CACHE node
NodeHistogram nodeHistogram = node.getNodeHistogram();
// histogram
Histogram applicationHistogram = nodeHistogram.getApplicationHistogram();
assertHistogram(applicationHistogram, 0, 1, 0, 0, 0);
Map<String, Histogram> agentHistogramMap = nodeHistogram.getAgentHistogramMap();
assertAgentHistogram(agentHistogramMap, "1.1.1.1", 0, 1, 0, 0, 0);
// time histogram
HistogramSchema histogramSchema = node.getServiceType().getHistogramSchema();
List<ResponseTimeViewModel.TimeCount> expectedTimeCounts = Collections.singletonList(new ResponseTimeViewModel.TimeCount(timeWindow.refineTimestamp(appASpanStartTime + cacheStartElapsed), 1));
List<TimeViewModel> applicationTimeHistogram = nodeHistogram.getApplicationTimeHistogram(node.getTimeHistogramFormat());
assertTimeHistogram(applicationTimeHistogram, histogramSchema.getNormalSlot(), expectedTimeCounts);
AgentResponseTimeViewModelList agentTimeHistogram = nodeHistogram.getAgentTimeHistogram(TimeHistogramFormat.V1);
assertAgentTimeHistogram(agentTimeHistogram.getAgentResponseTimeViewModelList(), "1.1.1.1", histogramSchema.getNormalSlot(), expectedTimeCounts);
} else {
fail("Unexpected node : " + node);
}
}
Collection<Link> links = applicationMap.getLinks();
Assert.assertEquals(3, links.size());
for (Link link : links) {
Application fromApplication = link.getFrom().getApplication();
Application toApplication = link.getTo().getApplication();
if ((fromApplication.getName().equals("ROOT_APP") && fromApplication.getServiceType().getCode() == TestTraceUtils.USER_TYPE_CODE) && (toApplication.getName().equals("ROOT_APP") && toApplication.getServiceType().getCode() == TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE)) {
// histogram
Histogram histogram = link.getHistogram();
assertHistogram(histogram, 1, 0, 0, 0, 0);
// time histogram
List<TimeViewModel> linkApplicationTimeSeriesHistogram = link.getLinkApplicationTimeSeriesHistogram();
HistogramSchema targetHistogramSchema = toApplication.getServiceType().getHistogramSchema();
List<ResponseTimeViewModel.TimeCount> expectedTimeCounts = Collections.singletonList(new ResponseTimeViewModel.TimeCount(timeWindow.refineTimestamp(rootSpanCollectorAcceptTime), 1));
assertTimeHistogram(linkApplicationTimeSeriesHistogram, targetHistogramSchema.getFastSlot(), expectedTimeCounts);
} else if ((fromApplication.getName().equals("ROOT_APP") && fromApplication.getServiceType().getCode() == TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE) && (toApplication.getName().equals("APP_A") && toApplication.getServiceType().getCode() == TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE)) {
// histogram
Histogram histogram = link.getHistogram();
assertHistogram(histogram, 1, 0, 0, 0, 0);
// time histogram
List<TimeViewModel> linkApplicationTimeSeriesHistogram = link.getLinkApplicationTimeSeriesHistogram();
HistogramSchema targetHistogramSchema = toApplication.getServiceType().getHistogramSchema();
List<ResponseTimeViewModel.TimeCount> expectedTimeCounts = Collections.singletonList(new ResponseTimeViewModel.TimeCount(timeWindow.refineTimestamp(appASpanCollectorAcceptTime), 1));
assertTimeHistogram(linkApplicationTimeSeriesHistogram, targetHistogramSchema.getFastSlot(), expectedTimeCounts);
} else if ((fromApplication.getName().equals("APP_A") && fromApplication.getServiceType().getCode() == TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE) && (toApplication.getName().equals("CacheName") && toApplication.getServiceType().getCode() == TestTraceUtils.CACHE_TYPE_CODE)) {
// histogram
Histogram histogram = link.getHistogram();
assertHistogram(histogram, 0, 1, 0, 0, 0);
// time histogram
List<TimeViewModel> linkApplicationTimeSeriesHistogram = link.getLinkApplicationTimeSeriesHistogram();
HistogramSchema targetHistogramSchema = toApplication.getServiceType().getHistogramSchema();
List<ResponseTimeViewModel.TimeCount> expectedTimeCounts = Collections.singletonList(new ResponseTimeViewModel.TimeCount(timeWindow.refineTimestamp(appASpanStartTime + cacheStartElapsed), 1));
assertTimeHistogram(linkApplicationTimeSeriesHistogram, targetHistogramSchema.getNormalSlot(), expectedTimeCounts);
} else {
Assert.fail("Unexpected link : " + link);
}
}
}
use of com.navercorp.pinpoint.common.server.bo.SpanEventBo in project pinpoint by naver.
the class LinkFilterTest method wasToBackendFilter.
@Test
public void wasToBackendFilter() {
final ServiceType tomcat = serviceTypeRegistryService.findServiceTypeByName(TOMCAT_TYPE_NAME);
final ServiceType backend = serviceTypeRegistryService.findServiceTypeByName(BACKEND_TYPE_NAME);
final String destinationA = "BACKEND_A";
final String destinationB = "BACKEND_B";
FilterDescriptor.FromNode fromNode = new FilterDescriptor.FromNode("APP_A", tomcat.getName(), null);
FilterDescriptor.ToNode toNode = new FilterDescriptor.ToNode(destinationA, backend.getName(), null);
FilterDescriptor.SelfNode selfNode = new FilterDescriptor.SelfNode(null, null, null);
FilterDescriptor.ResponseTime responseTime = new FilterDescriptor.ResponseTime(null, null);
FilterDescriptor.Option option = mock(FilterDescriptor.Option.class);
FilterDescriptor descriptor = new FilterDescriptor(fromNode, toNode, selfNode, responseTime, option);
FilterHint hint = new FilterHint(Collections.emptyList());
LinkFilter linkFilter = newLinkFilter(descriptor, hint);
logger.debug(linkFilter.toString());
SpanBo matchingSpan = new SpanBo();
matchingSpan.setApplicationId("APP_A");
matchingSpan.setApplicationServiceType(tomcat.getCode());
SpanEventBo spanEventDestinationA = new SpanEventBo();
spanEventDestinationA.setDestinationId(destinationA);
spanEventDestinationA.setServiceType(BACKEND_TYPE_CODE);
matchingSpan.addSpanEvent(spanEventDestinationA);
Assert.assertTrue(linkFilter.include(Collections.singletonList(matchingSpan)));
SpanBo unmatchingSpan = new SpanBo();
unmatchingSpan.setApplicationId("APP_A");
unmatchingSpan.setApplicationServiceType(tomcat.getCode());
SpanEventBo spanEventDestinationB = new SpanEventBo();
spanEventDestinationB.setDestinationId(destinationB);
spanEventDestinationB.setServiceType(BACKEND_TYPE_CODE);
unmatchingSpan.addSpanEvent(spanEventDestinationB);
Assert.assertFalse(linkFilter.include(Collections.singletonList(unmatchingSpan)));
Assert.assertTrue(linkFilter.include(Arrays.asList(matchingSpan, unmatchingSpan)));
SpanBo bothSpan = new SpanBo();
bothSpan.setApplicationId("APP_A");
bothSpan.setApplicationServiceType(tomcat.getCode());
bothSpan.addSpanEventBoList(Arrays.asList(spanEventDestinationA, spanEventDestinationB));
Assert.assertTrue(linkFilter.include(Collections.singletonList(bothSpan)));
}
use of com.navercorp.pinpoint.common.server.bo.SpanEventBo 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.SpanEventBo in project pinpoint by naver.
the class FilteredMapBuilderTest method twoTier.
/**
* USER -> ROOT_APP -> APP_A -> CACHE
*/
@Test
public void twoTier() {
// Given
final Range range = Range.newRange(1, 200000);
final FilteredMapBuilder builder = new FilteredMapBuilder(applicationFactory, registry, range, VERSION);
// root app span
long rootSpanId = RANDOM.nextLong();
long rootSpanStartTime = 1000L;
long rootSpanCollectorAcceptTime = 1210L;
int rootSpanElapsed = 200;
SpanBo rootSpan = new TestTraceUtils.SpanBuilder("ROOT_APP", "root-agent").spanId(rootSpanId).startTime(rootSpanStartTime).collectorAcceptTime(rootSpanCollectorAcceptTime).elapsed(rootSpanElapsed).build();
// app A span
long appASpanId = RANDOM.nextLong();
long appASpanStartTime = 1020L;
long appASpanCollectorAcceptTime = 1090L;
int appASpanElapsed = 160;
SpanBo appASpan = new TestTraceUtils.SpanBuilder("APP_A", "app-a").spanId(appASpanId).parentSpan(rootSpan).startTime(appASpanStartTime).collectorAcceptTime(appASpanCollectorAcceptTime).elapsed(appASpanElapsed).build();
// root app -> app A rpc span event
SpanEventBo rootRpcSpanEvent = new TestTraceUtils.RpcSpanEventBuilder("www.foo.com/bar", 10, 190).nextSpanId(appASpanId).build();
rootSpan.addSpanEvent(rootRpcSpanEvent);
// app A -> cache span event
int cacheStartElapsed = 20;
int cacheEndElapsed = 130;
SpanEventBo appACacheSpanEvent = new TestTraceUtils.CacheSpanEventBuilder("CacheName", "1.1.1.1", cacheStartElapsed, cacheEndElapsed).build();
appASpan.addSpanEvent(appACacheSpanEvent);
// When
builder.addTransaction(Arrays.asList(rootSpan, appASpan));
FilteredMap filteredMap = builder.build();
// Then
LinkDataDuplexMap linkDataDuplexMap = filteredMap.getLinkDataDuplexMap();
LinkDataMap sourceLinkDataMap = linkDataDuplexMap.getSourceLinkDataMap();
assertSourceLinkData(sourceLinkDataMap, "ROOT_APP", registry.findServiceType(TestTraceUtils.USER_TYPE_CODE), "ROOT_APP", registry.findServiceType(TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE));
assertSourceLinkData(sourceLinkDataMap, "ROOT_APP", registry.findServiceType(TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE), "www.foo.com/bar", registry.findServiceType(TestTraceUtils.RPC_TYPE_CODE));
assertSourceLinkData(sourceLinkDataMap, "APP_A", registry.findServiceType(TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE), "CacheName", registry.findServiceType(TestTraceUtils.CACHE_TYPE_CODE));
LinkDataMap targetLinkDataMap = linkDataDuplexMap.getTargetLinkDataMap();
assertTargetLinkData(targetLinkDataMap, "ROOT_APP", registry.findServiceType(TestTraceUtils.USER_TYPE_CODE), "ROOT_APP", registry.findServiceType(TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE));
assertTargetLinkData(targetLinkDataMap, "ROOT_APP", registry.findServiceType(TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE), "APP_A", registry.findServiceType(TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE));
ResponseHistograms responseHistograms = filteredMap.getResponseHistograms();
Application rootApplication = new Application("ROOT_APP", registry.findServiceType(TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE));
List<ResponseTime> rootAppResponseTimes = responseHistograms.getResponseTimeList(rootApplication);
Assert.assertNotNull(rootAppResponseTimes);
Assert.assertEquals(1, rootAppResponseTimes.size());
Application applicationA = new Application("APP_A", registry.findServiceType(TestTraceUtils.TEST_STAND_ALONE_TYPE_CODE));
List<ResponseTime> appAResponseTimes = responseHistograms.getResponseTimeList(applicationA);
Assert.assertNotNull(appAResponseTimes);
Assert.assertEquals(1, appAResponseTimes.size());
}
Aggregations