Skip to content

Commit

Permalink
[#2941] Add function of checking if deadlock occurred in agent
Browse files Browse the repository at this point in the history
Adds function of display unstable status on the inspector.
  • Loading branch information
koo-taejin authored and Xylus committed Jun 28, 2017
1 parent 7189ad2 commit 17e50af
Show file tree
Hide file tree
Showing 20 changed files with 978 additions and 167 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2017 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.common.server.bo.stat;

/**
* @author Taejin Koo
*/
public interface AgentWarningStatDataPoint extends AgentStatDataPoint {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @author Taejin Koo
*/
public class DeadlockBo implements AgentStatDataPoint {
public class DeadlockBo implements AgentWarningStatDataPoint {

public static final int UNCOLLECTED_INT_VALUE = -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,34 @@

package com.navercorp.pinpoint.common.server.util;

import java.io.UnsupportedEncodingException;

import com.navercorp.pinpoint.common.util.BytesUtils;
import com.navercorp.pinpoint.thrift.io.DeserializerFactory;
import com.navercorp.pinpoint.thrift.util.SerializationUtils;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;

import com.navercorp.pinpoint.thrift.io.DeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer;
import com.navercorp.pinpoint.thrift.util.SerializationUtils;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
* @author HyunGil Jeong
*/
public class AgentEventMessageDeserializer {

private final DeserializerFactory<HeaderTBaseDeserializer> tBaseDeserializerFactory;

public AgentEventMessageDeserializer(DeserializerFactory<HeaderTBaseDeserializer> tBaseDeserializerFactory) {
this.tBaseDeserializerFactory = tBaseDeserializerFactory;

private final List<DeserializerFactory> deserializerFactoryList;

public AgentEventMessageDeserializer(DeserializerFactory deserializerFactory) {
List<DeserializerFactory> deserializerFactoryList = new ArrayList<DeserializerFactory>(1);
deserializerFactoryList.add(deserializerFactory);

this.deserializerFactoryList = deserializerFactoryList;
}


public AgentEventMessageDeserializer(List<DeserializerFactory> deserializerFactoryList) {
this.deserializerFactoryList = deserializerFactoryList;
}

public Object deserialize(AgentEventType agentEventType, byte[] eventBody) throws UnsupportedEncodingException {
if (agentEventType == null) {
throw new NullPointerException("agentEventType must not be null");
Expand All @@ -46,10 +53,12 @@ public Object deserialize(AgentEventType agentEventType, byte[] eventBody) throw
return null;
}
if (TBase.class.isAssignableFrom(eventMessageType)) {
try {
return SerializationUtils.deserialize(eventBody, this.tBaseDeserializerFactory);
} catch (TException e) {
throw new UnsupportedEncodingException(e.getMessage());
for (DeserializerFactory deserializerFactory : deserializerFactoryList) {
try {
return SerializationUtils.deserialize(eventBody, deserializerFactory);
} catch (TException e) {
// ignore
}
}
} else if (String.class.isAssignableFrom(eventMessageType)) {
return BytesUtils.toString(eventBody);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2017 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.thrift.io;

import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocolFactory;

/**
* @author Taejin Koo
*/
public class AgentEventHeaderTBaseDeserializerFactory implements DeserializerFactory<HeaderTBaseDeserializer> {

private static final TProtocolFactory DEFAULT_PROTOCOL_FACTORY = new TCompactProtocol.Factory();
private final TProtocolFactory protocolFactory;
private final TBaseLocator locator = new AgentEventTBaseLocator();

public AgentEventHeaderTBaseDeserializerFactory() {
this(DEFAULT_PROTOCOL_FACTORY);
}

public AgentEventHeaderTBaseDeserializerFactory(TProtocolFactory protocolFactory) {
if (protocolFactory == null) {
throw new NullPointerException("protocolFactory must not be null");
}
this.protocolFactory = protocolFactory;
}

public TProtocolFactory getProtocolFactory() {
return protocolFactory;
}

@Override
public HeaderTBaseDeserializer createDeserializer() {
return new HeaderTBaseDeserializer(protocolFactory, locator);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -50,6 +51,7 @@ public class CommandController {
private SerializerFactory<HeaderTBaseSerializer> commandSerializerFactory;

@Autowired
@Qualifier("commandHeaderTBaseDeserializerFactory")
private DeserializerFactory<HeaderTBaseDeserializer> commandDeserializerFactory;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.navercorp.pinpoint.common.server.util.AgentEventMessageDeserializer;
import com.navercorp.pinpoint.common.server.util.AgentEventType;
import com.navercorp.pinpoint.common.server.util.AgentEventTypeCategory;
import com.navercorp.pinpoint.common.util.ArrayUtils;
import com.navercorp.pinpoint.web.dao.AgentEventDao;
import com.navercorp.pinpoint.web.vo.AgentEvent;
import com.navercorp.pinpoint.web.vo.DurationalAgentEvent;
Expand Down Expand Up @@ -57,7 +58,6 @@ public List<AgentEvent> getAgentEvents(String agentId, Range range, int... exclu
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);
Expand All @@ -66,7 +66,7 @@ public List<AgentEvent> getAgentEvents(String agentId, Range range, int... exclu
}
}
List<AgentEventBo> agentEventBos = this.agentEventDao.getAgentEvents(agentId, range, excludeEventTypes);
List<AgentEvent> agentEvents = createAgentEvents(agentEventBos, includeEventMessage);
List<AgentEvent> agentEvents = createAgentEvents(agentEventBos);
Collections.sort(agentEvents, AgentEvent.EVENT_TIMESTAMP_ASC_COMPARATOR);
return agentEvents;
}
Expand All @@ -91,17 +91,18 @@ public AgentEvent getAgentEvent(String agentId, long eventTimestamp, int eventTy
return null;
}

private List<AgentEvent> createAgentEvents(List<AgentEventBo> agentEventBos, boolean includeEventMessage) {
private List<AgentEvent> createAgentEvents(List<AgentEventBo> agentEventBos) {
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));
durationalAgentEvents.add(createDurationalAgentEvent(agentEventBo, false));
} else {
agentEvents.add(createAgentEvent(agentEventBo, includeEventMessage));
boolean hasMessage = !ArrayUtils.isEmpty(agentEventBo.getEventBody());
agentEvents.add(createAgentEvent(agentEventBo, hasMessage));
}
}
long durationStartTimestamp = DurationalAgentEvent.UNKNOWN_TIMESTAMP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.navercorp.pinpoint.web.dao.AgentLifeCycleDao;
import com.navercorp.pinpoint.web.dao.ApplicationIndexDao;
import com.navercorp.pinpoint.web.filter.agent.AgentEventFilter;
import com.navercorp.pinpoint.web.service.stat.AgentWarningStatService;
import com.navercorp.pinpoint.web.vo.AgentEvent;
import com.navercorp.pinpoint.web.vo.AgentInfo;
import com.navercorp.pinpoint.web.vo.AgentStatus;
Expand All @@ -33,8 +34,9 @@
import com.navercorp.pinpoint.web.vo.timeline.inspector.AgentEventTimeline;
import com.navercorp.pinpoint.web.vo.timeline.inspector.AgentEventTimelineBuilder;
import com.navercorp.pinpoint.web.vo.timeline.inspector.AgentStatusTimeline;
import com.navercorp.pinpoint.web.vo.timeline.inspector.InspectorTimeline;
import com.navercorp.pinpoint.web.vo.timeline.inspector.AgentStatusTimelineBuilder;
import com.navercorp.pinpoint.web.vo.timeline.inspector.AgentStatusTimelineSegment;
import com.navercorp.pinpoint.web.vo.timeline.inspector.InspectorTimeline;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.PredicateUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -64,6 +66,9 @@ public class AgentInfoServiceImpl implements AgentInfoService {
@Autowired
private AgentEventService agentEventService;

@Autowired
private AgentWarningStatService agentWarningStatService;

@Autowired
private ApplicationIndexDao applicationIndexDao;

Expand Down Expand Up @@ -262,8 +267,9 @@ public InspectorTimeline getAgentStatusTimeline(String agentId, Range range, int
AgentStatus initialStatus = getAgentStatus(agentId, range.getFrom());
List<AgentEvent> agentEvents = agentEventService.getAgentEvents(agentId, range);

AgentStatusTimelineBuilder agentStatusTimelinebuilder = new AgentStatusTimelineBuilder(range, initialStatus);
agentStatusTimelinebuilder.from(agentEvents);
List<AgentStatusTimelineSegment> warningStatusTimelineSegmentList = agentWarningStatService.select(agentId, range);

AgentStatusTimelineBuilder agentStatusTimelinebuilder = new AgentStatusTimelineBuilder(range, initialStatus, agentEvents, warningStatusTimelineSegmentList);
AgentStatusTimeline agentStatusTimeline = agentStatusTimelinebuilder.build();

AgentEventTimelineBuilder agentEventTimelineBuilder = new AgentEventTimelineBuilder(range);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer;
import com.navercorp.pinpoint.thrift.dto.command.TRouteResult;
import com.navercorp.pinpoint.thrift.io.DeserializerFactory;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer;
import com.navercorp.pinpoint.thrift.io.HeaderTBaseSerializer;
import com.navercorp.pinpoint.thrift.io.SerializerFactory;
import com.navercorp.pinpoint.thrift.util.SerializationUtils;
Expand All @@ -44,6 +43,7 @@
import org.apache.thrift.TBase;
import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -75,7 +75,8 @@ public class AgentServiceImpl implements AgentService {
private SerializerFactory<HeaderTBaseSerializer> commandSerializerFactory;

@Autowired
private DeserializerFactory<HeaderTBaseDeserializer> commandDeserializerFactory;
@Qualifier("commandHeaderTBaseDeserializerFactory")
private DeserializerFactory commandDeserializerFactory;

@Value("#{pinpointWebProps['web.activethread.activeAgent.duration.days'] ?: 7}")
private void setTimeDiffMs(int durationDays) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2017 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.web.service.stat;

import com.navercorp.pinpoint.web.vo.Range;
import com.navercorp.pinpoint.web.vo.timeline.inspector.AgentStatusTimelineSegment;

import java.util.List;
import java.util.Map;

/**
* @author Taejin Koo
*/
public interface AgentWarningStatService {

List<AgentStatusTimelineSegment> select(String agentId, Range range);

Map<Long, List<AgentStatusTimelineSegment>> selectSeparatedByStartTimestamp(String agentId, Range range);

}
Loading

0 comments on commit 17e50af

Please sign in to comment.