Skip to content

Commit

Permalink
[#9023] AgentAndStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jul 19, 2022
1 parent 54809c3 commit 827be6d
Show file tree
Hide file tree
Showing 27 changed files with 211 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ public AgentCountStatistics process(ApplicationAgentsList item) throws Exception
}

private int getAgentCount(List<ApplicationAgentList> applicationAgentLists) {
int agentCount = 0;
for (ApplicationAgentList applicationAgentList : applicationAgentLists) {
agentCount += applicationAgentList.getAgentInfos().size();
}
return agentCount;
return applicationAgentLists.stream()
.mapToInt(applicationAgentList -> applicationAgentList.getAgentInfos().size())
.sum();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkData;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap;
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.AgentInfo;
import com.navercorp.pinpoint.web.vo.Application;

Expand Down Expand Up @@ -58,16 +59,17 @@ ServerInstanceList createWasNodeInstanceListFromHistogram(Node wasNode, Instant
}

final ServerBuilder builder = new ServerBuilder();
final Set<AgentInfo> agentInfoSet = new HashSet<>();
final Set<AgentAndStatus> agentInfoSet = new HashSet<>();
final NodeHistogram nodeHistogram = wasNode.getNodeHistogram();
if (nodeHistogram != null && nodeHistogram.getAgentHistogramMap() != null) {
for (String agentId : nodeHistogram.getAgentHistogramMap().keySet()) {
AgentInfo agentInfo = new AgentInfo();
agentInfo.setAgentId(agentId);
agentInfo.setHostName(agentId);
agentInfo.setIp("");
agentInfo.setAgentName("");
agentInfo.setServiceType(wasNode.getServiceType());
agentInfoSet.add(agentInfo);
agentInfoSet.add(new AgentAndStatus(agentInfo));
}
}
builder.addAgentInfo(agentInfoSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram;
import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory;
import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.AgentInfo;
import com.navercorp.pinpoint.web.vo.AgentStatus;
import com.navercorp.pinpoint.web.vo.AgentStatusQuery;
Expand All @@ -41,6 +42,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author HyunGil Jeong
Expand Down Expand Up @@ -75,8 +77,12 @@ public ServerInstanceList createServerInstanceList(Node node, Instant timestamp)
agentInfos = filterAgentInfos(agentInfos, timestamp, node);
logger.debug("add agentInfos {} : {}", application, agentInfos);

Set<AgentAndStatus> agentAndStatusSet = agentInfos.stream()
.map(AgentAndStatus::new)
.collect(Collectors.toSet());

ServerBuilder builder = new ServerBuilder(hyperLinkFactory);
builder.addAgentInfo(agentInfos);
builder.addAgentInfo(agentAndStatusSet);
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.navercorp.pinpoint.web.hyperlink.HyperLink;
import com.navercorp.pinpoint.web.hyperlink.HyperLinkFactory;
import com.navercorp.pinpoint.web.hyperlink.LinkSources;
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.AgentInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -42,7 +43,7 @@ public class ServerBuilder {
private final Logger logger = LogManager.getLogger(this.getClass());

private final AgentHistogramList agentHistogramList = new AgentHistogramList();
private final Set<AgentInfo> agentSet = new HashSet<>();
private final Set<AgentAndStatus> agentSet = new HashSet<>();
private final HyperLinkFactory hyperLinkFactory;

public ServerBuilder() {
Expand All @@ -60,7 +61,7 @@ public void addCallHistogramList(AgentHistogramList agentHistogramList) {
this.agentHistogramList.addAgentHistogram(agentHistogramList);
}

public void addAgentInfo(Set<AgentInfo> agentInfo) {
public void addAgentInfo(Set<AgentAndStatus> agentInfo) {
if (agentInfo == null) {
return;
}
Expand Down Expand Up @@ -102,10 +103,10 @@ public ServerInstanceList buildLogicalServer(final AgentHistogramList hostHistog
return serverInstanceList;
}

public ServerInstanceList buildPhysicalServer(final Set<AgentInfo> agentSet) {
public ServerInstanceList buildPhysicalServer(final Set<AgentAndStatus> agentSet) {
final ServerInstanceList serverInstanceList = new ServerInstanceList();
for (AgentInfo agent : agentSet) {
final ServerInstance serverInstance = new ServerInstance(agent, buildHyperLink(agent));
for (AgentAndStatus agentAndStatus : agentSet) {
final ServerInstance serverInstance = new ServerInstance(agentAndStatus.getAgentInfo(), agentAndStatus.getStatus(), buildHyperLink(agentAndStatus.getAgentInfo()));
serverInstanceList.addServerInstance(serverInstance);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,24 @@ public class ServerInstance {

private final List<HyperLink> linkList;

public ServerInstance(AgentInfo agentInfo, List<HyperLink> linkList) {
public ServerInstance(AgentInfo agentInfo, AgentStatus agentStatus, List<HyperLink> linkList) {
Objects.requireNonNull(agentInfo, "agentInfo");

this.hostName = agentInfo.getHostName();
this.ip = agentInfo.getIp();
this.name = agentInfo.getAgentId();
this.agentName = agentInfo.getAgentName();
this.serviceType = agentInfo.getServiceType();
AgentStatus agentStatus = agentInfo.getStatus();
this.status = getAgentLifeCycleState(agentStatus);
this.serverType = ServerType.Physical;
this.linkList = Objects.requireNonNull(linkList, "linkList");
}

private AgentLifeCycleState getAgentLifeCycleState(AgentStatus agentStatus) {
if (agentStatus != null) {
this.status = agentStatus.getState();
return agentStatus.getState();
} else {
this.status = AgentLifeCycleState.UNKNOWN;
return AgentLifeCycleState.UNKNOWN;
}
this.serverType = ServerType.Physical;
this.linkList = Objects.requireNonNull(linkList, "linkList");
}

public ServerInstance(String hostName, String physicalName, ServiceType serviceType, List<HyperLink> linkList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand Down Expand Up @@ -54,10 +55,15 @@ public List<String> getAgentIdList() {
}

public Map<String, String> getAgentIdNameMap() {
Collection<List<ServerInstance>> serverList = this.serverInstanceList.values();
return serverList.stream()
.flatMap(List::stream)
.collect(Collectors.toMap(ServerInstance::getName, ServerInstance::getAgentName));
// Stream is not recommended
final Map<String, String> map = new HashMap<>();
for (List<ServerInstance> serverInstanceList : this.serverInstanceList.values()) {
for (ServerInstance serverInstance : serverInstanceList) {
// NPE
map.put(serverInstance.getName(), serverInstance.getAgentName());
}
}
return map;
}

public int getInstanceCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.navercorp.pinpoint.common.util.IdValidateUtils;
import com.navercorp.pinpoint.web.service.AgentEventService;
import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.AgentEvent;
import com.navercorp.pinpoint.web.vo.AgentInfo;
import com.navercorp.pinpoint.web.vo.AgentInfoFilter;
Expand Down Expand Up @@ -107,7 +108,7 @@ public ApplicationAgentsList getAgentList(
}

@GetMapping(value = "/getAgentInfo")
public AgentInfo getAgentInfo(
public AgentAndStatus getAgentInfo(
@RequestParam("agentId") String agentId,
@RequestParam("timestamp") long timestamp) {
return this.agentInfoService.getAgentInfo(agentId, timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.navercorp.pinpoint.common.server.cluster.ClusterKey;
import com.navercorp.pinpoint.web.vo.AgentInfo;
import com.navercorp.pinpoint.web.vo.AgentAndStatus;

import java.util.Objects;

Expand All @@ -13,9 +14,9 @@ public static ClusterKey from(AgentInfo agentInfo) {
return new ClusterKey(agentInfo.getApplicationName(), agentInfo.getAgentId(), agentInfo.getStartTimestamp());
}

public static ClusterKeyAndStatus withStatusFrom(AgentInfo agentInfo) {
Objects.requireNonNull(agentInfo, "agentInfo");
ClusterKey clusterKey = from(agentInfo);
return new ClusterKeyAndStatus(clusterKey, agentInfo.getStatus());
public static ClusterKeyAndStatus withStatusFrom(AgentAndStatus agentInfoAndStatus) {
Objects.requireNonNull(agentInfoAndStatus, "agentInfoAndStatus");
ClusterKey clusterKey = from(agentInfoAndStatus.getAgentInfo());
return new ClusterKeyAndStatus(clusterKey, agentInfoAndStatus.getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,11 @@ public NodeHistogramSummary getResponseTimeHistogramDataV2(

Application application = applicationFactory.createApplication(applicationName, serviceTypeCode);

List<Application> fromApplications = new ArrayList<>(fromApplicationNames.size());
for (int i = 0; i < fromApplicationNames.size(); i++) {
Application fromApplication = applicationFactory.createApplication(fromApplicationNames.get(i), fromServiceTypeCodes.get(i));
fromApplications.add(fromApplication);
}
List<Application> toApplications = new ArrayList<>(toApplicationNames.size());
for (int i = 0; i < toApplicationNames.size(); i++) {
Application toApplication = applicationFactory.createApplication(toApplicationNames.get(i), toServiceTypeCodes.get(i));
toApplications.add(toApplication);
}
final ResponseTimeHistogramServiceOption option = new ResponseTimeHistogramServiceOption.Builder(application, range, fromApplications, toApplications).setUseStatisticsAgentState(useStatisticsAgentState).build();
List<Application> fromApplications = toApplications(fromApplicationNames, fromServiceTypeCodes);
List<Application> toApplications = toApplications(toApplicationNames, toServiceTypeCodes);
final ResponseTimeHistogramServiceOption option = new ResponseTimeHistogramServiceOption.Builder(application, range, fromApplications, toApplications)
.setUseStatisticsAgentState(useStatisticsAgentState)
.build();

final NodeHistogramSummary nodeHistogramSummary = responseTimeHistogramService.selectNodeHistogramData(option);
if (useLoadHistogramFormat) {
Expand All @@ -315,6 +309,15 @@ public NodeHistogramSummary getResponseTimeHistogramDataV2(
return nodeHistogramSummary;
}

private List<Application> toApplications(List<String> applicationNames, List<Short> serviceTypeCodes) {
List<Application> result = new ArrayList<>(applicationNames.size());
for (int i = 0; i < applicationNames.size(); i++) {
Application application = applicationFactory.createApplication(applicationNames.get(i), serviceTypeCodes.get(i));
result.add(application);
}
return result;
}

private List<Application> mapApplicationPairsToApplications(List<ApplicationPair> applicationPairs) {
if (CollectionUtils.isEmpty(applicationPairs)) {
return Collections.emptyList();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.navercorp.pinpoint.web.service;

import com.navercorp.pinpoint.web.vo.AgentInfo;
import com.navercorp.pinpoint.web.vo.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.AgentInfoFilter;
import com.navercorp.pinpoint.web.vo.AgentStatus;
import com.navercorp.pinpoint.web.vo.AgentStatusQuery;
Expand All @@ -43,13 +44,13 @@ public interface AgentInfoService {

ApplicationAgentHostList getApplicationAgentHostList(int offset, int limit, int durationDays);

Set<AgentInfo> getAgentsByApplicationName(String applicationName, long timestamp);
Set<AgentAndStatus> getAgentsByApplicationName(String applicationName, long timestamp);

Set<AgentInfo> getAgentsByApplicationNameWithoutStatus(String applicationName, long timestamp);

Set<AgentInfo> getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff);
Set<AgentAndStatus> getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff);

AgentInfo getAgentInfo(String agentId, long timestamp);
AgentAndStatus getAgentInfo(String agentId, long timestamp);

AgentInfo getAgentInfoWithoutStatus(String agentId, long timestamp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.AgentInfoFilter;
import com.navercorp.pinpoint.web.vo.AgentStatus;
import com.navercorp.pinpoint.web.vo.AgentStatusQuery;
Expand Down Expand Up @@ -117,12 +118,12 @@ public ApplicationAgentsList getApplicationAgentsList(ApplicationAgentsList.Grou
Objects.requireNonNull(applicationName, "applicationName");

ApplicationAgentsList applicationAgentsList = new ApplicationAgentsList(groupBy, filter, hyperLinkFactory);
Set<AgentInfo> agentInfos = getAgentsByApplicationName(applicationName, timestamp);
if (agentInfos.isEmpty()) {
Set<AgentAndStatus> agentInfoAnsStatuss = getAgentsByApplicationName(applicationName, timestamp);
if (agentInfoAnsStatuss.isEmpty()) {
logger.warn("agent list is empty for application:{}", applicationName);
return applicationAgentsList;
}
applicationAgentsList.addAll(agentInfos);
applicationAgentsList.addAll(agentInfoAnsStatuss);
if (logger.isDebugEnabled()) {
logger.debug("getApplicationAgentsList={}", applicationAgentsList);
}
Expand Down Expand Up @@ -218,20 +219,20 @@ private List<String> getApplicationNameList(List<Application> applications) {
}

@Override
public Set<AgentInfo> getAgentsByApplicationName(String applicationName, long timestamp) {
public Set<AgentAndStatus> getAgentsByApplicationName(String applicationName, long timestamp) {
List<AgentInfo> agentInfos = this.getAgentsByApplicationNameWithoutStatus0(applicationName, timestamp);

List<AgentAndStatus> result = new ArrayList<>(agentInfos.size());

AgentStatusQuery query = AgentStatusQuery.buildQuery(agentInfos, Instant.ofEpochMilli(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());
}
AgentInfo agentInfo = agentInfos.get(i);
result.add(new AgentAndStatus(agentInfo, status.orElse(null)));
}
return new HashSet<>(agentInfos);

return new HashSet<>(result);
}


Expand All @@ -257,33 +258,35 @@ public List<AgentInfo> getAgentsByApplicationNameWithoutStatus0(String applicati
}

@Override
public Set<AgentInfo> getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff) {
public Set<AgentAndStatus> getRecentAgentsByApplicationName(String applicationName, long timestamp, long timeDiff) {
if (timeDiff > timestamp) {
throw new IllegalArgumentException("timeDiff must not be greater than timestamp");
}

Set<AgentInfo> unfilteredAgentInfos = this.getAgentsByApplicationName(applicationName, timestamp);
Set<AgentAndStatus> unfilteredAgentInfos = this.getAgentsByApplicationName(applicationName, timestamp);

final long eventTimestampFloor = timestamp - timeDiff;

Set<AgentInfo> filteredAgentInfos = new HashSet<>();
for (AgentInfo agentInfo : unfilteredAgentInfos) {
AgentStatus agentStatus = agentInfo.getStatus();
Set<AgentAndStatus> filteredAgentInfos = new HashSet<>();
for (AgentAndStatus agentInfoAndStatus : unfilteredAgentInfos) {
AgentStatus agentStatus = agentInfoAndStatus.getStatus();
if (AgentLifeCycleState.UNKNOWN == agentStatus.getState() || eventTimestampFloor <= agentStatus.getEventTimestamp()) {
filteredAgentInfos.add(agentInfo);
filteredAgentInfos.add(agentInfoAndStatus);
}
}
return filteredAgentInfos;
}

@Override
public AgentInfo getAgentInfo(String agentId, long timestamp) {
public AgentAndStatus getAgentInfo(String agentId, long timestamp) {

AgentInfo agentInfo = getAgentInfoWithoutStatus(agentId, timestamp);
if (agentInfo != null) {
Optional<AgentStatus> agentStatus = this.agentLifeCycleDao.getAgentStatus(agentInfo.getAgentId(), agentInfo.getStartTimestamp(), timestamp);
agentInfo.setStatus(agentStatus.orElse(null));
if (agentInfo == null) {
return null;
}
return agentInfo;

Optional<AgentStatus> agentStatus = this.agentLifeCycleDao.getAgentStatus(agentInfo.getAgentId(), agentInfo.getStartTimestamp(), timestamp);
return new AgentAndStatus(agentInfo, agentStatus.orElse(null));
}

@Override
Expand Down
Loading

0 comments on commit 827be6d

Please # to comment.