Skip to content

Commit

Permalink
[pinpoint-apm#9317] Separate AgentListController
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d authored and BillionaireDY committed Dec 29, 2022
1 parent 166f04f commit bc0f809
Show file tree
Hide file tree
Showing 18 changed files with 292 additions and 89 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 @@ -22,6 +22,7 @@
import com.navercorp.pinpoint.web.authorization.controller.AgentCommandController;
import com.navercorp.pinpoint.web.authorization.controller.AgentDownloadController;
import com.navercorp.pinpoint.web.authorization.controller.AgentInfoController;
import com.navercorp.pinpoint.web.authorization.controller.AgentListController;
import com.navercorp.pinpoint.web.authorization.controller.AgentStatController;
import com.navercorp.pinpoint.web.authorization.controller.AlarmController;
import com.navercorp.pinpoint.web.authorization.controller.ApplicationDataSourceController;
Expand Down Expand Up @@ -68,6 +69,12 @@ public UserController createUserController(UserService userService) {
public AgentInfoController createAgentInfoController(AgentInfoService agentInfoService, AgentEventService agentEventService) {
return new AgentInfoController(agentInfoService, agentEventService);
}

@Bean
public AgentListController createAgentListController(AgentInfoService agentInfoService) {
return new AgentListController(agentInfoService);
}

@Bean
public AgentStatController<AgentStatDataPoint> createAgentStatController(List<AgentStatService> agentStatServiceList,
List<AgentStatChartService> agentStatChartServiceList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.navercorp.pinpoint.web;

import com.navercorp.pinpoint.web.vo.tree.SortByRequestConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
Expand Down Expand Up @@ -66,4 +68,9 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
.setCacheControl(CacheControl.noCache());
}

@Override
public void addFormatters(FormatterRegistry registry) {
WebMvcConfigurer.super.addFormatters(registry);
registry.addConverter(new SortByRequestConverter());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.navercorp.pinpoint.web.response.CodeResult;
import com.navercorp.pinpoint.web.service.AgentEventService;
import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.view.tree.TreeNode;
import com.navercorp.pinpoint.web.vo.AgentEvent;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusAndLink;
import com.navercorp.pinpoint.web.vo.tree.InstancesList;
Expand Down Expand Up @@ -64,13 +65,13 @@ public AgentInfoController(AgentInfoService agentInfoService, AgentEventService
}

@GetMapping(value = "/getAgentList", params = {"!application"})
public TreeView<AgentStatusAndLink> getAgentList() {
public TreeView<TreeNode<AgentAndStatus>> getAgentList() {
long timestamp = System.currentTimeMillis();
return getAgentList(timestamp);
}

@GetMapping(value = "/getAgentList", params = {"!application", "from", "to"})
public TreeView<AgentStatusAndLink> getAgentList(
public TreeView<TreeNode<AgentAndStatus>> getAgentList(
@RequestParam("from") long from,
@RequestParam("to") long to) {
AgentInfoFilter filter = new DefaultAgentInfoFilter(from);
Expand All @@ -81,38 +82,38 @@ public TreeView<AgentStatusAndLink> getAgentList(


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

private static TreeView<AgentStatusAndLink> treeView(AgentsMapByApplication agentsListsList) {
List<InstancesList<AgentStatusAndLink>> list = agentsListsList.getAgentsListsList();
private static TreeView<TreeNode<AgentAndStatus>> treeView(AgentsMapByApplication agentsListsList) {
List<InstancesList<AgentAndStatus>> list = agentsListsList.getAgentsListsList();
return new SimpleTreeView<>(list, InstancesList::getGroupName, InstancesList::getInstancesList);
}

@GetMapping(value = "/getAgentList", params = {"application"})
public TreeView<AgentAndStatus> getAgentList(@RequestParam("application") String applicationName) {
public TreeView<TreeNode<AgentStatusAndLink>> getAgentList(@RequestParam("application") String applicationName) {
long timestamp = System.currentTimeMillis();
return getAgentList(applicationName, timestamp);
}

@GetMapping(value = "/getAgentList", params = {"application", "from", "to"})
public TreeView<AgentAndStatus> getAgentList(
public TreeView<TreeNode<AgentStatusAndLink>> getAgentList(
@RequestParam("application") String applicationName,
@RequestParam("from") long from,
@RequestParam("to") long to) {
AgentInfoFilter currentRunnedFilter = new AgentInfoFilterChain(
AgentInfoFilter currentRunFilter = new AgentInfoFilterChain(
new DefaultAgentInfoFilter(from)
);
long timestamp = to;
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(currentRunnedFilter, applicationName, timestamp);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(currentRunFilter, applicationName, timestamp);
return treeView(list);
}

@GetMapping(value = "/getAgentList", params = {"application", "timestamp"})
public TreeView<AgentAndStatus> getAgentList(
public TreeView<TreeNode<AgentStatusAndLink>> getAgentList(
@RequestParam("application") String applicationName,
@RequestParam("timestamp") long timestamp) {
AgentInfoFilter runningAgentFilter = new AgentInfoFilterChain(
Expand All @@ -122,8 +123,8 @@ public TreeView<AgentAndStatus> getAgentList(
return treeView(list);
}

private static TreeView<AgentAndStatus> treeView(AgentsMapByHost agentsMapByHost) {
List<InstancesList<AgentAndStatus>> list = agentsMapByHost.getAgentsListsList();
private static TreeView<TreeNode<AgentStatusAndLink>> treeView(AgentsMapByHost agentsMapByHost) {
List<InstancesList<AgentStatusAndLink>> list = agentsMapByHost.getAgentsListsList();
return new SimpleTreeView<>(list, InstancesList::getGroupName, InstancesList::getInstancesList);
}

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

import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.view.tree.StaticTreeView;
import com.navercorp.pinpoint.web.view.tree.TreeView;
import com.navercorp.pinpoint.web.vo.agent.AgentAndStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentInfoFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentInfoFilterChain;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusAndLink;
import com.navercorp.pinpoint.web.vo.agent.DefaultAgentInfoFilter;
import com.navercorp.pinpoint.web.vo.tree.InstancesList;
import com.navercorp.pinpoint.web.vo.tree.AgentsMapByApplication;
import com.navercorp.pinpoint.web.vo.tree.AgentsMapByHost;
import com.navercorp.pinpoint.web.vo.tree.SortByAgentInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
* @author intr3p1d
*/
@RestController
@RequestMapping(value = "/agents")
public class AgentListController {
private final AgentInfoService agentInfoService;

public AgentListController(AgentInfoService agentInfoService) {
this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService");
}

@GetMapping(value = "/all")
public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList() {
long timestamp = System.currentTimeMillis();
return getAllAgentsList(timestamp);
}

@GetMapping(value = "/all", params = {"from", "to"})
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);
return treeView(allAgentsList);
}

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

private static TreeView<InstancesList<AgentAndStatus>> treeView(AgentsMapByApplication agentsListsList) {
List<InstancesList<AgentAndStatus>> list = agentsListsList.getAgentsListsList();
return new StaticTreeView<>(list);
}


@GetMapping(value = "/v1", params = {"application", "sortBy"})
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
@RequestParam("application") String applicationName,
@RequestParam("sortBy") SortByAgentInfo.Rules sortBy) {
long timestamp = System.currentTimeMillis();
return getAgentsList(applicationName, timestamp, sortBy);
}

@GetMapping(value = "/v1", params = {"application", "from", "to", "sortBy"})
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
@RequestParam("application") String applicationName,
@RequestParam("from") long from,
@RequestParam("to") long to,
@RequestParam("sortBy") SortByAgentInfo.Rules sortBy) {
AgentInfoFilter currentRunFilter = new AgentInfoFilterChain(
new DefaultAgentInfoFilter(from)
);
long timestamp = to;
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(currentRunFilter, applicationName, timestamp, sortBy);
return treeView(list);
}

@GetMapping(value = "/v1", params = {"application", "timestamp", "sortBy"})
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList(
@RequestParam("application") String applicationName,
@RequestParam("timestamp") long timestamp,
@RequestParam("sortBy") SortByAgentInfo.Rules sortBy) {
AgentInfoFilter runningAgentFilter = new AgentInfoFilterChain(
AgentInfoFilter::filterRunning
);
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(runningAgentFilter, applicationName, timestamp, sortBy);
return treeView(list);
}

private static TreeView<InstancesList<AgentStatusAndLink>> treeView(AgentsMapByHost agentsMapByHost) {
List<InstancesList<AgentStatusAndLink>> list = agentsMapByHost.getAgentsListsList();
return new StaticTreeView<>(list);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ private <T> T getAgentInfo0(String agentId, long timestamp, ResultsExtractor<T>


/**
*
* @param agentId agent id
* @param agentStartTime agent start time in milliseconds
* @param agentId agent id
* @param agentStartTime agent start time in milliseconds
* @param deltaTimeInMilliSeconds limit the scan range in case of scanning for a non-exist agent
* @return
*/
Expand All @@ -123,15 +122,14 @@ public AgentInfo getAgentInfo(String agentId, long agentStartTime, int deltaTime

@Override
public List<AgentInfo> getAgentInfos(List<String> agentIds, long timestamp) {
return getAgentInfos0(agentIds, timestamp, AgentInfoColumn.simple());
return getAgentInfos0(agentIds, timestamp, agentInfoResultsExtractor, AgentInfoColumn.simple());
}


public List<AgentInfo> getSimpleAgentInfos(List<String> agentIds, long timestamp) {
return getAgentInfos0(agentIds, timestamp, AgentInfoColumn.simple());
return getAgentInfos0(agentIds, timestamp, agentInfoResultsExtractor, AgentInfoColumn.simple());
}

public List<AgentInfo> getAgentInfos0(List<String> agentIds, long timestamp, AgentInfoColumn column) {
public <T> List<T> getAgentInfos0(List<String> agentIds, long timestamp, ResultsExtractor<T> action, AgentInfoColumn column) {
if (CollectionUtils.isEmpty(agentIds)) {
return Collections.emptyList();
}
Expand All @@ -142,7 +140,7 @@ public List<AgentInfo> getAgentInfos0(List<String> agentIds, long timestamp, Age
}

TableName agentInfoTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable());
return this.hbaseOperations2.findParallel(agentInfoTableName, scans, agentInfoResultsExtractor);
return this.hbaseOperations2.findParallel(agentInfoTableName, scans, action);
}

private Scan createScan(String agentId, long currentTime, AgentInfoColumn column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.navercorp.pinpoint.web.vo.agent.AgentStatusQuery;
import com.navercorp.pinpoint.web.vo.agent.DetailedAgentAndStatus;
import com.navercorp.pinpoint.web.vo.timeline.inspector.InspectorTimeline;
import com.navercorp.pinpoint.web.vo.tree.SortByAgentInfo;

import java.util.List;
import java.util.Optional;
Expand All @@ -44,6 +45,8 @@ public interface AgentInfoService {

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

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

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

Set<AgentAndStatus> getAgentsByApplicationName(String applicationName, long timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.navercorp.pinpoint.web.vo.agent.AgentInfo;
import com.navercorp.pinpoint.web.vo.agent.AgentInfoFilter;
import com.navercorp.pinpoint.web.vo.agent.AgentStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusAndLink;
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 @@ -115,13 +116,20 @@ public AgentsMapByApplication getAllAgentsList(AgentInfoFilter filter, long time

return AgentsMapByApplication.newAgentsMapByApplication(
filter,
hyperLinkFactory,
agents
);
}

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

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

Expand All @@ -131,13 +139,15 @@ public AgentsMapByHost getAgentsListByApplicationName(AgentInfoFilter filter, St
}

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

logger.debug("getAgentsMapByHostname={}", agentsMapByHost);
return agentsMapByHost;
}


@Override
public ApplicationAgentHostList getApplicationAgentHostList(int offset, int limit, int durationDays) {
if (offset <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author emeroad
*/
@JsonSerialize(using = SimpleTreeViewSerializer.class)
public class SimpleTreeView<I, C> implements TreeView<C> {
public class SimpleTreeView<I, C> implements TreeView<TreeNode<C>> {

private final List<I> nodeList;
private final Function<I, String> valueMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.navercorp.pinpoint.web.view.tree;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Iterator;
import java.util.List;
import java.util.Objects;

public class StaticTreeView<C> implements TreeView<C> {

private final List<C> nodeList;

public StaticTreeView(List<C> nodeList) {
this.nodeList = Objects.requireNonNull(nodeList, "nodeList");
}

@Override
@JsonValue
@JsonUnwrapped
public Iterator<C> nodes() {
return nodeList.stream().iterator();
}

@Override
public String toString() {
return "TreeView{" +
"itemList=" + nodeList +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* @author emeroad
*/
public interface TreeView<C> {
Iterator<TreeNode<C>> nodes();
Iterator<C> nodes();
}
Loading

0 comments on commit bc0f809

Please sign in to comment.