Skip to content

Commit

Permalink
[pinpoint-apm#10035] Fixed agent list in active request
Browse files Browse the repository at this point in the history
  • Loading branch information
smilu97 committed Jun 14, 2023
1 parent c19e994 commit b387f49
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ private void refreshWithContext(SessionContext ctx, WebSocketSession session, St
}

private Consumer<Long> makeTickHandler(SessionContext ctx, WebSocketSession session, String applicationName) {
final List<ClusterKey> agentKeys =
this.agentLookupService.getRecentAgents(applicationName, TimeUnit.HOURS.toMillis(1));
final List<ClusterKey> agentKeys = this.agentLookupService.getRecentAgents(applicationName);
final TickHandler handler = new TickHandler(session, applicationName, agentKeys, getFetchers(agentKeys));
final Runnable decoratedHandler = decorateHandler(ctx.getTaskDecorator(), handler);
return t -> decoratedHandler.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
*/
public interface AgentLookupService {

List<ClusterKey> getRecentAgents(String applicationName, long timeDiffMs);
List<ClusterKey> getRecentAgents(String applicationName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
package com.navercorp.pinpoint.web.realtime.service;

import com.navercorp.pinpoint.common.server.cluster.ClusterKey;
import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState;
import com.navercorp.pinpoint.web.cluster.ClusterKeyAndStatus;
import com.navercorp.pinpoint.web.service.AgentService;
import com.navercorp.pinpoint.web.vo.agent.AgentStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.navercorp.pinpoint.common.server.util.time.Range;
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.tree.AgentsMapByHost;
import com.navercorp.pinpoint.web.vo.tree.InstancesList;
import com.navercorp.pinpoint.web.vo.tree.SortByAgentInfo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand All @@ -33,37 +35,35 @@
*/
class AgentLookupServiceImpl implements AgentLookupService {

private static final Logger logger = LogManager.getLogger(AgentLookupServiceImpl.class);
private final AgentInfoService agentInfoService;

private final AgentService agentService;

AgentLookupServiceImpl(AgentService agentService) {
this.agentService = Objects.requireNonNull(agentService, "agentService");
AgentLookupServiceImpl(AgentInfoService agentInfoService) {
this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService");
}

@Override
public List<ClusterKey> getRecentAgents(String applicationName, long timeDiffMs) {
final List<ClusterKeyAndStatus> keyAndStatuses = getRecentAgentInfoList0(applicationName, timeDiffMs);
final List<ClusterKey> keys = new ArrayList<>(keyAndStatuses.size());
for (final ClusterKeyAndStatus keyAndStatus: keyAndStatuses) {
if (isActive(keyAndStatus.getStatus())) {
keys.add(keyAndStatus.getClusterKey());
}
}
return keys;
public List<ClusterKey> getRecentAgents(String applicationName) {
final long now = System.currentTimeMillis();
return intoClusterKeyList(this.agentInfoService.getAgentsListByApplicationName(
new AgentStatusFilterChain(AgentStatusFilter::filterRunning),
applicationName,
Range.between(now, now),
SortByAgentInfo.Rules.AGENT_NAME_ASC
));
}

private List<ClusterKeyAndStatus> getRecentAgentInfoList0(String applicationName, long timeDiffMs) {
try {
return agentService.getRecentAgentInfoList(applicationName, timeDiffMs);
} catch (Exception e) {
logger.warn("Failed to get recent agent info list for {}", applicationName, e);
private static List<ClusterKey> intoClusterKeyList(AgentsMapByHost src) {
final List<ClusterKey> result = new ArrayList<>(src.getAgentsListsList().size());
for (final InstancesList<AgentStatusAndLink> instancesList: src.getAgentsListsList()) {
for (final AgentStatusAndLink instance: instancesList.getInstancesList()) {
result.add(intoClusterKey(instance.getAgentInfo()));
}
}
return Collections.emptyList();
return result;
}

private boolean isActive(AgentStatus agentStatus) {
return agentStatus != null && agentStatus.getState() != AgentLifeCycleState.UNKNOWN;
private static ClusterKey intoClusterKey(AgentInfo src) {
return new ClusterKey(src.getApplicationName(), src.getAgentId(), src.getStartTimestamp());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.navercorp.pinpoint.web.realtime.service;

import com.navercorp.pinpoint.web.service.AgentInfoService;
import com.navercorp.pinpoint.web.service.AgentService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
Expand All @@ -28,8 +29,8 @@ public class RealtimeWebServiceConfig {

@Bean
@ConditionalOnBean(AgentService.class)
AgentLookupService agentLookupService(AgentService agentService) {
return new AgentLookupServiceImpl(agentService);
AgentLookupService agentLookupService(AgentInfoService agentInfoService) {
return new AgentLookupServiceImpl(agentInfoService);
}

}

0 comments on commit b387f49

Please sign in to comment.