提交 bdc0601c 编写于 作者: P peng-yongsheng

Fixed the call type in calls of topology.

上级 41840ce8
......@@ -65,7 +65,7 @@ public class SpanIdExchanger implements IdExchanger<SpanDecorator> {
standardBuilder.setPeer(Const.EMPTY_STRING);
int spanLayer = standardBuilder.getSpanLayerValue();
int serverType = ServerTypeDefine.getInstance().getServerTypeId(standardBuilder.getComponentId());
int serverType = ServerTypeDefine.getInstance().getServerTypeByComponentId(standardBuilder.getComponentId()).getId();
networkAddressIDService.update(peerId, spanLayer, serverType);
}
}
......
......@@ -22,25 +22,25 @@ package org.apache.skywalking.apm.collector.storage.table.register;
* @author peng-yongsheng
*/
public class ServerType {
private int componentId;
private int id;
private int componentId;
private String name;
public ServerType(int componentId, int id, String name) {
this.componentId = componentId;
public ServerType(int id, String name) {
this.id = id;
this.name = name;
this.componentId = id;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getComponentId() {
return componentId;
}
public String getName() {
return name;
}
}
......@@ -28,41 +28,46 @@ public class ServerTypeDefine {
private static ServerTypeDefine INSTANCE = new ServerTypeDefine();
private String[] serverTypeNames;
private ServerType[] serverTypes;
private static final String HTTP = "http";
private static final String GRPC = "gRPC";
private static final String DUBBO = "dubbo";
private static final String MOTAN = "motan";
private static final String CLIENT = "client";
private static final String JDBC_DRIVER = "JDBC driver";
private ServerTypeDefine() {
this.serverTypes = new ServerType[30];
this.serverTypeNames = new String[11];
addServerType(new ServerType(ComponentsDefine.TOMCAT.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.HTTPCLIENT.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.DUBBO.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.H2.getId(), 1, ComponentsDefine.H2.getName()));
addServerType(new ServerType(ComponentsDefine.MYSQL.getId(), 2, ComponentsDefine.MYSQL.getName()));
addServerType(new ServerType(ComponentsDefine.ORACLE.getId(), 3, ComponentsDefine.ORACLE.getName()));
addServerType(new ServerType(ComponentsDefine.REDIS.getId(), 4, ComponentsDefine.REDIS.getName()));
addServerType(new ServerType(ComponentsDefine.MOTAN.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.MONGODB.getId(), 5, ComponentsDefine.MONGODB.getName()));
addServerType(new ServerType(ComponentsDefine.RESIN.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.FEIGN.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.OKHTTP.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.SPRING_REST_TEMPLATE.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.SPRING_MVC_ANNOTATION.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.STRUTS2.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.NUTZ_MVC_ANNOTATION.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.NUTZ_HTTP.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.JETTY_CLIENT.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.JETTY_SERVER.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.MEMCACHED.getId(), 6, ComponentsDefine.MEMCACHED.getName()));
addServerType(new ServerType(ComponentsDefine.SHARDING_JDBC.getId(), 7, ComponentsDefine.SHARDING_JDBC.getName()));
addServerType(new ServerType(ComponentsDefine.POSTGRESQL.getId(), 8, ComponentsDefine.POSTGRESQL.getName()));
addServerType(new ServerType(ComponentsDefine.GRPC.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.ELASTIC_JOB.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.ROCKET_MQ.getId(), 9, ComponentsDefine.ROCKET_MQ.getName()));
addServerType(new ServerType(ComponentsDefine.HTTP_ASYNC_CLIENT.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.KAFKA.getId(), 10, ComponentsDefine.KAFKA.getName()));
addServerType(new ServerType(ComponentsDefine.SERVICECOMB.getId(), Const.NONE, ComponentsDefine.SERVICECOMB.getName()));
addServerType(new ServerType(ComponentsDefine.HYSTRIX.getId(), Const.NONE, ComponentsDefine.HYSTRIX.getName()));
addServerType(new ServerType(ComponentsDefine.TOMCAT.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.HTTPCLIENT.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.DUBBO.getId(), DUBBO));
addServerType(new ServerType(ComponentsDefine.H2.getId(), JDBC_DRIVER));
addServerType(new ServerType(ComponentsDefine.MYSQL.getId(), JDBC_DRIVER));
addServerType(new ServerType(ComponentsDefine.ORACLE.getId(), JDBC_DRIVER));
addServerType(new ServerType(ComponentsDefine.REDIS.getId(), CLIENT));
addServerType(new ServerType(ComponentsDefine.MOTAN.getId(), MOTAN));
addServerType(new ServerType(ComponentsDefine.MONGODB.getId(), CLIENT));
addServerType(new ServerType(ComponentsDefine.RESIN.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.FEIGN.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.OKHTTP.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.SPRING_REST_TEMPLATE.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.SPRING_MVC_ANNOTATION.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.STRUTS2.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.NUTZ_MVC_ANNOTATION.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.NUTZ_HTTP.getId(), HTTP));
addServerType(new ServerType(ComponentsDefine.JETTY_CLIENT.getId(), HTTP));
addServerType(new ServerType(ComponentsDefine.JETTY_SERVER.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.MEMCACHED.getId(), CLIENT));
addServerType(new ServerType(ComponentsDefine.SHARDING_JDBC.getId(), JDBC_DRIVER));
addServerType(new ServerType(ComponentsDefine.POSTGRESQL.getId(), JDBC_DRIVER));
addServerType(new ServerType(ComponentsDefine.GRPC.getId(), GRPC));
addServerType(new ServerType(ComponentsDefine.ELASTIC_JOB.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.ROCKET_MQ.getId(), CLIENT));
addServerType(new ServerType(ComponentsDefine.HTTP_ASYNC_CLIENT.getId(), HTTP));
addServerType(new ServerType(ComponentsDefine.KAFKA.getId(), CLIENT));
addServerType(new ServerType(ComponentsDefine.SERVICECOMB.getId(), Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.HYSTRIX.getId(), Const.EMPTY_STRING));
}
public static ServerTypeDefine getInstance() {
......@@ -70,15 +75,14 @@ public class ServerTypeDefine {
}
private void addServerType(ServerType serverType) {
serverTypeNames[serverType.getId()] = serverType.getName();
serverTypes[serverType.getComponentId()] = serverType;
serverTypes[serverType.getId()] = serverType;
}
public int getServerTypeId(int componentId) {
return serverTypes[componentId].getId();
public ServerType getServerTypeByComponentId(int componentId) {
return serverTypes[componentId];
}
public String getServerType(int serverTypeId) {
return serverTypeNames[serverTypeId];
public ServerType getServerType(int serverTypeId) {
return serverTypes[serverTypeId];
}
}
......@@ -35,7 +35,7 @@ public class ServerTypeDefineTestCase {
for (Field field : fields) {
if (field.getType().equals(OfficialComponent.class)) {
OfficialComponent component = (OfficialComponent)field.get(ComponentsDefine.getInstance());
ServerTypeDefine.getInstance().getServerTypeId(component.getId());
ServerTypeDefine.getInstance().getServerTypeByComponentId(component.getId());
}
}
}
......
......@@ -40,6 +40,7 @@ import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalApp;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalAppBrief;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -117,8 +118,8 @@ public class ApplicationService {
long endSecondTimeBucket) throws ParseException {
List<ConjecturalApp> conjecturalApps = networkAddressUIDAO.getConjecturalApps();
conjecturalApps.forEach(conjecturalApp -> {
String name = ServerTypeDefine.getInstance().getServerType(conjecturalApp.getId());
conjecturalApp.setName(name);
int componentId = ServerTypeDefine.getInstance().getServerType(conjecturalApp.getId()).getComponentId();
conjecturalApp.setName(ComponentsDefine.getInstance().getComponentName(componentId));
});
ConjecturalAppBrief conjecturalAppBrief = new ConjecturalAppBrief();
......
......@@ -33,6 +33,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUID
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.table.register.ServerTypeDefine;
import org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm;
import org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode;
import org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode;
......@@ -71,7 +72,8 @@ class TopologyBuilder {
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> callerReferenceMetric,
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric,
long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) {
Map<Integer, String> components = changeNodeComp2Map(applicationComponents);
Map<Integer, String> componentNames = changeNodeCompName2Map(applicationComponents);
Map<Integer, Integer> componentIds = changeNodeCompId2Map(applicationComponents);
Map<Integer, Integer> mappings = changeMapping2Map(applicationMappings);
calleeReferenceMetric = calleeReferenceMetricFilter(calleeReferenceMetric);
......@@ -83,7 +85,7 @@ class TopologyBuilder {
ApplicationNode applicationNode = new ApplicationNode();
applicationNode.setId(applicationId);
applicationNode.setName(application.getApplicationCode());
applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
applicationNode.setType(componentNames.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
applicationNode.setSla(SLACalculator.INSTANCE.calculate(applicationMetric.getErrorCalls(), applicationMetric.getCalls()));
try {
......@@ -129,7 +131,7 @@ class TopologyBuilder {
ConjecturalNode conjecturalNode = new ConjecturalNode();
conjecturalNode.setId(target.getApplicationId());
conjecturalNode.setName(target.getApplicationCode());
conjecturalNode.setType(components.getOrDefault(target.getApplicationId(), Const.UNKNOWN));
conjecturalNode.setType(componentNames.getOrDefault(target.getApplicationId(), Const.UNKNOWN));
nodes.add(conjecturalNode);
}
......@@ -141,7 +143,7 @@ class TopologyBuilder {
call.setTarget(actualTargetId);
call.setTargetName(applicationCacheService.getApplicationById(actualTargetId).getApplicationCode());
call.setAlert(false);
call.setCallType(components.get(referenceMetric.getTarget()));
call.setCallType(ServerTypeDefine.getInstance().getServerTypeByComponentId(componentIds.get(referenceMetric.getTarget())).getName());
try {
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(source.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
......@@ -167,7 +169,7 @@ class TopologyBuilder {
ConjecturalNode conjecturalNode = new ConjecturalNode();
conjecturalNode.setId(source.getApplicationId());
conjecturalNode.setName(source.getApplicationCode());
conjecturalNode.setType(components.getOrDefault(source.getApplicationId(), Const.UNKNOWN));
conjecturalNode.setType(componentNames.getOrDefault(source.getApplicationId(), Const.UNKNOWN));
nodes.add(conjecturalNode);
}
......@@ -181,7 +183,7 @@ class TopologyBuilder {
if (source.getApplicationId() == Const.NONE_APPLICATION_ID) {
call.setCallType(Const.EMPTY_STRING);
} else {
call.setCallType(components.get(referenceMetric.getTarget()));
call.setCallType(ServerTypeDefine.getInstance().getServerTypeByComponentId(componentIds.get(referenceMetric.getTarget())).getName());
}
try {
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(target.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
......@@ -219,7 +221,7 @@ class TopologyBuilder {
return mappings;
}
private Map<Integer, String> changeNodeComp2Map(
private Map<Integer, String> changeNodeCompName2Map(
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents) {
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(applicationComponent -> {
......@@ -228,4 +230,13 @@ class TopologyBuilder {
});
return components;
}
private Map<Integer, Integer> changeNodeCompId2Map(
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents) {
Map<Integer, Integer> components = new HashMap<>();
applicationComponents.forEach(applicationComponent -> {
components.put(applicationComponent.getApplicationId(), applicationComponent.getComponentId());
});
return components;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册