Skip to content

Commit

Permalink
#1432 Handle cases for filtered server map where query time does not …
Browse files Browse the repository at this point in the history
…exist
  • Loading branch information
Xylus committed Jan 14, 2016
1 parent b7e39cb commit fe3c9ad
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,47 @@ public ApplicationMap build(Application application, AgentInfoService agentInfoS
}
}

public ApplicationMap build(LinkDataDuplexMap linkDataDuplexMap, AgentInfoService agentInfoService,
public ApplicationMap build(LinkDataDuplexMap linkDataDuplexMap, AgentInfoPopulator agentInfoPopulator,
NodeHistogramDataSource nodeHistogramDataSource) {
if (linkDataDuplexMap == null) {
throw new NullPointerException("linkDataMap must not be null");
}
if (agentInfoService == null) {
throw new NullPointerException("agentInfoService must not be null");
if (agentInfoPopulator == null) {
throw new NullPointerException("agentInfoPopulator must not be null");
}

NodeList nodeList = buildNode(linkDataDuplexMap);
LinkList linkList = buildLink(nodeList, linkDataDuplexMap);

appendNodeResponseTime(nodeList, linkList, nodeHistogramDataSource);
appendAgentInfo(nodeList, linkDataDuplexMap, agentInfoService);
appendAgentInfo(nodeList, linkDataDuplexMap, agentInfoPopulator);

final ApplicationMap map = new ApplicationMap(range, nodeList, linkList);
return map;
}

public ApplicationMap build(LinkDataDuplexMap linkDataDuplexMap, AgentInfoService agentInfoService,
public ApplicationMap build(LinkDataDuplexMap linkDataDuplexMap, final AgentInfoService agentInfoService,
final MapResponseDao mapResponseDao) {
AgentInfoPopulator agentInfoPopulator = new AgentInfoPopulator() {
@Override
public void addAgentInfos(Node node) {
Set<AgentInfo> agentList = agentInfoService.getAgentsByApplicationName(node.getApplication().getName(), range.getTo());
if (agentList.isEmpty()) {
logger.warn("agentInfo not found. applicationName:{}", node.getApplication());
// avoid NPE
node.setServerInstanceList(new ServerInstanceList());
return;
}
logger.debug("add agentInfo. {}, {}", node.getApplication(), agentList);
ServerBuilder builder = new ServerBuilder();
agentList = filterAgentInfoByResponseData(agentList, node);
builder.addAgentInfo(agentList);
ServerInstanceList serverInstanceList = builder.build();

// agentSet exists if the destination is a WAS, and has agent installed
node.setServerInstanceList(serverInstanceList);
}
};
NodeHistogramDataSource responseSource = new NodeHistogramDataSource() {
@Override
public NodeHistogram createNodeHistogram(Application application) {
Expand All @@ -105,11 +125,16 @@ public NodeHistogram createNodeHistogram(Application application) {
return nodeHistogram;
}
};
return this.build(linkDataDuplexMap, agentInfoService, responseSource);
return this.build(linkDataDuplexMap, agentInfoPopulator, responseSource);
}

public ApplicationMap build(LinkDataDuplexMap linkDataDuplexMap, AgentInfoService agentInfoService,
final ResponseHistogramBuilder mapHistogramSummary) {
public ApplicationMap build(LinkDataDuplexMap linkDataDuplexMap, final ResponseHistogramBuilder mapHistogramSummary) {
AgentInfoPopulator emptyPopulator = new AgentInfoPopulator() {
@Override
public void addAgentInfos(Node node) {
node.setServerInstanceList(new ServerInstanceList());
}
};
NodeHistogramDataSource responseSource = new NodeHistogramDataSource() {
@Override
public NodeHistogram createNodeHistogram(Application application) {
Expand All @@ -118,13 +143,17 @@ public NodeHistogram createNodeHistogram(Application application) {
return nodeHistogram;
}
};
return this.build(linkDataDuplexMap, agentInfoService, responseSource);
return this.build(linkDataDuplexMap, emptyPopulator, responseSource);
}

public interface NodeHistogramDataSource {
NodeHistogram createNodeHistogram(Application application);
}

public interface AgentInfoPopulator {
void addAgentInfos(Node node);
}

private NodeList buildNode(LinkDataDuplexMap linkDataDuplexMap) {
NodeList nodeList = new NodeList();
createNode(nodeList, linkDataDuplexMap.getSourceLinkDataMap());
Expand Down Expand Up @@ -380,15 +409,14 @@ private NodeHistogram createTerminalNodeHistogram(Node node, LinkList linkList)
return nodeHistogram;
}

public void appendAgentInfo(NodeList nodeList, LinkDataDuplexMap linkDataDuplexMap,
AgentInfoService agentInfoService) {
public void appendAgentInfo(NodeList nodeList, LinkDataDuplexMap linkDataDuplexMap, AgentInfoPopulator agentInfoPopulator) {
for (Node node : nodeList.getNodeList()) {
appendServerInfo(node, linkDataDuplexMap, agentInfoService);
appendServerInfo(node, linkDataDuplexMap, agentInfoPopulator);
}

}

private void appendServerInfo(Node node, LinkDataDuplexMap linkDataDuplexMap, AgentInfoService agentInfoService) {
private void appendServerInfo(Node node, LinkDataDuplexMap linkDataDuplexMap, AgentInfoPopulator agentInfoPopulator) {
final ServiceType nodeServiceType = node.getServiceType();
if (nodeServiceType.isUnknown()) {
// we do not know the server info for unknown nodes
Expand All @@ -407,22 +435,7 @@ private void appendServerInfo(Node node, LinkDataDuplexMap linkDataDuplexMap, Ag
ServerInstanceList serverInstanceList = builder.build();
node.setServerInstanceList(serverInstanceList);
} else if (nodeServiceType.isWas()) {
Set<AgentInfo> agentList = agentInfoService.getAgentsByApplicationName(node.getApplication().getName(),
range.getTo());
if (agentList.isEmpty()) {
logger.warn("agentInfo not found. applicationName:{}", node.getApplication());
// avoid NPE
node.setServerInstanceList(new ServerInstanceList());
return;
}
logger.debug("add agentInfo. {}, {}", node.getApplication(), agentList);
ServerBuilder builder = new ServerBuilder();
agentList = filterAgentInfoByResponseData(agentList, node);
builder.addAgentInfo(agentList);
ServerInstanceList serverInstanceList = builder.build();

// agentSet exists if the destination is a WAS, and has agent installed
node.setServerInstanceList(serverInstanceList);
agentInfoPopulator.addAgentInfos(node);
} else {
// add empty information
node.setServerInstanceList(new ServerInstanceList());
Expand Down Expand Up @@ -454,7 +467,11 @@ private Set<AgentInfo> filterAgentInfoByResponseData(Set<AgentInfo> agentList, N
}

private boolean isAgentRunning(AgentInfo agentInfo) {
return agentInfo.getStatus().getState() == AgentLifeCycleState.RUNNING;
if (agentInfo.getStatus() != null) {
return agentInfo.getStatus().getState() == AgentLifeCycleState.RUNNING;
} else {
return false;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.navercorp.pinpoint.common.util.TimeUtils;
import com.navercorp.pinpoint.web.dao.AgentInfoDao;

import com.navercorp.pinpoint.web.dao.AgentLifeCycleDao;
import com.navercorp.pinpoint.web.mapper.AgentInfoMapper;
import com.navercorp.pinpoint.web.vo.AgentInfo;
import org.apache.commons.collections.CollectionUtils;
Expand All @@ -48,9 +47,6 @@ public class HbaseAgentInfoDao implements AgentInfoDao {
@Autowired
private HbaseOperations2 hbaseOperations2;

@Autowired
private AgentLifeCycleDao agentLifeCycleDao;

@Autowired
private AgentInfoMapper agentInfoMapper;

Expand Down Expand Up @@ -106,11 +102,7 @@ public AgentInfo getAgentInfo(final String agentId, final long timestamp) {

Scan scan = createScan(agentId, timestamp);

AgentInfo agentInfo = this.hbaseOperations2.find(HBaseTables.AGENTINFO, scan, new AgentInfoResultsExtractor());
if (agentInfo != null) {
this.agentLifeCycleDao.populateAgentStatus(agentInfo, timestamp);
}
return agentInfo;
return this.hbaseOperations2.find(HBaseTables.AGENTINFO, scan, new AgentInfoResultsExtractor());
}

@Override
Expand All @@ -124,9 +116,7 @@ public List<AgentInfo> getAgentInfos(List<String> agentIds, long timestamp) {
scans.add(createScan(agentId, timestamp));
}

List<AgentInfo> agentInfos = this.hbaseOperations2.findParallel(HBaseTables.AGENTINFO, scans, new AgentInfoResultsExtractor());
this.agentLifeCycleDao.populateAgentStatuses(agentInfos, timestamp);
return agentInfos;
return this.hbaseOperations2.findParallel(HBaseTables.AGENTINFO, scans, new AgentInfoResultsExtractor());
}

private Scan createScan(String agentId, long currentTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import java.util.*;

import com.navercorp.pinpoint.common.bo.AgentInfoBo;
import com.navercorp.pinpoint.common.bo.AgentLifeCycleBo;
import com.navercorp.pinpoint.common.util.AgentLifeCycleState;
import com.navercorp.pinpoint.web.dao.AgentInfoDao;
import com.navercorp.pinpoint.web.dao.AgentLifeCycleDao;
Expand Down Expand Up @@ -96,6 +94,7 @@ public ApplicationAgentList getApplicationAgentList(ApplicationAgentList.Key app
SortedMap<String, List<AgentInfo>> result = new TreeMap<>();

List<AgentInfo> agentInfos = this.agentInfoDao.getAgentInfos(agentIdList, timestamp);
this.agentLifeCycleDao.populateAgentStatuses(agentInfos, timestamp);
for (AgentInfo agentInfo : agentInfos) {
if (agentInfo != null) {
String hostname = applicationAgentListKey.getKey(agentInfo);
Expand All @@ -121,23 +120,28 @@ public ApplicationAgentList getApplicationAgentList(ApplicationAgentList.Key app

@Override
public Set<AgentInfo> getAgentsByApplicationName(String applicationName, long timestamp) {
if (applicationName == null) {
throw new NullPointerException("applicationName must not be null");
}
List<String> agentIds = this.applicationIndexDao.selectAgentIds(applicationName);
return new HashSet<>(this.agentInfoDao.getAgentInfos(agentIds, timestamp));
return this.getAgentsByApplicationName(applicationName, timestamp, timestamp);
}

@Override
public Set<AgentInfo> getAgentsByApplicationName(String applicationName, long timestamp, long timeDiff) {
if (applicationName == null) {
throw new NullPointerException("applicationName must not be null");
}
if (timestamp < 0) {
throw new IllegalArgumentException("timeDiff must not be less than 0");
}
if (timeDiff > timestamp) {
throw new IllegalArgumentException("timeDiff must not be greater than timestamp");
}
final long eventTimestampFloor = timestamp - timeDiff;
Set<AgentInfo> unfilteredAgentInfos = this.getAgentsByApplicationName(applicationName, timestamp);

List<String> agentIds = this.applicationIndexDao.selectAgentIds(applicationName);
List<AgentInfo> unfilteredAgentInfos = this.agentInfoDao.getAgentInfos(agentIds, timestamp);
if (unfilteredAgentInfos == null || unfilteredAgentInfos.isEmpty()) {
return Collections.emptySet();
}
this.agentLifeCycleDao.populateAgentStatuses(unfilteredAgentInfos, timestamp);
Set<AgentInfo> filteredAgentInfos = new HashSet<>();
for (AgentInfo agentInfo : unfilteredAgentInfos) {
AgentStatus agentStatus = agentInfo.getStatus();
Expand All @@ -156,7 +160,11 @@ public AgentInfo getAgentInfo(String agentId, long timestamp) {
if (timestamp < 0) {
throw new IllegalArgumentException("timestamp must not be less than 0");
}
return this.agentInfoDao.getAgentInfo(agentId, timestamp);
AgentInfo agentInfo = this.agentInfoDao.getAgentInfo(agentId, timestamp);
if (agentInfo != null) {
this.agentLifeCycleDao.populateAgentStatus(agentInfo, timestamp);
}
return agentInfo;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ public class FilteredMapServiceImpl implements FilteredMapService {
@Autowired
private ApplicationTraceIndexDao applicationTraceIndexDao;

@Autowired
private AgentInfoService agentInfoService;

@Autowired
private ServiceTypeRegistryService registry;

Expand Down Expand Up @@ -285,7 +282,7 @@ private ApplicationMap createMap(Range range, Range scanRange, List<List<SpanBo>

ApplicationMapBuilder applicationMapBuilder = new ApplicationMapBuilder(range);
mapHistogramSummary.build();
ApplicationMap map = applicationMapBuilder.build(linkDataDuplexMap, agentInfoService, mapHistogramSummary);
ApplicationMap map = applicationMapBuilder.build(linkDataDuplexMap, mapHistogramSummary);

map.setApplicationScatterScanResult(applicationScatterScanResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ public void serialize(AgentInfo agentInfo, JsonGenerator jgen, SerializerProvide
jgen.writeObjectField("serverMetaData", agentInfo.getServerMetaData());

AgentStatus status = agentInfo.getStatus();
if (status == null) {
status = new AgentStatus(agentInfo.getAgentId());
status.setState(AgentLifeCycleState.UNKNOWN);
if (status != null) {
jgen.writeObjectField("status", status);
}
jgen.writeObjectField("status", status);

jgen.writeNumberField("initialStartTimestamp", agentInfo.getInitialStartTimestamp());

Expand Down

0 comments on commit fe3c9ad

Please sign in to comment.