Skip to content

Commit

Permalink
[#8934] Change existing agent list lookup policy
Browse files Browse the repository at this point in the history
Unify the policy for the physical server to the container.
  • Loading branch information
intr3p1d committed Jun 17, 2022
1 parent 3668b54 commit 3a11c3f
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* Callback handling scanner results.
* Implementations of this interface perform the actula work of extracting results from the
* Implementations of this interface perform the actual work of extracting results from the
* {@link ResultScanner} but without having to worry about exception handling or resource management.
*
* @author Costin Leau
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public ApplicationMap build(Application application, long timeoutMillis) {

Node node = new Node(nodeType, application);
if (serverInstanceListFactory != null) {
ServerInstanceList runningInstances = serverInstanceListFactory.createWasNodeInstanceList(node, range.getToInstant());
ServerInstanceList runningInstances = serverInstanceListFactory.createWasNodeInstanceList(node, range);
if (runningInstances.getInstanceCount() > 0) {
node.setServerInstanceList(runningInstances);
nodeList.addNode(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ private CompletableFuture<Void> getServerInstanceListFuture(Range range, Node no
CompletableFuture<ServerInstanceList> serverInstanceListFuture;
ServiceType nodeServiceType = node.getServiceType();
if (nodeServiceType.isWas()) {
final Instant to = range.getToInstant();
serverInstanceListFuture = CompletableFuture.supplyAsync(new Supplier<ServerInstanceList>() {
@Override
public ServerInstanceList get() {
if (Boolean.TRUE == stopSign.get()) { // Stop
return serverInstanceListFactory.createEmptyNodeInstanceList();
}
return serverInstanceListFactory.createWasNodeInstanceList(node, to);
return serverInstanceListFactory.createWasNodeInstanceList(node, range);
}
}, executor);
} else if (nodeServiceType.isTerminal() || nodeServiceType.isAlias()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.navercorp.pinpoint.web.applicationmap.appender.server;

import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.applicationmap.nodes.Node;
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerBuilder;
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList;
Expand All @@ -24,7 +25,6 @@
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap;
import com.navercorp.pinpoint.web.vo.Application;

import java.time.Instant;
import java.util.Objects;

/**
Expand All @@ -39,8 +39,8 @@ public DefaultServerInstanceListFactory(ServerInstanceListDataSource serverInsta
}

@Override
public ServerInstanceList createWasNodeInstanceList(Node wasNode, Instant timestamp) {
return serverInstanceListDataSource.createServerInstanceList(wasNode, timestamp);
public ServerInstanceList createWasNodeInstanceList(Node wasNode, Range range) {
return serverInstanceListDataSource.createServerInstanceList(wasNode, range);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@

package com.navercorp.pinpoint.web.applicationmap.appender.server;

import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.applicationmap.nodes.Node;
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap;

import java.time.Instant;

/**
* @author HyunGil Jeong
*/
public class EmptyServerInstanceListFactory implements ServerInstanceListFactory {

@Override
public ServerInstanceList createWasNodeInstanceList(Node wasNode, Instant timestamp) {
public ServerInstanceList createWasNodeInstanceList(Node wasNode, Range range) {
return new ServerInstanceList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@

package com.navercorp.pinpoint.web.applicationmap.appender.server;

import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.applicationmap.nodes.Node;
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList;
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataDuplexMap;

import java.time.Instant;

/**
* @author HyunGil Jeong
*/
public interface ServerInstanceListFactory {

ServerInstanceList createWasNodeInstanceList(Node wasNode, Instant timestamp);
ServerInstanceList createWasNodeInstanceList(Node wasNode, Range range);

ServerInstanceList createTerminalNodeInstanceList(Node terminalNode, LinkDataDuplexMap linkDataDuplexMap);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.navercorp.pinpoint.web.applicationmap.appender.server;

import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.applicationmap.appender.server.datasource.ServerInstanceListDataSource;
import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram;
import com.navercorp.pinpoint.web.applicationmap.nodes.Node;
Expand All @@ -42,11 +43,11 @@ public StatisticsServerInstanceListFactory(ServerInstanceListDataSource serverIn
}

@Override
public ServerInstanceList createWasNodeInstanceList(Node wasNode, Instant timestamp) {
ServerInstanceList serverInstanceList = createWasNodeInstanceListFromHistogram(wasNode, timestamp);
public ServerInstanceList createWasNodeInstanceList(Node wasNode, Range range) {
ServerInstanceList serverInstanceList = createWasNodeInstanceListFromHistogram(wasNode, range.getToInstant());
if (serverInstanceList.getServerInstanceList().isEmpty()) {
// When there is no transaction information, agentInfo information is used.
serverInstanceList = createWasNodeInstanceListFromAgentInfo(wasNode, timestamp);
serverInstanceList = createWasNodeInstanceListFromAgentInfo(wasNode, range);
}
return serverInstanceList;
}
Expand Down Expand Up @@ -74,8 +75,8 @@ ServerInstanceList createWasNodeInstanceListFromHistogram(Node wasNode, Instant
return builder.build();
}

ServerInstanceList createWasNodeInstanceListFromAgentInfo(Node wasNode, Instant timestamp) {
return serverInstanceListDataSource.createServerInstanceList(wasNode, timestamp);
ServerInstanceList createWasNodeInstanceListFromAgentInfo(Node wasNode, Range range) {
return serverInstanceListDataSource.createServerInstanceList(wasNode, range);
}

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

package com.navercorp.pinpoint.web.applicationmap.appender.server.datasource;

import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState;
import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.applicationmap.nodes.Node;
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerBuilder;
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList;
import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram;
import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram;
import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.vo.AgentInfo;
import com.navercorp.pinpoint.web.vo.AgentInfoFilter;
import com.navercorp.pinpoint.web.vo.AgentInfoFilterChain;
import com.navercorp.pinpoint.web.vo.AgentStatus;
import com.navercorp.pinpoint.web.vo.AgentStatusQuery;
import com.navercorp.pinpoint.web.vo.Application;
import com.navercorp.pinpoint.web.vo.DefaultAgentInfoFilter;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.util.CollectionUtils;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
Expand All @@ -54,9 +53,10 @@ public AgentInfoServerInstanceListDataSource(AgentInfoService agentInfoService)
this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService");
}

public ServerInstanceList createServerInstanceList(Node node, Instant timestamp) {
public ServerInstanceList createServerInstanceList(Node node, Range range) {
Objects.requireNonNull(node, "node");
Objects.requireNonNull(timestamp, "timestamp");
Objects.requireNonNull(range, "timestamp");
Instant timestamp = range.getToInstant();
if (timestamp.toEpochMilli() < 0) {
return new ServerInstanceList();
}
Expand All @@ -69,7 +69,7 @@ public ServerInstanceList createServerInstanceList(Node node, Instant timestamp)
}

logger.debug("unfiltered agentInfos {}", agentInfos);
agentInfos = filterAgentInfos(agentInfos, timestamp, node);
agentInfos = filterAgentInfos(agentInfos, range, node);
logger.debug("add agentInfos {} : {}", application, agentInfos);

ServerBuilder builder = new ServerBuilder();
Expand All @@ -78,42 +78,26 @@ public ServerInstanceList createServerInstanceList(Node node, Instant timestamp)
}

// TODO Change to list of filters?
private Set<AgentInfo> filterAgentInfos(Set<AgentInfo> agentInfos, Instant timestamp, Node node) {

final Map<String, Histogram> agentHistogramMap = getAgentHistogramMap(node);

private Set<AgentInfo> filterAgentInfos(Set<AgentInfo> agentInfos, Range range, Node 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<AgentInfo> agentsToCheckStatus = new ArrayList<>(agentInfos);
AgentStatusQuery query = AgentStatusQuery.buildQuery(agentInfos, range.getToInstant());

List<Optional<AgentStatus>> agentStatusList = agentInfoService.getAgentStatus(query);
AgentInfoFilter filter = new AgentInfoFilterChain(
new DefaultAgentInfoFilter(range.getFrom())
);

int idx = 0;
for (AgentInfo agentInfo : agentsToCheckStatus) {
Optional<AgentStatus> agentStatus = agentStatusList.get(idx++);
if (agentStatus.isPresent()) {
if (agentStatus.get().getState() == AgentLifeCycleState.RUNNING) {
if (filter.filter(agentInfo) == AgentInfoFilter.ACCEPT) {
filteredAgentInfos.add(agentInfo);
}
}
}

return filteredAgentInfos;
}

private Map<String, Histogram> getAgentHistogramMap(Node node) {
NodeHistogram nodeHistogram = node.getNodeHistogram();
if (nodeHistogram != null) {
return nodeHistogram.getAgentHistogramMap();
}
return Collections.emptyMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@

package com.navercorp.pinpoint.web.applicationmap.appender.server.datasource;

import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.applicationmap.nodes.Node;
import com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstanceList;

import java.time.Instant;

/**
* @author emeroad
* @author minwoo.jung
* @author HyunGil Jeong
*/
public interface ServerInstanceListDataSource {

ServerInstanceList createServerInstanceList(Node node, Instant timestamp);
ServerInstanceList createServerInstanceList(Node node, Range range);
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public ApplicationAgentsList getAgentList(
@RequestParam("from") long from,
@RequestParam("to") long to) {
AgentInfoFilter containerFilter = new AgentInfoFilterChain(
AgentInfoFilter::filterServer,
new DefaultAgentInfoFilter(from)
);
long timestamp = to;
Expand All @@ -101,7 +100,6 @@ public ApplicationAgentsList getAgentList(
@RequestParam("application") String applicationName,
@RequestParam("timestamp") long timestamp) {
AgentInfoFilter runningContainerFilter = new AgentInfoFilterChain(
AgentInfoFilter::filterServer,
new DefaultAgentInfoFilter(Long.MAX_VALUE)
);
return this.agentInfoService.getApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, runningContainerFilter, applicationName, timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public NodeHistogramSummary selectNodeHistogramData(ResponseTimeHistogramService
if (applicationServiceType.isWas()) {
NodeHistogram nodeHistogram = nodeHistogramFactory.createWasNodeHistogram(option.getApplication(), option.getRange());
node.setNodeHistogram(nodeHistogram);
ServerInstanceList serverInstanceList = serverInstanceListFactory.createWasNodeInstanceList(node, option.getRange().getToInstant());
ServerInstanceList serverInstanceList = serverInstanceListFactory.createWasNodeInstanceList(node, option.getRange());
return new NodeHistogramSummary(serverInstanceList, nodeHistogram);
} else if (applicationServiceType.isTerminal() || applicationServiceType.isUnknown() || applicationServiceType.isAlias()) {
if (sourceApplications.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void wasNode() {
nodeList.addNode(wasNode);

ServerInstanceList serverInstanceList = new ServerInstanceList();
when(serverInstanceListDataSource.createServerInstanceList(wasNode, range.getToInstant())).thenReturn(serverInstanceList);
when(serverInstanceListDataSource.createServerInstanceList(wasNode, range)).thenReturn(serverInstanceList);
// When
serverInfoAppender.appendServerInfo(range, nodeList, linkDataDuplexMap, timeoutMillis);
// Then
Expand All @@ -136,9 +136,9 @@ public void wasNodes() {
nodeList.addNode(wasNode2);

ServerInstanceList serverInstanceList1 = new ServerInstanceList();
when(serverInstanceListDataSource.createServerInstanceList(wasNode1, range.getToInstant())).thenReturn(serverInstanceList1);
when(serverInstanceListDataSource.createServerInstanceList(wasNode1, range)).thenReturn(serverInstanceList1);
ServerInstanceList serverInstanceList2 = new ServerInstanceList();
when(serverInstanceListDataSource.createServerInstanceList(wasNode2, range.getToInstant())).thenReturn(serverInstanceList2);
when(serverInstanceListDataSource.createServerInstanceList(wasNode2, range)).thenReturn(serverInstanceList2);
// When
serverInfoAppender.appendServerInfo(range, nodeList, linkDataDuplexMap, timeoutMillis);
// Then
Expand Down

0 comments on commit 3a11c3f

Please sign in to comment.