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

1. Get the service id only when agent register service name.

2. Setting the src span type when agent register service name.
3. Revert the topology build logic.
上级 09f9c120
......@@ -54,7 +54,7 @@ public class ServiceNameDiscoveryServiceHandler extends ServiceNameDiscoveryServ
int applicationId = serviceNameElement.getApplicationId();
String serviceName = serviceNameElement.getServiceName();
int srcSpanType = serviceNameElement.getSrcSpanTypeValue();
int serviceId = serviceNameService.getOrCreate(applicationId, srcSpanType, serviceName);
int serviceId = serviceNameService.get(applicationId, srcSpanType, serviceName);
if (serviceId != 0) {
ServiceNameMappingElement.Builder mappingElement = ServiceNameMappingElement.newBuilder();
......
......@@ -24,5 +24,8 @@ import org.apache.skywalking.apm.collector.core.module.Service;
* @author peng-yongsheng
*/
public interface IServiceNameService extends Service {
int getOrCreate(int applicationId, int srcSpanType, String serviceName);
int get(int applicationId, int srcSpanType, String serviceName);
}
......@@ -74,4 +74,8 @@ public class ServiceNameService implements IServiceNameService {
}
return serviceId;
}
@Override public int get(int applicationId, int srcSpanType, String serviceName) {
return getServiceIdCacheService().get(applicationId, srcSpanType, serviceName);
}
}
......@@ -27,6 +27,7 @@ import org.apache.skywalking.apm.network.proto.UniqueId;
* @author peng-yongsheng
*/
public class ReferenceDecorator implements StandardBuilder {
private boolean isOrigin = true;
private StandardBuilder standardBuilder;
private TraceSegmentReference referenceObject;
......
......@@ -65,7 +65,7 @@ public class SpanIdExchanger implements IdExchanger<SpanDecorator> {
standardBuilder.setPeer(Const.EMPTY_STRING);
int spanLayer = standardBuilder.getSpanLayerValue();
int serverType = ServerTypeDefine.getInstance().getServerTypeByComponentId(standardBuilder.getComponentId()).getId();
int serverType = ServerTypeDefine.getInstance().getServerTypeId(standardBuilder.getComponentId());
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 id;
private int componentId;
private int id;
private String name;
public ServerType(int id, String name) {
public ServerType(int componentId, int id, String name) {
this.componentId = componentId;
this.id = id;
this.name = name;
this.componentId = id;
}
public int getId() {
return id;
}
public int getComponentId() {
return componentId;
}
public String getName() {
return name;
}
public int getComponentId() {
return componentId;
}
}
......@@ -28,46 +28,41 @@ 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];
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));
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()));
}
public static ServerTypeDefine getInstance() {
......@@ -75,14 +70,15 @@ public class ServerTypeDefine {
}
private void addServerType(ServerType serverType) {
serverTypes[serverType.getId()] = serverType;
serverTypeNames[serverType.getId()] = serverType.getName();
serverTypes[serverType.getComponentId()] = serverType;
}
public ServerType getServerTypeByComponentId(int componentId) {
return serverTypes[componentId];
public int getServerTypeId(int componentId) {
return serverTypes[componentId].getId();
}
public ServerType getServerType(int serverTypeId) {
return serverTypes[serverTypeId];
public String getServerType(int serverTypeId) {
return serverTypeNames[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().getServerTypeByComponentId(component.getId());
ServerTypeDefine.getInstance().getServerTypeId(component.getId());
}
}
}
......
......@@ -40,7 +40,6 @@ 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;
......@@ -118,8 +117,8 @@ public class ApplicationService {
long endSecondTimeBucket) throws ParseException {
List<ConjecturalApp> conjecturalApps = networkAddressUIDAO.getConjecturalApps();
conjecturalApps.forEach(conjecturalApp -> {
int componentId = ServerTypeDefine.getInstance().getServerType(conjecturalApp.getId()).getComponentId();
conjecturalApp.setName(ComponentsDefine.getInstance().getComponentName(componentId));
String serverType = ServerTypeDefine.getInstance().getServerType(conjecturalApp.getId());
conjecturalApp.setName(serverType);
});
ConjecturalAppBrief conjecturalAppBrief = new ConjecturalAppBrief();
......
......@@ -73,8 +73,8 @@ public class ServiceTopologyService {
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
List<IServiceReferenceMetricUIDAO.ServiceReferenceMetric> referenceMetrics = serviceReferenceMetricUIDAO.getFrontServices(step, startTimeBucket, endTimeBucket, MetricSource.Callee, serviceId);
referenceMetrics.addAll(serviceReferenceMetricUIDAO.getBehindServices(step, startTimeBucket, endTimeBucket, MetricSource.Caller, serviceId));
List<IServiceReferenceMetricUIDAO.ServiceReferenceMetric> referenceMetrics = serviceReferenceMetricUIDAO.getFrontServices(step, startTimeBucket, endTimeBucket, MetricSource.Caller, serviceId);
referenceMetrics.addAll(serviceReferenceMetricUIDAO.getBehindServices(step, startTimeBucket, endTimeBucket, MetricSource.Callee, serviceId));
Set<Integer> nodeIds = new HashSet<>();
......
......@@ -33,7 +33,6 @@ 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;
......@@ -72,8 +71,7 @@ class TopologyBuilder {
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> callerReferenceMetric,
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric,
long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) {
Map<Integer, String> componentNames = changeNodeCompName2Map(applicationComponents);
Map<Integer, Integer> componentIds = changeNodeCompId2Map(applicationComponents);
Map<Integer, String> components = changeNodeComp2Map(applicationComponents);
Map<Integer, Integer> mappings = changeMapping2Map(applicationMappings);
calleeReferenceMetric = calleeReferenceMetricFilter(calleeReferenceMetric);
......@@ -85,7 +83,7 @@ class TopologyBuilder {
ApplicationNode applicationNode = new ApplicationNode();
applicationNode.setId(applicationId);
applicationNode.setName(application.getApplicationCode());
applicationNode.setType(componentNames.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
applicationNode.setSla(SLACalculator.INSTANCE.calculate(applicationMetric.getErrorCalls(), applicationMetric.getCalls()));
try {
......@@ -131,7 +129,7 @@ class TopologyBuilder {
ConjecturalNode conjecturalNode = new ConjecturalNode();
conjecturalNode.setId(target.getApplicationId());
conjecturalNode.setName(target.getApplicationCode());
conjecturalNode.setType(componentNames.getOrDefault(target.getApplicationId(), Const.UNKNOWN));
conjecturalNode.setType(components.getOrDefault(target.getApplicationId(), Const.UNKNOWN));
nodes.add(conjecturalNode);
}
......@@ -143,7 +141,7 @@ class TopologyBuilder {
call.setTarget(actualTargetId);
call.setTargetName(applicationCacheService.getApplicationById(actualTargetId).getApplicationCode());
call.setAlert(false);
call.setCallType(ServerTypeDefine.getInstance().getServerTypeByComponentId(componentIds.get(referenceMetric.getTarget())).getName());
call.setCallType(components.get(referenceMetric.getTarget()));
try {
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(source.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
......@@ -169,7 +167,7 @@ class TopologyBuilder {
ConjecturalNode conjecturalNode = new ConjecturalNode();
conjecturalNode.setId(source.getApplicationId());
conjecturalNode.setName(source.getApplicationCode());
conjecturalNode.setType(componentNames.getOrDefault(source.getApplicationId(), Const.UNKNOWN));
conjecturalNode.setType(components.getOrDefault(source.getApplicationId(), Const.UNKNOWN));
nodes.add(conjecturalNode);
}
......@@ -183,7 +181,7 @@ class TopologyBuilder {
if (source.getApplicationId() == Const.NONE_APPLICATION_ID) {
call.setCallType(Const.EMPTY_STRING);
} else {
call.setCallType(ServerTypeDefine.getInstance().getServerTypeByComponentId(componentIds.get(referenceMetric.getTarget())).getName());
call.setCallType(components.get(referenceMetric.getTarget()));
}
try {
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(target.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
......@@ -221,7 +219,7 @@ class TopologyBuilder {
return mappings;
}
private Map<Integer, String> changeNodeCompName2Map(
private Map<Integer, String> changeNodeComp2Map(
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents) {
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(applicationComponent -> {
......@@ -230,13 +228,4 @@ 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;
}
}
......@@ -74,6 +74,7 @@ public enum OperationNameDictionary {
ServiceNameElement serviceNameElement = ServiceNameElement.newBuilder()
.setApplicationId(operationNameKey.getApplicationId())
.setServiceName(operationNameKey.getOperationName())
.setSrcSpanType(operationNameKey.getSpanType())
.build();
builder.addElements(serviceNameElement);
}
......@@ -122,9 +123,14 @@ public enum OperationNameDictionary {
OperationNameKey key = (OperationNameKey)o;
if (applicationId != key.applicationId)
return false;
return operationName.equals(key.operationName);
boolean isApplicationMatch = false;
if (applicationId == key.applicationId) {
isApplicationMatch = true;
} else if (operationName.equals(key.operationName)) {
isApplicationMatch = true;
}
return isApplicationMatch && isEntry == key.isEntry
&& isExit == key.isExit;
}
@Override public int hashCode() {
......@@ -140,5 +146,15 @@ public enum OperationNameDictionary {
boolean isExit() {
return isExit;
}
SpanType getSpanType() {
if (isEntry) {
return SpanType.Entry;
} else if (isExit) {
return SpanType.Exit;
} else {
return SpanType.Local;
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册