Search in sources :

Example 1 with AgentStatusQuery

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

the class AgentInfoServerInstanceListDataSource method filterAgentInfos.

// TODO Change to list of filters?
private Set<AgentInfo> filterAgentInfos(Set<AgentInfo> agentInfos, long timestamp, Node node) {
    final Map<String, Histogram> agentHistogramMap = getAgentHistogramMap(node);
    Set<AgentInfo> filteredAgentInfos = new HashSet<>();
    List<AgentInfo> agentsToCheckStatus = new ArrayList<>();
    for (AgentInfo agentInfo : agentInfos) {
        String agentId = agentInfo.getAgentId();
        if (agentHistogramMap.containsKey(agentId)) {
            filteredAgentInfos.add(agentInfo);
        } else {
            agentsToCheckStatus.add(agentInfo);
        }
    }
    AgentStatusQuery query = AgentStatusQuery.buildQuery(agentInfos, timestamp);
    List<Optional<AgentStatus>> agentStatusList = agentInfoService.getAgentStatus(query);
    int idx = 0;
    for (AgentInfo agentInfo : agentsToCheckStatus) {
        Optional<AgentStatus> agentStatus = agentStatusList.get(idx++);
        if (agentStatus.isPresent()) {
            if (agentStatus.get().getState() == AgentLifeCycleState.RUNNING) {
                filteredAgentInfos.add(agentInfo);
            }
        }
    }
    return filteredAgentInfos;
}
Also used : Histogram(com.navercorp.pinpoint.web.applicationmap.histogram.Histogram) NodeHistogram(com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram) Optional(java.util.Optional) ArrayList(java.util.ArrayList) AgentStatusQuery(com.navercorp.pinpoint.web.vo.AgentStatusQuery) AgentStatus(com.navercorp.pinpoint.web.vo.AgentStatus) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) HashSet(java.util.HashSet)

Example 2 with AgentStatusQuery

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

the class AgentInfoServiceImpl method getAgentsByApplicationName.

@Override
public Set<AgentInfo> getAgentsByApplicationName(String applicationName, long timestamp) {
    List<AgentInfo> agentInfos = this.getAgentsByApplicationNameWithoutStatus0(applicationName, timestamp);
    AgentStatusQuery query = AgentStatusQuery.buildQuery(agentInfos, timestamp);
    List<Optional<AgentStatus>> agentStatus = this.agentLifeCycleDao.getAgentStatus(query);
    for (int i = 0; i < agentStatus.size(); i++) {
        Optional<AgentStatus> status = agentStatus.get(i);
        if (status.isPresent()) {
            AgentInfo agentInfo = agentInfos.get(i);
            agentInfo.setStatus(status.get());
        }
    }
    return new HashSet<>(agentInfos);
}
Also used : AgentStatusQuery(com.navercorp.pinpoint.web.vo.AgentStatusQuery) AgentStatus(com.navercorp.pinpoint.web.vo.AgentStatus) Optional(java.util.Optional) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) HashSet(java.util.HashSet)

Example 3 with AgentStatusQuery

use of com.navercorp.pinpoint.web.vo.AgentStatusQuery 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)

Example 4 with AgentStatusQuery

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

the class HbaseAgentLifeCycleDaoTest method populateAgentStatus_should_not_crash_with_invalid_inputs.

@Test
public void populateAgentStatus_should_not_crash_with_invalid_inputs() {
    this.agentLifeCycleDao.getAgentStatus(null, 1000, 1000L);
    AgentStatusQuery.Builder builder = AgentStatusQuery.newBuilder();
    AgentStatusQuery query = builder.build(1000L);
    this.agentLifeCycleDao.getAgentStatus(query);
}
Also used : AgentStatusQuery(com.navercorp.pinpoint.web.vo.AgentStatusQuery) Test(org.junit.Test)

Example 5 with AgentStatusQuery

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

the class HbaseAgentLifeCycleDaoTest method agentInfos_should_be_populated_accordingly_even_with_nulls.

@Test
public void agentInfos_should_be_populated_accordingly_even_with_nulls() {
    // Given
    final String expectedAgentId = "test-agent";
    final long expectedTimestamp = 1000L;
    final AgentLifeCycleState expectedAgentLifeCycleState = AgentLifeCycleState.RUNNING;
    final AgentLifeCycleBo scannedLifeCycleBo = createAgentLifeCycleBo(expectedAgentId, expectedTimestamp, expectedAgentLifeCycleState);
    when(this.hbaseOperations2.findParallel(any(TableName.class), anyList(), any(ResultsExtractor.class))).thenReturn(Arrays.asList(scannedLifeCycleBo, scannedLifeCycleBo));
    AgentInfo nonNullAgentInfo = new AgentInfo();
    nonNullAgentInfo.setAgentId(expectedAgentId);
    nonNullAgentInfo.setStartTimestamp(expectedTimestamp);
    AgentInfo nullAgentInfo = null;
    List<AgentInfo> givenAgentInfos = Arrays.asList(nonNullAgentInfo, nullAgentInfo, nonNullAgentInfo, nullAgentInfo);
    // When
    AgentStatusQuery query = AgentStatusQuery.buildQuery(givenAgentInfos, expectedTimestamp);
    List<Optional<AgentStatus>> agentStatus = this.agentLifeCycleDao.getAgentStatus(query);
    // Then
    Assert.assertEquals(nonNullAgentInfo, givenAgentInfos.get(0));
    Assert.assertEquals(nullAgentInfo, givenAgentInfos.get(1));
    Assert.assertEquals(nonNullAgentInfo, givenAgentInfos.get(2));
    Assert.assertEquals(nullAgentInfo, givenAgentInfos.get(3));
    AgentStatus nonNullAgentInfoStatus = agentStatus.get(0).get();
    Assert.assertEquals(expectedAgentId, nonNullAgentInfoStatus.getAgentId());
    Assert.assertEquals(expectedTimestamp, nonNullAgentInfoStatus.getEventTimestamp());
    Assert.assertEquals(expectedAgentLifeCycleState, nonNullAgentInfoStatus.getState());
}
Also used : ResultsExtractor(com.navercorp.pinpoint.common.hbase.ResultsExtractor) TableName(org.apache.hadoop.hbase.TableName) AgentStatusQuery(com.navercorp.pinpoint.web.vo.AgentStatusQuery) AgentStatus(com.navercorp.pinpoint.web.vo.AgentStatus) Optional(java.util.Optional) AgentInfo(com.navercorp.pinpoint.web.vo.AgentInfo) AgentLifeCycleBo(com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo) AgentLifeCycleState(com.navercorp.pinpoint.common.server.util.AgentLifeCycleState) Test(org.junit.Test)

Aggregations

AgentStatusQuery (com.navercorp.pinpoint.web.vo.AgentStatusQuery)5 AgentInfo (com.navercorp.pinpoint.web.vo.AgentInfo)4 AgentStatus (com.navercorp.pinpoint.web.vo.AgentStatus)4 HashSet (java.util.HashSet)3 Optional (java.util.Optional)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ResultsExtractor (com.navercorp.pinpoint.common.hbase.ResultsExtractor)1 AgentLifeCycleBo (com.navercorp.pinpoint.common.server.bo.AgentLifeCycleBo)1 SimpleAgentKey (com.navercorp.pinpoint.common.server.bo.SimpleAgentKey)1 AgentLifeCycleState (com.navercorp.pinpoint.common.server.util.AgentLifeCycleState)1 ServiceType (com.navercorp.pinpoint.common.trace.ServiceType)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 Histogram (com.navercorp.pinpoint.web.applicationmap.histogram.Histogram)1 NodeHistogram (com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram)1 MapResponseDao (com.navercorp.pinpoint.web.dao.MapResponseDao)1 AgentInfoService (com.navercorp.pinpoint.web.service.AgentInfoService)1 Application (com.navercorp.pinpoint.web.vo.Application)1