Search in sources :

Example 1 with ResponseHistograms

use of com.navercorp.pinpoint.web.vo.ResponseHistograms 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());
}
Also used : LinkDataDuplexMap(com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap) Range(com.navercorp.pinpoint.web.vo.Range) SpanBo(com.navercorp.pinpoint.common.server.bo.SpanBo) TestTraceUtils(com.navercorp.pinpoint.web.TestTraceUtils) ResponseHistograms(com.navercorp.pinpoint.web.vo.ResponseHistograms) ResponseTime(com.navercorp.pinpoint.web.vo.ResponseTime) Application(com.navercorp.pinpoint.web.vo.Application) SpanEventBo(com.navercorp.pinpoint.common.server.bo.SpanEventBo) LinkDataMap(com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap) Test(org.junit.Test)

Example 2 with ResponseHistograms

use of com.navercorp.pinpoint.web.vo.ResponseHistograms in project pinpoint by naver.

the class ApplicationMapBuilderTest method setUp.

@Before
public void setUp() {
    MapResponseDao mapResponseDao = mock(MapResponseDao.class);
    mapResponseNodeHistogramDataSource = new MapResponseNodeHistogramDataSource(mapResponseDao);
    ResponseHistograms responseHistograms = mock(ResponseHistograms.class);
    responseHistogramBuilderNodeHistogramDataSource = new ResponseHistogramsNodeHistogramDataSource(responseHistograms);
    AgentInfoService agentInfoService = mock(AgentInfoService.class);
    agentInfoServerInstanceListDataSource = new AgentInfoServerInstanceListDataSource(agentInfoService);
    Answer<List<ResponseTime>> responseTimeAnswer = new Answer<List<ResponseTime>>() {

        final long timestamp = System.currentTimeMillis();

        @Override
        public List<ResponseTime> answer(InvocationOnMock invocation) {
            Application application = invocation.getArgument(0);
            String applicationName = application.getName();
            ServiceType applicationServiceType = application.getServiceType();
            int depth = ApplicationMapBuilderTestHelper.getDepthFromApplicationName(applicationName);
            ResponseTime responseTime = new ResponseTime(application.getName(), application.getServiceType(), timestamp);
            responseTime.addResponseTime(ApplicationMapBuilderTestHelper.createAgentIdFromDepth(depth), applicationServiceType.getHistogramSchema().getNormalSlot().getSlotTime(), 1);
            return Collections.singletonList(responseTime);
        }
    };
    when(mapResponseDao.selectResponseTime(any(Application.class), any(Range.class))).thenAnswer(responseTimeAnswer);
    when(responseHistograms.getResponseTimeList(any(Application.class))).thenAnswer(responseTimeAnswer);
    when(agentInfoService.getAgentsByApplicationName(anyString(), anyLong())).thenAnswer(new Answer<Set<AgentInfo>>() {

        @Override
        public Set<AgentInfo> answer(InvocationOnMock invocation) throws Throwable {
            String applicationName = invocation.getArgument(0);
            AgentInfo agentInfo = ApplicationMapBuilderTestHelper.createAgentInfoFromApplicationName(applicationName);
            AgentStatus agentStatus = new AgentStatus(agentInfo.getAgentId(), AgentLifeCycleState.RUNNING, 0);
            agentInfo.setStatus(agentStatus);
            Set<AgentInfo> agentInfos = new HashSet<>();
            agentInfos.add(agentInfo);
            return agentInfos;
        }
    });
    when(agentInfoService.getAgentsByApplicationNameWithoutStatus(anyString(), anyLong())).thenAnswer(new Answer<Set<AgentInfo>>() {

        @Override
        public Set<AgentInfo> answer(InvocationOnMock invocation) throws Throwable {
            String applicationName = invocation.getArgument(0);
            AgentInfo agentInfo = ApplicationMapBuilderTestHelper.createAgentInfoFromApplicationName(applicationName);
            Set<AgentInfo> agentInfos = new HashSet<>();
            agentInfos.add(agentInfo);
            return agentInfos;
        }
    });
    when(agentInfoService.getAgentStatus(anyString(), anyLong())).thenAnswer(new Answer<AgentStatus>() {

        @Override
        public AgentStatus answer(InvocationOnMock invocation) throws Throwable {
            String agentId = invocation.getArgument(0);
            AgentStatus agentStatus = new AgentStatus(agentId, AgentLifeCycleState.RUNNING, System.currentTimeMillis());
            return agentStatus;
        }
    });
    doAnswer(new Answer<List<Optional<AgentStatus>>>() {

        @Override
        public List<Optional<AgentStatus>> answer(InvocationOnMock invocation) throws Throwable {
            List<Optional<AgentStatus>> result = new ArrayList<>();
            AgentStatusQuery query = invocation.getArgument(0);
            for (SimpleAgentKey agentInfo : query.getAgentKeys()) {
                AgentStatus agentStatus = new AgentStatus(agentInfo.getAgentId(), AgentLifeCycleState.RUNNING, System.currentTimeMillis());
                result.add(Optional.of(agentStatus));
            }
            return result;
        }
    }).when(agentInfoService).getAgentStatus(any());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AgentInfoService(com.navercorp.pinpoint.web.service.AgentInfoService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AgentInfoServerInstanceListDataSource(com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.AgentInfoServerInstanceListDataSource) ResponseHistograms(com.navercorp.pinpoint.web.vo.ResponseHistograms) AgentStatus(com.navercorp.pinpoint.web.vo.AgentStatus) ServiceType(com.navercorp.pinpoint.common.trace.ServiceType) MapResponseNodeHistogramDataSource(com.navercorp.pinpoint.web.applicationmap.appender.histogram.datasource.MapResponseNodeHistogramDataSource) ArrayList(java.util.ArrayList) List(java.util.List) ResponseTime(com.navercorp.pinpoint.web.vo.ResponseTime) MapResponseDao(com.navercorp.pinpoint.web.dao.MapResponseDao) Range(com.navercorp.pinpoint.web.vo.Range) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AgentStatusQuery(com.navercorp.pinpoint.web.vo.AgentStatusQuery) SimpleAgentKey(com.navercorp.pinpoint.common.server.bo.SimpleAgentKey) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResponseHistogramsNodeHistogramDataSource(com.navercorp.pinpoint.web.applicationmap.appender.histogram.datasource.ResponseHistogramsNodeHistogramDataSource) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) Application(com.navercorp.pinpoint.web.vo.Application) Before(org.junit.Before)

Aggregations

Application (com.navercorp.pinpoint.web.vo.Application)2 Range (com.navercorp.pinpoint.web.vo.Range)2 ResponseHistograms (com.navercorp.pinpoint.web.vo.ResponseHistograms)2 ResponseTime (com.navercorp.pinpoint.web.vo.ResponseTime)2 SimpleAgentKey (com.navercorp.pinpoint.common.server.bo.SimpleAgentKey)1 SpanBo (com.navercorp.pinpoint.common.server.bo.SpanBo)1 SpanEventBo (com.navercorp.pinpoint.common.server.bo.SpanEventBo)1 ServiceType (com.navercorp.pinpoint.common.trace.ServiceType)1 TestTraceUtils (com.navercorp.pinpoint.web.TestTraceUtils)1 MapResponseNodeHistogramDataSource (com.navercorp.pinpoint.web.applicationmap.appender.histogram.datasource.MapResponseNodeHistogramDataSource)1 ResponseHistogramsNodeHistogramDataSource (com.navercorp.pinpoint.web.applicationmap.appender.histogram.datasource.ResponseHistogramsNodeHistogramDataSource)1 AgentInfoServerInstanceListDataSource (com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.AgentInfoServerInstanceListDataSource)1 LinkDataDuplexMap (com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap)1 LinkDataMap (com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap)1 MapResponseDao (com.navercorp.pinpoint.web.dao.MapResponseDao)1 AgentInfoService (com.navercorp.pinpoint.web.service.AgentInfoService)1 AgentInfo (com.navercorp.pinpoint.web.vo.AgentInfo)1 AgentStatus (com.navercorp.pinpoint.web.vo.AgentStatus)1 AgentStatusQuery (com.navercorp.pinpoint.web.vo.AgentStatusQuery)1 ArrayList (java.util.ArrayList)1