Search in sources :

Example 1 with TimeViewModel

use of com.navercorp.pinpoint.web.view.TimeViewModel in project pinpoint by naver.

the class ApplicationTimeHistogramTest method testLoadViewModel.

@Test
public void testLoadViewModel() {
    Application app = new Application("test", ServiceType.STAND_ALONE);
    final long timestamp = System.currentTimeMillis();
    Range range = Range.newRange(timestamp, timestamp + 60000);
    ApplicationTimeHistogramBuilder builder = new ApplicationTimeHistogramBuilder(app, range);
    List<ResponseTime> responseHistogramList = new ArrayList<>();
    ResponseTime responseTime = new ResponseTime(app.getName(), app.getServiceType(), timestamp);
    responseTime.addResponseTime("test", (short) 1000, 1);
    responseHistogramList.add(responseTime);
    ApplicationTimeHistogram histogram = builder.build(responseHistogramList);
    List<TimeViewModel> viewModelList = histogram.createViewModel(TimeHistogramFormat.V2);
    logger.debug("{}", viewModelList);
}
Also used : TimeViewModel(com.navercorp.pinpoint.web.view.TimeViewModel) ArrayList(java.util.ArrayList) ResponseTime(com.navercorp.pinpoint.web.vo.ResponseTime) Range(com.navercorp.pinpoint.web.vo.Range) Application(com.navercorp.pinpoint.web.vo.Application) Test(org.junit.Test)

Example 2 with TimeViewModel

use of com.navercorp.pinpoint.web.view.TimeViewModel 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);
        }
    }
}
Also used : ApplicationMap(com.navercorp.pinpoint.web.applicationmap.ApplicationMap) NodeHistogram(com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram) Histogram(com.navercorp.pinpoint.web.applicationmap.histogram.Histogram) Node(com.navercorp.pinpoint.web.applicationmap.nodes.Node) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HistogramSchema(com.navercorp.pinpoint.common.trace.HistogramSchema) AgentResponseTimeViewModelList(com.navercorp.pinpoint.web.view.AgentResponseTimeViewModelList) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo) AgentResponseTimeViewModelList(com.navercorp.pinpoint.web.view.AgentResponseTimeViewModelList) AgentResponseTimeViewModel(com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel) ResponseTimeViewModel(com.navercorp.pinpoint.web.view.ResponseTimeViewModel) NodeHistogram(com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram) Range(com.navercorp.pinpoint.web.vo.Range) TimeWindow(com.navercorp.pinpoint.web.util.TimeWindow) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) TestTraceUtils(com.navercorp.pinpoint.web.TestTraceUtils) AgentResponseTimeViewModel(com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel) TimeViewModel(com.navercorp.pinpoint.web.view.TimeViewModel) ResponseTimeViewModel(com.navercorp.pinpoint.web.view.ResponseTimeViewModel) Application(com.navercorp.pinpoint.web.vo.Application) Map(java.util.Map) ApplicationMap(com.navercorp.pinpoint.web.applicationmap.ApplicationMap) Link(com.navercorp.pinpoint.web.applicationmap.link.Link) Test(org.junit.Test)

Example 3 with TimeViewModel

use of com.navercorp.pinpoint.web.view.TimeViewModel in project pinpoint by naver.

the class FilteredMapServiceImplTest method assertTimeHistogram.

private void assertTimeHistogram(List<TimeViewModel> histogramList, HistogramSlot histogramSlot, List<ResponseTimeViewModel.TimeCount> expectedTimeCounts) {
    if (CollectionUtils.isEmpty(histogramList)) {
        Assert.fail("Checked against empty histogramList.");
    }
    String slotName = histogramSlot.getSlotName();
    for (TimeViewModel timeViewModel : histogramList) {
        ResponseTimeViewModel histogram = (ResponseTimeViewModel) timeViewModel;
        if (histogram.getColumnName().equals(slotName)) {
            for (ResponseTimeViewModel.TimeCount expectedTimeCount : expectedTimeCounts) {
                boolean expectedTimeCountExists = false;
                for (ResponseTimeViewModel.TimeCount actualTimeCount : histogram.getColumnValue()) {
                    if (expectedTimeCount.getTime() == actualTimeCount.getTime()) {
                        expectedTimeCountExists = true;
                        Assert.assertEquals("TimeCount mismatch for slot : " + slotName, expectedTimeCount.getCount(), actualTimeCount.getCount());
                        break;
                    }
                }
                if (!expectedTimeCountExists) {
                    Assert.fail("Expected TimeCount for " + slotName + " not found, time : " + expectedTimeCount.getTime() + ", count : " + expectedTimeCount.getCount());
                }
            }
            return;
        }
    }
    Assert.fail("Expected " + slotName + " but had none.");
}
Also used : AgentResponseTimeViewModel(com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel) TimeViewModel(com.navercorp.pinpoint.web.view.TimeViewModel) ResponseTimeViewModel(com.navercorp.pinpoint.web.view.ResponseTimeViewModel) AgentResponseTimeViewModel(com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel) ResponseTimeViewModel(com.navercorp.pinpoint.web.view.ResponseTimeViewModel) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 4 with TimeViewModel

use of com.navercorp.pinpoint.web.view.TimeViewModel in project pinpoint by naver.

the class AgentTimeHistogram method createAgentResponseTimeViewModel.

private AgentResponseTimeViewModel createAgentResponseTimeViewModel(Application agentName, List<TimeHistogram> timeHistogramList, TimeHistogramFormat timeHistogramFormat) {
    List<TimeViewModel> responseTimeViewModel = createResponseTimeViewModel(timeHistogramList, timeHistogramFormat);
    AgentResponseTimeViewModel agentResponseTimeViewModel = new AgentResponseTimeViewModel(agentName, responseTimeViewModel);
    return agentResponseTimeViewModel;
}
Also used : AgentResponseTimeViewModel(com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel) TimeViewModel(com.navercorp.pinpoint.web.view.TimeViewModel) AgentResponseTimeViewModel(com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel)

Example 5 with TimeViewModel

use of com.navercorp.pinpoint.web.view.TimeViewModel in project pinpoint by naver.

the class ApplicationTimeHistogramTest method testViewModel.

@Test
public void testViewModel() throws IOException {
    Application app = new Application("test", ServiceType.STAND_ALONE);
    ApplicationTimeHistogramBuilder builder = new ApplicationTimeHistogramBuilder(app, Range.newRange(0, 10 * 6000));
    List<ResponseTime> responseHistogramList = createResponseTime(app);
    ApplicationTimeHistogram histogram = builder.build(responseHistogramList);
    List<TimeViewModel> viewModel = histogram.createViewModel(TimeHistogramFormat.V1);
    logger.debug("{}", viewModel);
    ObjectWriter writer = mapper.writer();
    String s = writer.writeValueAsString(viewModel);
    logger.debug(s);
}
Also used : TimeViewModel(com.navercorp.pinpoint.web.view.TimeViewModel) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ResponseTime(com.navercorp.pinpoint.web.vo.ResponseTime) Application(com.navercorp.pinpoint.web.vo.Application) Test(org.junit.Test)

Aggregations

TimeViewModel (com.navercorp.pinpoint.web.view.TimeViewModel)5 AgentResponseTimeViewModel (com.navercorp.pinpoint.web.view.AgentResponseTimeViewModel)3 Application (com.navercorp.pinpoint.web.vo.Application)3 Test (org.junit.Test)3 ResponseTimeViewModel (com.navercorp.pinpoint.web.view.ResponseTimeViewModel)2 Range (com.navercorp.pinpoint.web.vo.Range)2 ResponseTime (com.navercorp.pinpoint.web.vo.ResponseTime)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)1 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)1 HistogramSchema (com.navercorp.pinpoint.common.trace.HistogramSchema)1 TestTraceUtils (com.navercorp.pinpoint.web.TestTraceUtils)1 ApplicationMap (com.navercorp.pinpoint.web.applicationmap.ApplicationMap)1 Histogram (com.navercorp.pinpoint.web.applicationmap.histogram.Histogram)1 NodeHistogram (com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram)1 Link (com.navercorp.pinpoint.web.applicationmap.link.Link)1 Node (com.navercorp.pinpoint.web.applicationmap.nodes.Node)1 TimeWindow (com.navercorp.pinpoint.web.util.TimeWindow)1 AgentResponseTimeViewModelList (com.navercorp.pinpoint.web.view.AgentResponseTimeViewModelList)1