Skip to content

Commit

Permalink
[#10865] Added param
Browse files Browse the repository at this point in the history
  • Loading branch information
smilu97 committed Apr 9, 2024
1 parent 86f8f20 commit 4daa496
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.navercorp.pinpoint.web.authorization.controller;

import com.google.common.base.Predicates;
import com.navercorp.pinpoint.common.PinpointConstants;
import com.navercorp.pinpoint.common.server.util.AgentEventType;
import com.navercorp.pinpoint.common.server.util.time.Range;
Expand All @@ -31,8 +32,7 @@
import com.navercorp.pinpoint.web.vo.agent.AgentStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusAndLink;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilterChain;
import com.navercorp.pinpoint.web.vo.agent.DefaultAgentStatusFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilters;
import com.navercorp.pinpoint.web.vo.agent.DetailedAgentAndStatus;
import com.navercorp.pinpoint.web.vo.timeline.inspector.InspectorTimeline;
import com.navercorp.pinpoint.web.vo.tree.AgentsMapByApplication;
Expand Down Expand Up @@ -81,7 +81,7 @@ public TreeView<TreeNode<AgentAndStatus>> getAgentList() {
public TreeView<TreeNode<AgentAndStatus>> getAgentList(
@RequestParam("from") @PositiveOrZero long from,
@RequestParam("to") @PositiveOrZero long to) {
final AgentStatusFilter filter = new DefaultAgentStatusFilter(from);
final AgentStatusFilter filter = AgentStatusFilters.common(from);
final AgentsMapByApplication<AgentAndStatus> allAgentsList =
this.agentInfoService.getAllAgentsList(filter, Range.between(from, to));
return treeView(allAgentsList);
Expand All @@ -92,7 +92,7 @@ public TreeView<TreeNode<AgentAndStatus>> getAgentList(
public TreeView<TreeNode<AgentAndStatus>> getAgentList(
@RequestParam("timestamp") @PositiveOrZero long timestamp) {
final AgentsMapByApplication<AgentAndStatus> allAgentsList =
this.agentInfoService.getAllAgentsList(AgentStatusFilter::accept, Range.between(timestamp, timestamp));
this.agentInfoService.getAllAgentsList(Predicates.alwaysTrue(), Range.between(timestamp, timestamp));
return treeView(allAgentsList);
}

Expand All @@ -114,7 +114,7 @@ public TreeView<TreeNode<AgentStatusAndLink>> getAgentList(
@RequestParam("application") @NotBlank String applicationName,
@RequestParam("from") @PositiveOrZero long from,
@RequestParam("to") @PositiveOrZero long to) {
final AgentStatusFilter currentRunFilter = new AgentStatusFilterChain(new DefaultAgentStatusFilter(from));
final AgentStatusFilter currentRunFilter = AgentStatusFilters.common(from);
final AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(
currentRunFilter,
applicationName,
Expand All @@ -128,9 +128,8 @@ public TreeView<TreeNode<AgentStatusAndLink>> getAgentList(
public TreeView<TreeNode<AgentStatusAndLink>> getAgentList(
@RequestParam("application") @NotBlank String applicationName,
@RequestParam("timestamp") @PositiveOrZero long timestamp) {
final AgentStatusFilter runningAgentFilter = new AgentStatusFilterChain(AgentStatusFilter::filterRunning);
final AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(
runningAgentFilter,
AgentStatusFilters.running(),
applicationName,
Range.between(timestamp, timestamp),
DEFAULT_SORT_BY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import com.navercorp.pinpoint.web.vo.agent.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusAndLink;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilterChain;
import com.navercorp.pinpoint.web.vo.agent.DefaultAgentStatusFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilters;
import com.navercorp.pinpoint.web.vo.agent.DetailedAgentInfo;
import com.navercorp.pinpoint.web.vo.tree.AgentsMapByApplication;
import com.navercorp.pinpoint.web.vo.tree.AgentsMapByHost;
Expand Down Expand Up @@ -45,7 +44,7 @@ public AgentListController(AgentInfoService agentInfoService) {
public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList() {
final long timestamp = System.currentTimeMillis();
final AgentsMapByApplication<AgentAndStatus> allAgentsList = this.agentInfoService.getAllAgentsList(
AgentStatusFilter::accept,
agentStatus -> true,
Range.between(timestamp, timestamp)
);
return treeView(allAgentsList);
Expand All @@ -55,7 +54,7 @@ public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList() {
public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList(
@RequestParam("from") @PositiveOrZero long from,
@RequestParam("to") @PositiveOrZero long to) {
final AgentStatusFilter filter = new DefaultAgentStatusFilter(from);
final AgentStatusFilter filter = AgentStatusFilters.common(from);
final AgentsMapByApplication<AgentAndStatus> allAgentsList = this.agentInfoService.getAllAgentsList(
filter,
Range.between(from, to)
Expand All @@ -71,12 +70,13 @@ private static <T> TreeView<InstancesList<T>> treeView(AgentsMapByApplication<T>
@GetMapping(value = "/search-application", params = {"application"})
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
@RequestParam("application") @NotBlank String applicationName,
@RequestParam(value = "serviceTypeName", required = false) String serviceTypeName,
@RequestParam(value = "sortBy") Optional<SortByAgentInfo.Rules> sortBy) {
final SortByAgentInfo.Rules paramSortBy = sortBy.orElse(DEFAULT_SORT_BY);
final long timestamp = System.currentTimeMillis();
final AgentStatusFilter runningAgentFilter = new AgentStatusFilterChain(AgentStatusFilter::filterRunning);
final AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(
runningAgentFilter,
AgentStatusFilters.running(),
agentInfo -> serviceTypeName == null || agentInfo.getServiceType().getName().equals(serviceTypeName),
applicationName,
Range.between(timestamp, timestamp),
paramSortBy
Expand All @@ -87,15 +87,15 @@ public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
@GetMapping(value = "/search-application", params = {"application", "from", "to"})
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
@RequestParam("application") @NotBlank String applicationName,
@RequestParam(value = "serviceTypeName", required = false) String serviceTypeName,
@RequestParam("from") @PositiveOrZero long from,
@RequestParam("to") @PositiveOrZero long to,
@RequestParam(value = "sortBy") Optional<SortByAgentInfo.Rules> sortBy) {
final SortByAgentInfo.Rules paramSortBy = sortBy.orElse(DEFAULT_SORT_BY);
final AgentStatusFilter currentRunFilter = new AgentStatusFilterChain(
new DefaultAgentStatusFilter(from)
);
final AgentStatusFilter currentRunFilter = AgentStatusFilters.common(from);
final AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(
currentRunFilter,
agentInfo -> serviceTypeName == null || agentInfo.getServiceType().getName().equals(serviceTypeName),
applicationName,
Range.between(from, to),
paramSortBy
Expand All @@ -113,7 +113,7 @@ public TreeView<InstancesList<DetailedAgentInfo>> getAllAgentStatistics() {
final long timestamp = System.currentTimeMillis();
final AgentsMapByApplication<DetailedAgentInfo> allAgentsList =
this.agentInfoService.getAllAgentsStatisticsList(
AgentStatusFilter::accept,
agentStatus -> true,
Range.between(timestamp, timestamp)
);
return treeView(allAgentsList);
Expand All @@ -126,7 +126,7 @@ public TreeView<InstancesList<DetailedAgentInfo>> getAllAgentStatistics(
) {
final AgentsMapByApplication<DetailedAgentInfo> allAgentsList =
this.agentInfoService.getAllAgentsStatisticsList(
AgentStatusFilter::accept,
agentStatus -> true,
Range.between(from, to)
);
return treeView(allAgentsList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.vo.agent.AgentInfo;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusAndLink;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilterChain;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilters;
import com.navercorp.pinpoint.web.vo.tree.AgentsMapByHost;
import com.navercorp.pinpoint.web.vo.tree.InstancesList;
import com.navercorp.pinpoint.web.vo.tree.SortByAgentInfo;
Expand All @@ -49,7 +48,7 @@ class AgentLookupServiceImpl implements AgentLookupService {
public List<ClusterKey> getRecentAgents(String applicationName) {
final long now = System.currentTimeMillis();
return intoClusterKeyList(this.agentInfoService.getAgentsListByApplicationName(
new AgentStatusFilterChain(AgentStatusFilter::filterRunning),
AgentStatusFilters.running(),
applicationName,
Range.between(now - recentness.toMillis(), now),
SortByAgentInfo.Rules.AGENT_NAME_ASC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.navercorp.pinpoint.web.vo.agent.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentInfo;
import com.navercorp.pinpoint.web.vo.agent.AgentStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusQuery;
import com.navercorp.pinpoint.web.vo.agent.DetailedAgentAndStatus;
import com.navercorp.pinpoint.web.vo.agent.DetailedAgentInfo;
Expand All @@ -33,6 +32,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

/**
* @author netspider
Expand All @@ -42,11 +42,12 @@ public interface AgentInfoService {

int NO_DURATION = -1;

AgentsMapByApplication<AgentAndStatus> getAllAgentsList(AgentStatusFilter filter, Range range);
AgentsMapByApplication<AgentAndStatus> getAllAgentsList(Predicate<AgentStatus> filter, Range range);

AgentsMapByApplication<DetailedAgentInfo> getAllAgentsStatisticsList(AgentStatusFilter filter, Range range);
AgentsMapByApplication<DetailedAgentInfo> getAllAgentsStatisticsList(Predicate<AgentStatus> filter, Range range);

AgentsMapByHost getAgentsListByApplicationName(AgentStatusFilter filter, String applicationName, Range range, SortByAgentInfo.Rules sortBy);
AgentsMapByHost getAgentsListByApplicationName(Predicate<AgentStatus> agentStatusPredicate, Predicate<AgentInfo> agentInfoPredicate, String applicationName, Range range, SortByAgentInfo.Rules sortBy);
AgentsMapByHost getAgentsListByApplicationName(Predicate<AgentStatus> agentStatusPredicate, 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 @@ -33,8 +33,6 @@
import com.navercorp.pinpoint.web.vo.agent.AgentInfo;
import com.navercorp.pinpoint.web.vo.agent.AgentStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusAndLink;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilterChain;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusQuery;
import com.navercorp.pinpoint.web.vo.agent.DetailedAgentAndStatus;
import com.navercorp.pinpoint.web.vo.agent.DetailedAgentInfo;
Expand Down Expand Up @@ -64,6 +62,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -105,7 +104,7 @@ public AgentInfoServiceImpl(AgentEventService agentEventService,
}

@Override
public AgentsMapByApplication<AgentAndStatus> getAllAgentsList(AgentStatusFilter filter, Range range) {
public AgentsMapByApplication<AgentAndStatus> getAllAgentsList(Predicate<AgentStatus> filter, Range range) {
Objects.requireNonNull(filter, "filter");

List<Application> applications = applicationIndexDao.selectAllApplicationNames();
Expand All @@ -121,7 +120,7 @@ public AgentsMapByApplication<AgentAndStatus> getAllAgentsList(AgentStatusFilter
}

@Override
public AgentsMapByApplication<DetailedAgentInfo> getAllAgentsStatisticsList(AgentStatusFilter filter, Range range) {
public AgentsMapByApplication<DetailedAgentInfo> getAllAgentsStatisticsList(Predicate<AgentStatus> filter, Range range) {
Objects.requireNonNull(filter, "filter");

List<Application> applications = applicationIndexDao.selectAllApplicationNames();
Expand All @@ -137,25 +136,25 @@ public AgentsMapByApplication<DetailedAgentInfo> getAllAgentsStatisticsList(Agen
}

@Override
public AgentsMapByHost getAgentsListByApplicationName(AgentStatusFilter filter,
public AgentsMapByHost getAgentsListByApplicationName(Predicate<AgentStatus> agentStatusPredicate,
Predicate<AgentInfo> agentInfoPredicate,
String applicationName,
Range range,
SortByAgentInfo.Rules sortBy) {
Objects.requireNonNull(filter, "filter");
Objects.requireNonNull(agentStatusPredicate, "agentStatusPredicate");
Objects.requireNonNull(agentInfoPredicate, "agentInfoPredicate");
Objects.requireNonNull(applicationName, "applicationName");

Set<AgentAndStatus> agentInfoAndStatuses = getAgentsByApplicationName(applicationName, range.getTo());
AgentStatusFilter activeAgentFilter = new AgentStatusFilterChain(
filter,
x -> isActiveAgent(x.getAgentId(), range)
);
Predicate<AgentStatus> activeAgentPredicate = x -> isActiveAgent(x.getAgentId(), range);

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

AgentsMapByHost agentsMapByHost = AgentsMapByHost.newAgentsMapByHost(
activeAgentFilter,
agentStatusPredicate.and(activeAgentPredicate),
agentInfoPredicate,
SortByAgentInfo.comparing(AgentStatusAndLink::getAgentInfo, sortBy.getRule()),
hyperLinkFactory,
agentInfoAndStatuses
Expand All @@ -165,6 +164,13 @@ public AgentsMapByHost getAgentsListByApplicationName(AgentStatusFilter filter,
return agentsMapByHost;
}

@Override
public AgentsMapByHost getAgentsListByApplicationName(Predicate<AgentStatus> agentStatusPredicate,
String applicationName,
Range range,
SortByAgentInfo.Rules sortBy) {
return getAgentsListByApplicationName(agentStatusPredicate, x -> true, applicationName, range, sortBy);
}

@Override
public ApplicationAgentHostList getApplicationAgentHostList(int offset, int limit, int durationDays) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
package com.navercorp.pinpoint.web.vo.agent;

import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState;
import java.util.function.Predicate;

public interface AgentStatusFilter {
boolean ACCEPT = true;
boolean REJECT = false;
public interface AgentStatusFilter extends Predicate<AgentStatus> {

boolean filter(AgentStatus agentStatus);

static boolean accept(AgentStatus agentStatus) {
return ACCEPT;
}

static boolean reject(AgentStatus agentStatus) {
return REJECT;
}

static boolean filterRunning(AgentStatus agentStatus) {
if (agentStatus == null) {
return REJECT;
}
if (agentStatus.getState() == AgentLifeCycleState.RUNNING) {
return ACCEPT;
}
return REJECT;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.navercorp.pinpoint.web.vo.agent;

import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState;

public class AgentStatusFilters {

private static final AgentStatusFilter RUNNING = new RunningAgentStatusFilter();

public static AgentStatusFilter running() {
return RUNNING;
}

public static AgentStatusFilter common(long minEventTimestamp) {
return new DefaultAgentStatusFilter(minEventTimestamp);
}

private static class RunningAgentStatusFilter implements AgentStatusFilter {
@Override
public boolean test(AgentStatus agentStatus) {
if (agentStatus == null) {
return false;
}
return agentStatus.getState() == AgentLifeCycleState.RUNNING;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ public DefaultAgentStatusFilter(long from) {
}

@Override
public boolean filter(AgentStatus agentStatus) {
public boolean test(AgentStatus agentStatus) {
if (agentStatus == null) {
return REJECT;
return false;
}
if (agentStatus.getState() == AgentLifeCycleState.RUNNING) {
return ACCEPT;
return true;
}
if (agentStatus.getEventTimestamp() >= from) {
return ACCEPT;
}
return REJECT;
return agentStatus.getEventTimestamp() >= from;
}

}
Loading

0 comments on commit 4daa496

Please sign in to comment.