Skip to content

Commit

Permalink
[pinpoint-apm#8934] Refactor AgentInfoController
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d committed Jul 6, 2022
1 parent e4404f2 commit 134115e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ public ApplicationAgentsList getAgentList(
@RequestParam("application") String applicationName,
@RequestParam("from") long from,
@RequestParam("to") long to) {
AgentInfoFilter containerFilter = new AgentInfoFilterChain(
AgentInfoFilter currentRunnedFilter = new AgentInfoFilterChain(
new DefaultAgentInfoFilter(from)
);
long timestamp = to;
return this.agentInfoService.getApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, containerFilter, applicationName, timestamp);
return this.agentInfoService.getApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, currentRunnedFilter, applicationName, timestamp);
}

@GetMapping(value = "/getAgentList", params = {"application", "timestamp"})
public ApplicationAgentsList getAgentList(
@RequestParam("application") String applicationName,
@RequestParam("timestamp") long timestamp) {
AgentInfoFilter runningContainerFilter = new AgentInfoFilterChain(
new DefaultAgentInfoFilter(Long.MAX_VALUE)
AgentInfoFilter runningAgentFilter = new AgentInfoFilterChain(
AgentInfoFilter::filterRunning
);
return this.agentInfoService.getApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, runningContainerFilter, applicationName, timestamp);
return this.agentInfoService.getApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, runningAgentFilter, applicationName, timestamp);
}

@GetMapping(value = "/getAgentInfo")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.navercorp.pinpoint.web.vo;

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

public interface AgentInfoFilter {
boolean ACCEPT = true;
boolean REJECT = false;
Expand All @@ -14,4 +16,14 @@ static boolean reject(AgentInfo agentInfo) {
return REJECT;
}

static boolean filterRunning(AgentInfo agentInfo) {
final AgentStatus agentStatus = agentInfo.getStatus();
if (agentStatus == null) {
return REJECT;
}
if (agentStatus.getState() == AgentLifeCycleState.RUNNING) {
return ACCEPT;
}
return REJECT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class AgentInfoFilterChainTest {
public class AgentInfoFilterUnionTest {

@Test
public void filter_running() {
final long current = System.currentTimeMillis();

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

AgentStatus status = new AgentStatus("testAgent", AgentLifeCycleState.RUNNING, current);
AgentInfo info = new AgentInfo();
info.setStatus(status);

Assertions.assertEquals(AgentInfoFilter.ACCEPT, chain.filter(info));
}

@Test
public void filter_from_accept() {
Expand Down

0 comments on commit 134115e

Please sign in to comment.