Skip to content

Commit

Permalink
[pinpoint-apm#9037] Refactor ClusterKey
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jul 15, 2022
1 parent 0a80254 commit dfb7f85
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ public AgentInfoBo mapRow(Result result, int rowNum) throws Exception {
long reverseStartTime = BytesUtils.bytesToLong(rowKey, HbaseTableConstants.AGENT_ID_MAX_LEN);
long startTime = TimeUtils.recoveryTimeMillis(reverseStartTime);

byte[] serializedAgentInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_IDENTIFIER);
byte[] serializedServerMetaData = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_SERVER_META_DATA);
byte[] serializedJvmInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_JVM);

final byte[] serializedAgentInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_IDENTIFIER);
final AgentInfoBo.Builder agentInfoBoBuilder = createBuilderFromValue(serializedAgentInfo);
agentInfoBoBuilder.setAgentId(agentId);
agentInfoBoBuilder.setStartTime(startTime);

final byte[] serializedServerMetaData = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_SERVER_META_DATA);
if (serializedServerMetaData != null) {
agentInfoBoBuilder.setServerMetaData(new ServerMetaDataBo.Builder(serializedServerMetaData).build());
}

final byte[] serializedJvmInfo = result.getValue(AGENTINFO_INFO.getName(), AGENTINFO_INFO.QUALIFIER_JVM);
if (serializedJvmInfo != null) {
agentInfoBoBuilder.setJvmInfo(new JvmInfoBo(serializedJvmInfo));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@

package com.navercorp.pinpoint.web.applicationmap.nodes;

import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.navercorp.pinpoint.web.view.ServerInstanceListSerializer;
Expand All @@ -41,35 +46,25 @@ public Map<String, List<ServerInstance>> getServerInstanceList() {
}

public List<String> getAgentIdList() {
final Collection<List<ServerInstance>> serverInstanceValueList = this.serverInstanceList.values();

final List<String> agentList = new ArrayList<>();
for (List<ServerInstance> serverInstanceList : serverInstanceValueList) {
for (ServerInstance serverInstance : serverInstanceList) {
agentList.add(serverInstance.getName());
}
}
return agentList;
Collection<List<ServerInstance>> serverList = this.serverInstanceList.values();
return serverList.stream()
.flatMap(List::stream)
.map(ServerInstance::getName)
.collect(Collectors.toList());
}

public Map<String, String> getAgentIdNameMap() {
final Collection<List<ServerInstance>> serverInstanceValueList = this.serverInstanceList.values();

final Map<String, String> map = new HashMap<>();
for (List<ServerInstance> serverInstanceList : serverInstanceValueList) {
for (ServerInstance serverInstance : serverInstanceList) {
map.put(serverInstance.getName(), serverInstance.getAgentName());
}
}
return map;
Collection<List<ServerInstance>> serverList = this.serverInstanceList.values();
return serverList.stream()
.flatMap(List::stream)
.collect(Collectors.toMap(ServerInstance::getName, ServerInstance::getAgentName));
}

public int getInstanceCount() {
int count = 0;
for (List<ServerInstance> entry : serverInstanceList.values()) {
count += entry.size();
}
return count;
Collection<List<ServerInstance>> serverList = this.serverInstanceList.values();
return serverList.stream()
.mapToInt(List::size)
.sum();
}

private void addServerInstance(List<ServerInstance> nodeList, ServerInstance serverInstance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
*/
public interface AgentInfoDao {

AgentInfo getInitialAgentInfo(String agentId);

List<AgentInfo> getInitialAgentInfos(List<String> agentIds);

AgentInfo getAgentInfo(String agentId, long timestamp);

AgentInfo getAgentInfo(String agentId, long agentStartTime, int deltaTimeInMilliSeconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,45 +62,6 @@ public HbaseAgentInfoDao(HbaseOperations2 hbaseOperations2,
this.agentInfoResultsExtractor = Objects.requireNonNull(agentInfoResultsExtractor, "agentInfoResultsExtractor");
}

/**
* Returns the very first information of the agent
*
* @param agentId
*/
@Override
public AgentInfo getInitialAgentInfo(final String agentId) {
Objects.requireNonNull(agentId, "agentId");

Scan scan = createScanForInitialAgentInfo(agentId);

TableName agentInfoTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable());
return this.hbaseOperations2.find(agentInfoTableName, scan, agentInfoResultsExtractor);
}

@Override
public List<AgentInfo> getInitialAgentInfos(List<String> agentIds) {
if (CollectionUtils.isEmpty(agentIds)) {
return Collections.emptyList();
}
List<Scan> scans = new ArrayList<>(agentIds.size());
for (String agentId : agentIds) {
scans.add(createScanForInitialAgentInfo(agentId));
}

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

private Scan createScanForInitialAgentInfo(String agentId) {
Scan scan = new Scan();

byte[] reverseStartKey = RowKeyUtils.agentIdAndTimestamp(agentId, Long.MAX_VALUE);
scan.withStartRow(reverseStartKey);
scan.setReversed(true);
scan.setMaxVersions(1);
scan.setCaching(SCANNER_CACHING);
return scan;
}

/**
* Returns the information of the agent with its start time closest to the given timestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.navercorp.pinpoint.web.hyperlink;


import javax.annotation.Nullable;

public class DefaultLinkSource implements LinkSource {
private final String hostName;
private final String ip;


public DefaultLinkSource(String hostName, String ip) {
public DefaultLinkSource(String hostName, @Nullable String ip) {
this.hostName = hostName;
this.ip = ip;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public interface AgentInfoService {

AgentInfo getAgentInfo(String agentId, long timestamp);

AgentInfo getAgentInfoNoStatus(String agentId, long agentStartTime, int deltaTimeInMilliseconds);
AgentInfo getAgentInfoWithoutStatus(String agentId, long timestamp);

AgentInfo getAgentInfoWithoutStatus(String agentId, long agentStartTime, int deltaTimeInMilliseconds);

AgentStatus getAgentStatus(String agentId, long timestamp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,7 @@ public Set<AgentInfo> getRecentAgentsByApplicationName(String applicationName, l

@Override
public AgentInfo getAgentInfo(String agentId, long timestamp) {
Objects.requireNonNull(agentId, "agentId");

if (timestamp < 0) {
throw new IllegalArgumentException("timestamp must not be less than 0");
}
AgentInfo agentInfo = this.agentInfoDao.getAgentInfo(agentId, timestamp);
AgentInfo agentInfo = getAgentInfoWithoutStatus(agentId, timestamp);
if (agentInfo != null) {
Optional<AgentStatus> agentStatus = this.agentLifeCycleDao.getAgentStatus(agentInfo.getAgentId(), agentInfo.getStartTimestamp(), timestamp);
agentInfo.setStatus(agentStatus.orElse(null));
Expand All @@ -292,7 +287,17 @@ public AgentInfo getAgentInfo(String agentId, long timestamp) {
}

@Override
public AgentInfo getAgentInfoNoStatus(String agentId, long agentStartTime, int deltaTimeInMilliSeconds) {
public AgentInfo getAgentInfoWithoutStatus(String agentId, long timestamp) {
Objects.requireNonNull(agentId, "agentId");

if (timestamp < 0) {
throw new IllegalArgumentException("timestamp must not be less than 0");
}
return this.agentInfoDao.getAgentInfo(agentId, timestamp);
}

@Override
public AgentInfo getAgentInfoWithoutStatus(String agentId, long agentStartTime, int deltaTimeInMilliSeconds) {
return this.agentInfoDao.getAgentInfo(agentId, agentStartTime, deltaTimeInMilliSeconds);
}

Expand Down Expand Up @@ -348,7 +353,7 @@ public InspectorTimeline getAgentStatusTimeline(String agentId, Range range, int

@Override
public boolean isExistAgentId(String agentId) {
AgentInfo agentInfo = getAgentInfo(agentId, System.currentTimeMillis());
AgentInfo agentInfo = getAgentInfoWithoutStatus(agentId, System.currentTimeMillis());
return agentInfo != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ private SpanResult order(List<SpanBo> spans, Predicate<SpanBo> filter, boolean i

private Optional<String> getAgentName(String agentId, long agentStartTime) {
final int deltaTimeInMilli = 1000;
final AgentInfo agentInfo = this.agentInfoService.getAgentInfoNoStatus(agentId, agentStartTime, deltaTimeInMilli);
final AgentInfo agentInfo = this.agentInfoService.getAgentInfoWithoutStatus(agentId, agentStartTime, deltaTimeInMilli);
return agentInfo == null ? Optional.empty() : Optional.ofNullable(agentInfo.getAgentName());
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class NodeSerializer extends JsonSerializer<Node> {

@Override
public void serialize(Node node, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
public void serialize(Node node, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
// jgen.writeStringField("id", node.getNodeName());serverInstanceList
jgen.writeStringField("key", node.getNodeName()); // necessary for go.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class AgentInfo {
private String agentVersion;
private ServerMetaDataBo serverMetaData;
private JvmInfoBo jvmInfo;
private long initialStartTimestamp;
private boolean container;
private AgentStatus status;

Expand Down Expand Up @@ -163,10 +162,6 @@ public void setJvmInfo(JvmInfoBo jvmInfo) {
this.jvmInfo = jvmInfo;
}

public long getInitialStartTimestamp() {
return initialStartTimestamp;
}


public boolean isContainer() {
return container;
Expand Down Expand Up @@ -221,7 +216,6 @@ public String toString() {
sb.append(", agentVersion='").append(agentVersion).append('\'');
sb.append(", serverMetaData='").append(serverMetaData).append('\'');
sb.append(", jvmInfo=").append(jvmInfo);
sb.append(", initialStartTimestamp=").append(initialStartTimestamp);
sb.append(", container=").append(container);
sb.append(", status=").append(status);
sb.append('}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public void test() throws Exception {

CollectorClusterInfoRepository info = new CollectorClusterInfoRepository();

final ClusterKey agent1 = new ClusterKey("app", "agent1", 0);
final ClusterKey agent2 = new ClusterKey("app", "agent2", 1);
final Set<ClusterKey> profilerInfos = Set.of(agent1, agent2);
final ClusterKey clusterKey1 = new ClusterKey("app", "agent1", 0);
final ClusterKey clusterKey2 = new ClusterKey("app", "agent2", 1);
final Set<ClusterKey> profilerInfos = Set.of(clusterKey1, clusterKey2);

ClusterId clusterId = new ClusterId("/path", "/collectorA", "appName");
info.put(clusterId, profilerInfos);

List<ClusterId> collectorList = info.get(agent1);
List<ClusterId> collectorList = info.get(clusterKey1);
logger.debug("{}", collectorList);
Assertions.assertEquals(clusterId, collectorList.get(0));

info.remove(clusterId);
Assertions.assertTrue(info.get(agent1).isEmpty(), "Not found");
Assertions.assertTrue(info.get(clusterKey1).isEmpty(), "Not found");
}


Expand Down

0 comments on commit dfb7f85

Please sign in to comment.