Search in sources :

Example 1 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.

the class AgentEventServiceImpl method createAgentEvents.

private List<AgentEvent> createAgentEvents(List<AgentEventBo> agentEventBos, boolean includeEventMessage) {
    if (CollectionUtils.isEmpty(agentEventBos)) {
        return Collections.emptyList();
    }
    List<AgentEvent> agentEvents = new ArrayList<>(agentEventBos.size());
    PriorityQueue<DurationalAgentEvent> durationalAgentEvents = new PriorityQueue<>(agentEventBos.size(), AgentEvent.EVENT_TIMESTAMP_ASC_COMPARATOR);
    for (AgentEventBo agentEventBo : agentEventBos) {
        if (agentEventBo.getEventType().isCategorizedAs(AgentEventTypeCategory.DURATIONAL)) {
            durationalAgentEvents.add(createDurationalAgentEvent(agentEventBo, includeEventMessage));
        } else {
            agentEvents.add(createAgentEvent(agentEventBo, includeEventMessage));
        }
    }
    long durationStartTimestamp = DurationalAgentEvent.UNKNOWN_TIMESTAMP;
    while (!durationalAgentEvents.isEmpty()) {
        DurationalAgentEvent currentEvent = durationalAgentEvents.remove();
        if (durationStartTimestamp == DurationalAgentEvent.UNKNOWN_TIMESTAMP) {
            durationStartTimestamp = currentEvent.getEventTimestamp();
        }
        currentEvent.setDurationStartTimestamp(durationStartTimestamp);
        DurationalAgentEvent nextEvent = durationalAgentEvents.peek();
        if (nextEvent != null) {
            long nextEventTimestamp = nextEvent.getEventTimestamp();
            currentEvent.setDurationEndTimestamp(nextEventTimestamp);
            durationStartTimestamp = nextEventTimestamp;
        }
        agentEvents.add(currentEvent);
    }
    return agentEvents;
}
Also used : DurationalAgentEvent(com.navercorp.pinpoint.web.vo.DurationalAgentEvent) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) ArrayList(java.util.ArrayList) PriorityQueue(java.util.PriorityQueue) AgentEvent(com.navercorp.pinpoint.web.vo.AgentEvent) DurationalAgentEvent(com.navercorp.pinpoint.web.vo.DurationalAgentEvent)

Example 2 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.

the class AgentEventServiceImpl method getAgentEvent.

@Override
public AgentEvent getAgentEvent(String agentId, long eventTimestamp, int eventTypeCode) {
    if (agentId == null) {
        throw new NullPointerException("agentId must not be null");
    }
    if (eventTimestamp < 0) {
        throw new IllegalArgumentException("eventTimeTimestamp must not be less than 0");
    }
    final AgentEventType eventType = AgentEventType.getTypeByCode(eventTypeCode);
    if (eventType == null) {
        throw new IllegalArgumentException("invalid eventTypeCode [" + eventTypeCode + "]");
    }
    final boolean includeEventMessage = true;
    AgentEventBo agentEventBo = this.agentEventDao.getAgentEvent(agentId, eventTimestamp, eventType);
    if (agentEventBo != null) {
        return createAgentEvent(agentEventBo, includeEventMessage);
    }
    return null;
}
Also used : AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo)

Example 3 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.

the class AgentEventServiceImpl method getAgentEvents.

@Override
public List<AgentEvent> getAgentEvents(String agentId, Range range, int... excludeEventTypeCodes) {
    if (agentId == null) {
        throw new NullPointerException("agentId must not be null");
    }
    final boolean includeEventMessage = false;
    Set<AgentEventType> excludeEventTypes = EnumSet.noneOf(AgentEventType.class);
    for (int excludeEventTypeCode : excludeEventTypeCodes) {
        AgentEventType excludeEventType = AgentEventType.getTypeByCode(excludeEventTypeCode);
        if (excludeEventType != null) {
            excludeEventTypes.add(excludeEventType);
        }
    }
    List<AgentEventBo> agentEventBos = this.agentEventDao.getAgentEvents(agentId, range, excludeEventTypes);
    List<AgentEvent> agentEvents = createAgentEvents(agentEventBos, includeEventMessage);
    Collections.sort(agentEvents, AgentEvent.EVENT_TIMESTAMP_ASC_COMPARATOR);
    return agentEvents;
}
Also used : AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) AgentEvent(com.navercorp.pinpoint.web.vo.AgentEvent) DurationalAgentEvent(com.navercorp.pinpoint.web.vo.DurationalAgentEvent)

Example 4 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.

the class AgentEventHandlerTest method handler_should_handle_events_with_empty_message_body.

@Test
public void handler_should_handle_events_with_empty_message_body() throws Exception {
    // given
    final AgentEventType expectedEventType = AgentEventType.AGENT_CONNECTED;
    ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
    // when
    this.agentEventHandler.handleEvent(this.pinpointServer, TEST_EVENT_TIMESTAMP, expectedEventType);
    verify(this.agentEventDao, times(1)).insert(argCaptor.capture());
    // then
    AgentEventBo actualAgentEventBo = argCaptor.getValue();
    assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
    assertEquals(TEST_START_TIMESTAMP, actualAgentEventBo.getStartTimestamp());
    assertEquals(TEST_EVENT_TIMESTAMP, actualAgentEventBo.getEventTimestamp());
    assertEquals(expectedEventType, actualAgentEventBo.getEventType());
    assertNull(actualAgentEventBo.getEventBody());
}
Also used : AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) Test(org.junit.Test)

Example 5 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.

the class AgentEventHandlerTest method handler_should_handle_serialization_of_messages_appropriately.

@Test
public void handler_should_handle_serialization_of_messages_appropriately() throws Exception {
    // given
    final AgentEventType expectedEventType = AgentEventType.OTHER;
    final String expectedMessageBody = "test event message";
    final byte[] expectedMessageBodyBytes = BytesUtils.toBytes(expectedMessageBody);
    ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
    when(this.agentEventMessageSerializer.serialize(expectedEventType, expectedMessageBody)).thenReturn(expectedMessageBodyBytes);
    // when
    this.agentEventHandler.handleEvent(this.pinpointServer, TEST_EVENT_TIMESTAMP, expectedEventType, expectedMessageBody);
    verify(this.agentEventDao, times(1)).insert(argCaptor.capture());
    // then
    AgentEventBo actualAgentEventBo = argCaptor.getValue();
    assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
    assertEquals(TEST_START_TIMESTAMP, actualAgentEventBo.getStartTimestamp());
    assertEquals(TEST_EVENT_TIMESTAMP, actualAgentEventBo.getEventTimestamp());
    assertEquals(expectedEventType, actualAgentEventBo.getEventType());
    assertEquals(expectedMessageBodyBytes, actualAgentEventBo.getEventBody());
}
Also used : AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) Test(org.junit.Test)

Aggregations

AgentEventBo (com.navercorp.pinpoint.common.server.bo.AgentEventBo)7 AgentEventType (com.navercorp.pinpoint.common.server.util.AgentEventType)5 Test (org.junit.Test)4 ResponseEvent (com.navercorp.pinpoint.collector.cluster.route.ResponseEvent)2 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)2 TCommandTransferResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse)2 HeaderTBaseDeserializer (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer)2 AgentEvent (com.navercorp.pinpoint.web.vo.AgentEvent)2 DurationalAgentEvent (com.navercorp.pinpoint.web.vo.DurationalAgentEvent)2 TCommandEcho (com.navercorp.pinpoint.thrift.dto.command.TCommandEcho)1 TCommandThreadDumpResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse)1 ArrayList (java.util.ArrayList)1 PriorityQueue (java.util.PriorityQueue)1