Skip to content

Commit

Permalink
[pinpoint-apm#8934] Filter agent list to sure that the agent is truly…
Browse files Browse the repository at this point in the history
… active
  • Loading branch information
intr3p1d committed Nov 29, 2022
1 parent e206e35 commit 25ef996
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public TreeView<TreeNode<AgentAndStatus>> getAgentList(
@RequestParam("to") long to) {
AgentInfoFilter filter = new DefaultAgentInfoFilter(from);
long timestamp = to;
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(filter, timestamp);
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(filter, Range.between(from, to));
return treeView(allAgentsList);
}


@GetMapping(value = "/getAgentList", params = {"!application", "timestamp"})
public TreeView<TreeNode<AgentAndStatus>> getAgentList(
@RequestParam("timestamp") long timestamp) {
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(AgentInfoFilter::accept, timestamp);
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(AgentInfoFilter::accept, Range.between(timestamp, timestamp));
return treeView(allAgentsList);
}

Expand All @@ -108,7 +108,7 @@ public TreeView<TreeNode<AgentStatusAndLink>> getAgentList(
new DefaultAgentInfoFilter(from)
);
long timestamp = to;
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(currentRunFilter, applicationName, timestamp);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(currentRunFilter, applicationName, Range.between(from, to));
return treeView(list);
}

Expand All @@ -119,7 +119,7 @@ public TreeView<TreeNode<AgentStatusAndLink>> getAgentList(
AgentInfoFilter runningAgentFilter = new AgentInfoFilterChain(
AgentInfoFilter::filterRunning
);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(runningAgentFilter, applicationName, timestamp);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(runningAgentFilter, applicationName, Range.between(timestamp, timestamp));
return treeView(list);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.navercorp.pinpoint.web.authorization.controller;

import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.view.tree.StaticTreeView;
import com.navercorp.pinpoint.web.view.tree.TreeView;
Expand Down Expand Up @@ -35,7 +36,7 @@ public AgentListController(AgentInfoService agentInfoService) {
@GetMapping(value = "/search-all")
public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList() {
long timestamp = System.currentTimeMillis();
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(AgentInfoFilter::accept, timestamp);
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(AgentInfoFilter::accept, Range.between(timestamp, timestamp));
return treeView(allAgentsList);
}

Expand All @@ -44,8 +45,7 @@ public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList(
@RequestParam("from") long from,
@RequestParam("to") long to) {
AgentInfoFilter filter = new DefaultAgentInfoFilter(from);
long timestamp = to;
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(filter, timestamp);
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(filter, Range.between(from, to));
return treeView(allAgentsList);
}

Expand All @@ -63,7 +63,7 @@ public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
AgentInfoFilter runningAgentFilter = new AgentInfoFilterChain(
AgentInfoFilter::filterRunning
);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(runningAgentFilter, applicationName, timestamp, sortBy);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(runningAgentFilter, applicationName, Range.between(timestamp, timestamp), sortBy);
return treeView(list);
}

Expand All @@ -76,8 +76,7 @@ public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
AgentInfoFilter currentRunFilter = new AgentInfoFilterChain(
new DefaultAgentInfoFilter(from)
);
long timestamp = to;
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(currentRunFilter, applicationName, timestamp, sortBy);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(currentRunFilter, applicationName, Range.between(from, to), sortBy);
return treeView(list);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public interface AgentInfoService {

int NO_DURATION = -1;

AgentsMapByApplication getAllAgentsList(AgentInfoFilter filter, long timestamp);
AgentsMapByApplication getAllAgentsList(AgentInfoFilter filter, Range range);

AgentsMapByHost getAgentsListByApplicationName(AgentInfoFilter filter, String applicationName, long timestamp);
AgentsMapByHost getAgentsListByApplicationName(AgentInfoFilter filter, String applicationName, Range range);

AgentsMapByHost getAgentsListByApplicationName(AgentInfoFilter filter, String applicationName, long timestamp, SortByAgentInfo.Rules sortBy);
AgentsMapByHost getAgentsListByApplicationName(AgentInfoFilter filter, String applicationName, Range range, SortByAgentInfo.Rules sortBy);

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

Expand Down
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.bootstrap.Agent;
import com.navercorp.pinpoint.common.server.bo.stat.JvmGcBo;
import com.navercorp.pinpoint.common.server.util.AgentEventType;
import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState;
Expand All @@ -33,6 +34,7 @@
import com.navercorp.pinpoint.web.vo.agent.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentInfo;
import com.navercorp.pinpoint.web.vo.agent.AgentInfoFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentInfoFilterChain;
import com.navercorp.pinpoint.web.vo.agent.AgentStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusAndLink;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusQuery;
Expand All @@ -56,6 +58,7 @@
import java.time.Instant;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
Expand Down Expand Up @@ -105,13 +108,13 @@ public AgentInfoServiceImpl(AgentEventService agentEventService,
}

@Override
public AgentsMapByApplication getAllAgentsList(AgentInfoFilter filter, long timestamp) {
public AgentsMapByApplication getAllAgentsList(AgentInfoFilter filter, Range range) {
Objects.requireNonNull(filter, "filter");

List<Application> applications = applicationIndexDao.selectAllApplicationNames();
List<AgentAndStatus> agents = new ArrayList<>();
for (Application application : applications) {
agents.addAll(getAgentsByApplicationName(application.getName(), timestamp));
agents.addAll(getAgentsByApplicationName(application.getName(), range.getTo()));
}

return AgentsMapByApplication.newAgentsMapByApplication(
Expand All @@ -121,27 +124,34 @@ public AgentsMapByApplication getAllAgentsList(AgentInfoFilter filter, long time
}

@Override
public AgentsMapByHost getAgentsListByApplicationName(AgentInfoFilter filter, String applicationName, long timestamp) {
return getAgentsListByApplicationName(filter, applicationName, timestamp, SortByAgentInfo.Rules.AGENT_ID_ASC);
public AgentsMapByHost getAgentsListByApplicationName(AgentInfoFilter filter, String applicationName, Range range) {
return getAgentsListByApplicationName(filter, applicationName, range, SortByAgentInfo.Rules.AGENT_ID_ASC);
}

@Override
public AgentsMapByHost getAgentsListByApplicationName(AgentInfoFilter filter,
String applicationName,
long timestamp,
Range range,
SortByAgentInfo.Rules sortBy) {
Objects.requireNonNull(filter, "filter");
Objects.requireNonNull(applicationName, "applicationName");

Set<AgentAndStatus> agentInfoAndStatuses = getAgentsByApplicationName(applicationName, timestamp);
Set<AgentAndStatus> agentInfoAndStatuses = getAgentsByApplicationName(applicationName, range.getTo());
AgentInfoFilter activeAgentFilter = new AgentInfoFilterChain(
filter,
x -> isActiveAgent(x.getAgentInfo().getAgentId(), range)
);

if (agentInfoAndStatuses.isEmpty()) {
logger.warn("agent list is empty for application:{}", applicationName);
}

AgentsMapByHost agentsMapByHost = AgentsMapByHost.newAgentsMapByHost(filter,
AgentsMapByHost agentsMapByHost = AgentsMapByHost.newAgentsMapByHost(
activeAgentFilter,
SortByAgentInfo.agentIdAsc(AgentStatusAndLink::getAgentInfo),
hyperLinkFactory,
agentInfoAndStatuses);
agentInfoAndStatuses
);

logger.debug("getAgentsMapByHostname={}", agentsMapByHost);
return agentsMapByHost;
Expand Down Expand Up @@ -225,12 +235,11 @@ private List<String> getAgentIdList(String applicationName, int durationDays) {
}

private List<String> getApplicationNameList(List<Application> applications) {
List<String> applicationNameList = applications.stream()
return applications.stream()
.map(Application::getName)
.distinct()
.sorted(Comparator.naturalOrder())
.collect(Collectors.toList());
return applicationNameList;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public AgentInfoFilterChain(AgentInfoFilter... agentInfoFilters) {
@Override
public boolean filter(AgentAndStatus agentAndStatus) {
for (AgentInfoFilter agentFilter : this.agentInfoFilters) {
if (agentFilter.filter(agentAndStatus) == ACCEPT) {
return ACCEPT;
if (agentFilter.filter(agentAndStatus) == REJECT) {
return REJECT;
}
}
return REJECT;
return ACCEPT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void filter_running() {

AgentInfoFilter chain = new AgentInfoFilterChain(
AgentInfoFilter::filterRunning,
AgentInfoFilter::reject
AgentInfoFilter::accept
);

AgentStatus status = new AgentStatus("testAgent", AgentLifeCycleState.RUNNING, current);
Expand Down

0 comments on commit 25ef996

Please sign in to comment.