Repository: pinpoint-apm/pinpoint
Issue: Running container agents may be missing in Inspector View agent list when queried for less than 5 minutes
Labels: bug
module:web

#### What version of pinpoint are you using?
master

#### Describe the bug
Some agents with `pinpoint.container` option are missing from the agent list in Inspector View even if they are alive. This is because the agent list currently filters out any agents that do not have any events (such as ping, or connected) in between the search period.
So if the agent has sent pings in time 1 and time 6, and the search period is set from time 2 to time 5, the agent will be filtered out even if it is currently running.

#### What did you do to trigger the bug?
Steps to reproduce, for example:
1. Ran an agent with`-Dpinpoint.container` option.
2. Query for the agent in Inspector View, with search period set to not include any events from the agent. (ie in between agent pings)

#### Expected behavior
Running agents with `pinpoint.container` option should be displayed in the agent list, and not be filtered out even if there were no events from the agent during the search period.


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentInfoController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentInfoController.java
index 56ae264db941..907ad3d59575 100644
--- a/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentInfoController.java
+++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/AgentInfoController.java
@@ -94,13 +94,20 @@ public ApplicationAgentsList getAgentList(
             @RequestParam("from") long from,
             @RequestParam("to") long to) {
         ApplicationAgentsList.Filter containerFilter = agentInfo -> {
-            if (agentInfo.isContainer()) {
-                AgentStatus agentStatus = agentInfo.getStatus();
-                if (agentStatus == null || agentStatus.getEventTimestamp() < from) {
-                    return ApplicationAgentsList.Filter.REJECT;
-                }
+            if (!agentInfo.isContainer()) {
+                return ApplicationAgentsList.Filter.ACCEPT;
             }
-            return ApplicationAgentsList.Filter.ACCEPT;
+            AgentStatus agentStatus = agentInfo.getStatus();
+            if (agentStatus == null) {
+                return ApplicationAgentsList.Filter.REJECT;
+            }
+            if (agentStatus.getState() == AgentLifeCycleState.RUNNING) {
+                return ApplicationAgentsList.Filter.ACCEPT;
+            }
+            if (agentStatus.getEventTimestamp() >= from) {
+                return ApplicationAgentsList.Filter.ACCEPT;
+            }
+            return ApplicationAgentsList.Filter.REJECT;
         };
         long timestamp = to;
         return this.agentInfoService.getApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, containerFilter, applicationName, timestamp);
@@ -113,13 +120,17 @@ public ApplicationAgentsList getAgentList(
             @RequestParam("application") String applicationName,
             @RequestParam("timestamp") long timestamp) {
         ApplicationAgentsList.Filter runningContainerFilter = agentInfo -> {
-            if (agentInfo.isContainer()) {
-                AgentStatus agentStatus = agentInfo.getStatus();
-                if (agentStatus == null || agentStatus.getState() != AgentLifeCycleState.RUNNING) {
-                    return ApplicationAgentsList.Filter.REJECT;
-                }
+            if (!agentInfo.isContainer()) {
+                return ApplicationAgentsList.Filter.ACCEPT;
+            }
+            AgentStatus agentStatus = agentInfo.getStatus();
+            if (agentStatus == null) {
+                return ApplicationAgentsList.Filter.REJECT;
+            }
+            if (agentStatus.getState() == AgentLifeCycleState.RUNNING) {
+                return ApplicationAgentsList.Filter.ACCEPT;
             }
-            return ApplicationAgentsList.Filter.ACCEPT;
+            return ApplicationAgentsList.Filter.REJECT;
         };
         return this.agentInfoService.getApplicationAgentsList(ApplicationAgentsList.GroupBy.HOST_NAME, runningContainerFilter, applicationName, timestamp);
     }


Test patch: