diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/RelationDefineUtil.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/RelationDefineUtil.java new file mode 100644 index 000000000..32ef0910d --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/RelationDefineUtil.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.oap.server.core.analysis.manual; + +import lombok.Getter; +import org.apache.skywalking.oap.server.core.Const; + +public class RelationDefineUtil { + public static String buildEntityId(RelationDefine define) { + return String.valueOf(define.source) + + Const.ID_SPLIT + String.valueOf(define.dest) + + Const.ID_SPLIT + String.valueOf(define.componentId); + } + + /** + * @param entityId + * @return 1. sourceId 2. destId 3. componentId + */ + public static RelationDefine splitEntityId(String entityId) { + String[] parts = entityId.split(Const.ID_SPLIT); + if (parts.length != 3) { + throw new RuntimeException("Illegal Service/Endpoint Relation entity id"); + } + return new RelationDefine(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])); + } + + @Getter + public static class RelationDefine { + private int source; + private int dest; + private int componentId; + + public RelationDefine(int source, int dest, int componentId) { + this.source = source; + this.dest = dest; + this.componentId = componentId; + } + } +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/endpointrelation/EndpointCallRelationDispatcher.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/endpointrelation/EndpointCallRelationDispatcher.java index 0b6190e4e..6eca47576 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/endpointrelation/EndpointCallRelationDispatcher.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/manual/endpointrelation/EndpointCallRelationDispatcher.java @@ -42,8 +42,7 @@ public class EndpointCallRelationDispatcher implements SourceDispatcher serviceRelationClientCalls, List serviceRelationServerCalls) { + Topology build(List serviceRelationClientCalls, List serviceRelationServerCalls) { filterZeroSourceOrTargetReference(serviceRelationClientCalls); filterZeroSourceOrTargetReference(serviceRelationServerCalls); Map nodes = new HashMap<>(); List calls = new LinkedList<>(); - Set callIds = new HashSet<>(); + HashMap callMap = new HashMap<>(); - for (Call clientCall : serviceRelationClientCalls) { + for (Call.CallDetail clientCall : serviceRelationClientCalls) { ServiceInventory source = serviceInventoryCache.get(clientCall.getSource()); ServiceInventory target = serviceInventoryCache.get(clientCall.getTarget()); @@ -72,20 +72,25 @@ class TopologyBuilder { } String callId = source.getSequence() + Const.ID_SPLIT + target.getSequence(); - if (!callIds.contains(callId)) { - callIds.add(callId); - + if (!callMap.containsKey(callId)) { Call call = new Call(); + + callMap.put(callId, call); + call.setSource(clientCall.getSource()); call.setTarget(clientCall.getTarget()); call.setId(clientCall.getId()); - call.setDetectPoint(DetectPoint.CLIENT); - call.setCallType(componentLibraryCatalogService.getComponentName(clientCall.getComponentId())); + call.addDetectPoint(DetectPoint.CLIENT); + call.addSourceComponent(componentLibraryCatalogService.getComponentName(clientCall.getComponentId())); calls.add(call); + } else { + Call call = callMap.get(callId); + call.addDetectPoint(DetectPoint.CLIENT); + call.addSourceComponent(componentLibraryCatalogService.getComponentName(clientCall.getComponentId())); } } - for (Call serverCall : serviceRelationServerCalls) { + for (Call.CallDetail serverCall : serviceRelationServerCalls) { ServiceInventory source = serviceInventoryCache.get(serverCall.getSource()); ServiceInventory target = serviceInventoryCache.get(serverCall.getTarget()); @@ -112,21 +117,22 @@ class TopologyBuilder { } String callId = source.getSequence() + Const.ID_SPLIT + target.getSequence(); - if (!callIds.contains(callId)) { - callIds.add(callId); - + if (!callMap.containsKey(callId)) { Call call = new Call(); + callMap.put(callId, call); + call.setSource(serverCall.getSource()); call.setTarget(serverCall.getTarget()); call.setId(serverCall.getId()); - call.setDetectPoint(DetectPoint.SERVER); - calls.add(call); + call.addDetectPoint(DetectPoint.SERVER); + call.addTargetComponent(componentLibraryCatalogService.getComponentName(serverCall.getComponentId())); - if (source.getSequence() == Const.USER_SERVICE_ID) { - call.setCallType(Const.EMPTY_STRING); - } else { - call.setCallType(componentLibraryCatalogService.getComponentName(serverCall.getComponentId())); - } + calls.add(call); + } else { + Call call = callMap.get(callId); + + call.addDetectPoint(DetectPoint.SERVER); + call.addTargetComponent(componentLibraryCatalogService.getComponentName(serverCall.getComponentId())); } if (!nodes.containsKey(source.getSequence())) { @@ -160,9 +166,9 @@ class TopologyBuilder { return serviceNode; } - private void filterZeroSourceOrTargetReference(List serviceRelationClientCalls) { + private void filterZeroSourceOrTargetReference(List serviceRelationClientCalls) { for (int i = serviceRelationClientCalls.size() - 1; i >= 0; i--) { - Call call = serviceRelationClientCalls.get(i); + Call.CallDetail call = serviceRelationClientCalls.get(i); if (call.getSource() == 0 || call.getTarget() == 0) { serviceRelationClientCalls.remove(i); } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java index 667941bf5..806e9b117 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/TopologyQueryService.java @@ -81,8 +81,8 @@ public class TopologyQueryService implements Service { public Topology getGlobalTopology(final Step step, final long startTB, final long endTB, final long startTimestamp, final long endTimestamp) throws IOException { logger.debug("step: {}, startTimeBucket: {}, endTimeBucket: {}", step, startTB, endTB); - List serviceRelationServerCalls = getTopologyQueryDAO().loadServerSideServiceRelations(step, startTB, endTB); - List serviceRelationClientCalls = getTopologyQueryDAO().loadClientSideServiceRelations(step, startTB, endTB); + List serviceRelationServerCalls = getTopologyQueryDAO().loadServerSideServiceRelations(step, startTB, endTB); + List serviceRelationClientCalls = getTopologyQueryDAO().loadClientSideServiceRelations(step, startTB, endTB); TopologyBuilder builder = new TopologyBuilder(moduleManager); Topology topology = builder.build(serviceRelationClientCalls, serviceRelationServerCalls); @@ -95,8 +95,8 @@ public class TopologyQueryService implements Service { List serviceIds = new ArrayList<>(); serviceIds.add(serviceId); - List serviceRelationClientCalls = getTopologyQueryDAO().loadSpecifiedClientSideServiceRelations(step, startTB, endTB, serviceIds); - List serviceRelationServerCalls = getTopologyQueryDAO().loadSpecifiedServerSideServiceRelations(step, startTB, endTB, serviceIds); + List serviceRelationClientCalls = getTopologyQueryDAO().loadSpecifiedClientSideServiceRelations(step, startTB, endTB, serviceIds); + List serviceRelationServerCalls = getTopologyQueryDAO().loadSpecifiedServerSideServiceRelations(step, startTB, endTB, serviceIds); TopologyBuilder builder = new TopologyBuilder(moduleManager); Topology topology = builder.build(serviceRelationClientCalls, serviceRelationServerCalls); @@ -104,10 +104,10 @@ public class TopologyQueryService implements Service { List sourceServiceIds = new ArrayList<>(); serviceRelationClientCalls.forEach(call -> sourceServiceIds.add(call.getSource())); if (CollectionUtils.isNotEmpty(sourceServiceIds)) { - List sourceCalls = getTopologyQueryDAO().loadSpecifiedServerSideServiceRelations(step, startTB, endTB, sourceServiceIds); + List sourceCalls = getTopologyQueryDAO().loadSpecifiedServerSideServiceRelations(step, startTB, endTB, sourceServiceIds); topology.getNodes().forEach(node -> { if (Strings.isNullOrEmpty(node.getType())) { - for (Call call : sourceCalls) { + for (Call.CallDetail call : sourceCalls) { if (node.getId() == call.getTarget()) { node.setType(getComponentLibraryCatalogService().getComponentName(call.getComponentId())); break; @@ -122,13 +122,17 @@ public class TopologyQueryService implements Service { public Topology getEndpointTopology(final Step step, final long startTB, final long endTB, final int endpointId) throws IOException { - List serverSideCalls = getTopologyQueryDAO().loadSpecifiedDestOfServerSideEndpointRelations(step, startTB, endTB, endpointId); - serverSideCalls.forEach(call -> call.setDetectPoint(DetectPoint.SERVER)); - - serverSideCalls.forEach(call -> call.setCallType(Const.EMPTY_STRING)); + List serverSideCalls = getTopologyQueryDAO().loadSpecifiedDestOfServerSideEndpointRelations(step, startTB, endTB, endpointId); Topology topology = new Topology(); - topology.getCalls().addAll(serverSideCalls); + serverSideCalls.forEach(callDetail -> { + Call call = new Call(); + call.setId(callDetail.getId()); + call.setSource(callDetail.getSource()); + call.setTarget(callDetail.getTarget()); + call.addDetectPoint(DetectPoint.SERVER); + topology.getCalls().add(call); + }); Set nodeIds = new HashSet<>(); serverSideCalls.forEach(call -> { diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Call.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Call.java index 650ef1830..0a518584c 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Call.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Call.java @@ -18,7 +18,9 @@ package org.apache.skywalking.oap.server.core.query.entity; +import java.util.*; import lombok.*; +import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.source.DetectPoint; /** @@ -27,10 +29,68 @@ import org.apache.skywalking.oap.server.core.source.DetectPoint; @Getter @Setter public class Call { - private int source; - private int target; - private int componentId; - private String callType; + private Integer source; + private Integer target; + private List sourceComponents; + private List targetComponents; private String id; - private DetectPoint detectPoint; + private List detectPoints; + + private List sourceComponentIDs; + private List targetComponentIDs; + + public Call() { + sourceComponents = new ArrayList<>(); + targetComponents = new ArrayList<>(); + detectPoints = new ArrayList<>(); + } + + public void setSource(int source) { + this.source = source; + } + + public void setTarget(int target) { + this.target = target; + } + + public void addSourceComponentId(int componentId) { + sourceComponentIDs.add(componentId); + } + + public void addTargetComponentId(int componentId) { + targetComponentIDs.add(componentId); + } + + public void addSourceComponent(String component) { + if (!sourceComponents.contains(component)) { + sourceComponents.add(component); + } + } + + public void addTargetComponent(String component) { + if (!targetComponents.contains(component)) { + targetComponents.add(component); + } + } + + public void addDetectPoint(DetectPoint point) { + if (!detectPoints.contains(point)) { + detectPoints.add(point); + } + } + + @Setter + @Getter + public static class CallDetail { + @Setter(AccessLevel.PRIVATE) + private String id; + private Integer source; + private Integer target; + private DetectPoint detectPoint; + private Integer componentId; + + public void generateID() { + id = source + Const.ID_SPLIT + target; + } + } } diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EndpointRelation.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EndpointRelation.java index 648daec96..f2dfd4155 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EndpointRelation.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/EndpointRelation.java @@ -34,11 +34,7 @@ public class EndpointRelation extends Source { } @Override public String getEntityId() { - return String.valueOf(endpointId) + Const.ID_SPLIT + String.valueOf(childEndpointId) + Const.ID_SPLIT + String.valueOf(componentId); - } - - public static String buildEntityId(int endpointId, int childEndpointId, int componentId) { - return String.valueOf(endpointId) + Const.ID_SPLIT + String.valueOf(childEndpointId) + Const.ID_SPLIT + String.valueOf(componentId); + return String.valueOf(endpointId) + Const.ID_SPLIT + String.valueOf(childEndpointId); } @Getter @Setter private int endpointId; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceRelation.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceRelation.java index 1f0d62b78..8f1025022 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceRelation.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/source/ServiceRelation.java @@ -34,27 +34,7 @@ public class ServiceRelation extends Source { } @Override public String getEntityId() { - return String.valueOf(sourceServiceId) + Const.ID_SPLIT + String.valueOf(destServiceId) + Const.ID_SPLIT + String.valueOf(componentId); - } - - public static String buildEntityId(int sourceServiceId, int destServiceId, int componentId) { - return String.valueOf(sourceServiceId) + Const.ID_SPLIT + String.valueOf(destServiceId) + Const.ID_SPLIT + String.valueOf(componentId); - } - - /** - * @param entityId - * @return 1. sourceServiceId 2. destServiceId 3. componentId - */ - public static Integer[] splitEntityId(String entityId) { - String[] parts = entityId.split(Const.ID_SPLIT); - if (parts.length != 3) { - throw new RuntimeException("Illegal ServiceRelation eneity id"); - } - Integer[] ids = new Integer[3]; - ids[0] = Integer.parseInt(parts[0]); - ids[1] = Integer.parseInt(parts[1]); - ids[2] = Integer.parseInt(parts[2]); - return ids; + return String.valueOf(sourceServiceId) + Const.ID_SPLIT + String.valueOf(destServiceId); } @Getter @Setter private int sourceServiceId; diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/ITopologyQueryDAO.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/ITopologyQueryDAO.java index b17a7eb87..e274dfe2d 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/ITopologyQueryDAO.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/ITopologyQueryDAO.java @@ -28,16 +28,16 @@ import org.apache.skywalking.oap.server.library.module.Service; */ public interface ITopologyQueryDAO extends Service { - List loadSpecifiedServerSideServiceRelations(Step step, long startTB, long endTB, + List loadSpecifiedServerSideServiceRelations(Step step, long startTB, long endTB, List serviceIds) throws IOException; - List loadSpecifiedClientSideServiceRelations(Step step, long startTB, long endTB, + List loadSpecifiedClientSideServiceRelations(Step step, long startTB, long endTB, List serviceIds) throws IOException; - List loadServerSideServiceRelations(Step step, long startTB, long endTB) throws IOException; + List loadServerSideServiceRelations(Step step, long startTB, long endTB) throws IOException; - List loadClientSideServiceRelations(Step step, long startTB, long endTB) throws IOException; + List loadClientSideServiceRelations(Step step, long startTB, long endTB) throws IOException; - List loadSpecifiedDestOfServerSideEndpointRelations(Step step, long startTB, long endTB, + List loadSpecifiedDestOfServerSideEndpointRelations(Step step, long startTB, long endTB, int destEndpointId) throws IOException; } diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol b/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol index 02ddbfa8d..6fc96650a 160000 --- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol +++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol @@ -1 +1 @@ -Subproject commit 02ddbfa8d84865e1a85a25f49933307970d0ab71 +Subproject commit 6fc96650acc7f539fcdf6d51648525ce93e5fa1a diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopologyQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopologyQueryEsDAO.java index 52d8e2611..b924941ab 100644 --- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopologyQueryEsDAO.java +++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/TopologyQueryEsDAO.java @@ -19,25 +19,21 @@ package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import org.apache.skywalking.oap.server.core.UnexpectedException; +import org.apache.skywalking.oap.server.core.analysis.manual.RelationDefineUtil; +import org.apache.skywalking.oap.server.core.analysis.manual.endpointrelation.EndpointRelationServerSideMetrics; import org.apache.skywalking.oap.server.core.analysis.manual.servicerelation.*; import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics; -import org.apache.skywalking.oap.server.core.analysis.manual.endpointrelation.EndpointRelationServerSideMetrics; -import org.apache.skywalking.oap.server.core.analysis.manual.servicerelation.ServiceRelationServerSideMetrics; -import org.apache.skywalking.oap.server.core.query.entity.Call; -import org.apache.skywalking.oap.server.core.query.entity.Step; +import org.apache.skywalking.oap.server.core.query.entity.*; import org.apache.skywalking.oap.server.core.source.DetectPoint; -import org.apache.skywalking.oap.server.core.source.ServiceRelation; import org.apache.skywalking.oap.server.core.storage.DownSamplingModelNameBuilder; import org.apache.skywalking.oap.server.core.storage.query.ITopologyQueryDAO; import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient; import org.apache.skywalking.oap.server.library.util.CollectionUtils; import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.index.query.BoolQueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.query.*; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.builder.SearchSourceBuilder; @@ -52,7 +48,7 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO { } @Override - public List loadSpecifiedServerSideServiceRelations(Step step, long startTB, long endTB, + public List loadSpecifiedServerSideServiceRelations(Step step, long startTB, long endTB, List serviceIds) throws IOException { if (CollectionUtils.isEmpty(serviceIds)) { throw new UnexpectedException("Service id is empty"); @@ -67,7 +63,7 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO { } @Override - public List loadSpecifiedClientSideServiceRelations(Step step, long startTB, long endTB, + public List loadSpecifiedClientSideServiceRelations(Step step, long startTB, long endTB, List serviceIds) throws IOException { if (CollectionUtils.isEmpty(serviceIds)) { throw new UnexpectedException("Service id is empty"); @@ -99,7 +95,8 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO { sourceBuilder.query(boolQuery); } - @Override public List loadServerSideServiceRelations(Step step, long startTB, long endTB) throws IOException { + @Override public List loadServerSideServiceRelations(Step step, long startTB, + long endTB) throws IOException { String indexName = DownSamplingModelNameBuilder.build(step, ServiceRelationServerSideMetrics.INDEX_NAME); SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource(); sourceBuilder.query(QueryBuilders.rangeQuery(ServiceRelationServerSideMetrics.TIME_BUCKET).gte(startTB).lte(endTB)); @@ -108,7 +105,8 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO { return load(sourceBuilder, indexName, DetectPoint.SERVER); } - @Override public List loadClientSideServiceRelations(Step step, long startTB, long endTB) throws IOException { + @Override public List loadClientSideServiceRelations(Step step, long startTB, + long endTB) throws IOException { String indexName = DownSamplingModelNameBuilder.build(step, ServiceRelationClientSideMetrics.INDEX_NAME); SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource(); sourceBuilder.query(QueryBuilders.rangeQuery(ServiceRelationServerSideMetrics.TIME_BUCKET).gte(startTB).lte(endTB)); @@ -118,7 +116,7 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO { } @Override - public List loadSpecifiedDestOfServerSideEndpointRelations(Step step, long startTB, long endTB, + public List loadSpecifiedDestOfServerSideEndpointRelations(Step step, long startTB, long endTB, int destEndpointId) throws IOException { String indexName = DownSamplingModelNameBuilder.build(step, EndpointRelationServerSideMetrics.INDEX_NAME); @@ -138,24 +136,24 @@ public class TopologyQueryEsDAO extends EsDAO implements ITopologyQueryDAO { return load(sourceBuilder, indexName, DetectPoint.SERVER); } - private List load(SearchSourceBuilder sourceBuilder, String indexName, + private List load(SearchSourceBuilder sourceBuilder, String indexName, DetectPoint detectPoint) throws IOException { sourceBuilder.aggregation(AggregationBuilders.terms(Metrics.ENTITY_ID).field(Metrics.ENTITY_ID).size(1000)); SearchResponse response = getClient().search(indexName, sourceBuilder); - List calls = new ArrayList<>(); + List calls = new ArrayList<>(); Terms entityTerms = response.getAggregations().get(Metrics.ENTITY_ID); for (Terms.Bucket entityBucket : entityTerms.getBuckets()) { String entityId = entityBucket.getKeyAsString(); - Integer[] entityIds = ServiceRelation.splitEntityId(entityId); - Call call = new Call(); - call.setId(entityId); - call.setSource(entityIds[0]); - call.setTarget(entityIds[1]); - call.setComponentId(entityIds[2]); + RelationDefineUtil.RelationDefine relationDefine = RelationDefineUtil.splitEntityId(entityId); + Call.CallDetail call = new Call.CallDetail(); + call.setSource(relationDefine.getSource()); + call.setTarget(relationDefine.getDest()); + call.setComponentId(relationDefine.getComponentId()); call.setDetectPoint(detectPoint); + call.generateID(); calls.add(call); } return calls; diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopologyQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopologyQueryDAO.java index 653c74ebd..0349b9689 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopologyQueryDAO.java +++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TopologyQueryDAO.java @@ -19,19 +19,14 @@ package org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao; import java.io.IOException; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; +import java.sql.*; +import java.util.*; +import org.apache.skywalking.oap.server.core.analysis.manual.RelationDefineUtil; import org.apache.skywalking.oap.server.core.analysis.manual.endpointrelation.EndpointRelationServerSideMetrics; import org.apache.skywalking.oap.server.core.analysis.manual.servicerelation.*; import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics; -import org.apache.skywalking.oap.server.core.analysis.manual.servicerelation.ServiceRelationServerSideMetrics; -import org.apache.skywalking.oap.server.core.query.entity.Call; -import org.apache.skywalking.oap.server.core.query.entity.Step; +import org.apache.skywalking.oap.server.core.query.entity.*; import org.apache.skywalking.oap.server.core.source.DetectPoint; -import org.apache.skywalking.oap.server.core.source.ServiceRelation; import org.apache.skywalking.oap.server.core.storage.DownSamplingModelNameBuilder; import org.apache.skywalking.oap.server.core.storage.query.ITopologyQueryDAO; import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCHikariCPClient; @@ -46,38 +41,41 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO { this.h2Client = h2Client; } - @Override public List loadSpecifiedServerSideServiceRelations(Step step, long startTB, long endTB, + @Override public List loadSpecifiedServerSideServiceRelations(Step step, long startTB, long endTB, List serviceIds) throws IOException { String tableName = DownSamplingModelNameBuilder.build(step, ServiceRelationServerSideMetrics.INDEX_NAME); return loadServiceCalls(tableName, startTB, endTB, ServiceRelationServerSideMetrics.SOURCE_SERVICE_ID, ServiceRelationServerSideMetrics.DEST_SERVICE_ID, serviceIds, true); } - @Override public List loadSpecifiedClientSideServiceRelations(Step step, long startTB, long endTB, + @Override public List loadSpecifiedClientSideServiceRelations(Step step, long startTB, long endTB, List serviceIds) throws IOException { String tableName = DownSamplingModelNameBuilder.build(step, ServiceRelationClientSideMetrics.INDEX_NAME); return loadServiceCalls(tableName, startTB, endTB, ServiceRelationServerSideMetrics.SOURCE_SERVICE_ID, ServiceRelationServerSideMetrics.DEST_SERVICE_ID, serviceIds, false); } - @Override public List loadServerSideServiceRelations(Step step, long startTB, long endTB) throws IOException { + @Override public List loadServerSideServiceRelations(Step step, long startTB, + long endTB) throws IOException { String tableName = DownSamplingModelNameBuilder.build(step, ServiceRelationServerSideMetrics.INDEX_NAME); return loadServiceCalls(tableName, startTB, endTB, ServiceRelationServerSideMetrics.SOURCE_SERVICE_ID, ServiceRelationServerSideMetrics.DEST_SERVICE_ID, new ArrayList<>(0), false); } - @Override public List loadClientSideServiceRelations(Step step, long startTB, long endTB) throws IOException { + @Override public List loadClientSideServiceRelations(Step step, long startTB, + long endTB) throws IOException { String tableName = DownSamplingModelNameBuilder.build(step, ServiceRelationClientSideMetrics.INDEX_NAME); return loadServiceCalls(tableName, startTB, endTB, ServiceRelationServerSideMetrics.SOURCE_SERVICE_ID, ServiceRelationServerSideMetrics.DEST_SERVICE_ID, new ArrayList<>(0), true); } - @Override public List loadSpecifiedDestOfServerSideEndpointRelations(Step step, long startTB, long endTB, + @Override + public List loadSpecifiedDestOfServerSideEndpointRelations(Step step, long startTB, long endTB, int destEndpointId) throws IOException { String tableName = DownSamplingModelNameBuilder.build(step, EndpointRelationServerSideMetrics.INDEX_NAME); - List calls = loadEndpointFromSide(tableName, startTB, endTB, EndpointRelationServerSideMetrics.SOURCE_ENDPOINT_ID, EndpointRelationServerSideMetrics.DEST_ENDPOINT_ID, destEndpointId, false); + List calls = loadEndpointFromSide(tableName, startTB, endTB, EndpointRelationServerSideMetrics.SOURCE_ENDPOINT_ID, EndpointRelationServerSideMetrics.DEST_ENDPOINT_ID, destEndpointId, false); calls.addAll(loadEndpointFromSide(tableName, startTB, endTB, EndpointRelationServerSideMetrics.SOURCE_ENDPOINT_ID, EndpointRelationServerSideMetrics.DEST_ENDPOINT_ID, destEndpointId, true)); return calls; } - private List loadServiceCalls(String tableName, long startTB, long endTB, String sourceCName, + private List loadServiceCalls(String tableName, long startTB, long endTB, String sourceCName, String destCName, List serviceIds, boolean isClientSide) throws IOException { Object[] conditions = new Object[serviceIds.size() * 2 + 2]; conditions[0] = startTB; @@ -95,7 +93,7 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO { } serviceIdMatchSql.append(")"); } - List calls = new ArrayList<>(); + List calls = new ArrayList<>(); try (Connection connection = h2Client.getConnection()) { try (ResultSet resultSet = h2Client.executeQuery(connection, "select " + Metrics.ENTITY_ID @@ -112,13 +110,13 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO { return calls; } - private List loadEndpointFromSide(String tableName, long startTB, long endTB, String sourceCName, + private List loadEndpointFromSide(String tableName, long startTB, long endTB, String sourceCName, String destCName, int id, boolean isSourceId) throws IOException { Object[] conditions = new Object[3]; conditions[0] = startTB; conditions[1] = endTB; conditions[2] = id; - List calls = new ArrayList<>(); + List calls = new ArrayList<>(); try (Connection connection = h2Client.getConnection()) { try (ResultSet resultSet = h2Client.executeQuery(connection, "select " + Metrics.ENTITY_ID @@ -135,17 +133,22 @@ public class H2TopologyQueryDAO implements ITopologyQueryDAO { return calls; } - private void buildCalls(ResultSet resultSet, List calls, boolean isClientSide) throws SQLException { + private void buildCalls(ResultSet resultSet, List calls, + boolean isClientSide) throws SQLException { while (resultSet.next()) { - Call call = new Call(); + Call.CallDetail call = new Call.CallDetail(); String entityId = resultSet.getString(Metrics.ENTITY_ID); - Integer[] entityIds = ServiceRelation.splitEntityId(entityId); + RelationDefineUtil.RelationDefine relationDefine = RelationDefineUtil.splitEntityId(entityId); - call.setSource(entityIds[0]); - call.setTarget(entityIds[1]); - call.setComponentId(entityIds[2]); - call.setDetectPoint(isClientSide ? DetectPoint.CLIENT : DetectPoint.SERVER); - call.setId(entityId); + call.setSource(relationDefine.getSource()); + call.setTarget(relationDefine.getDest()); + call.setComponentId(relationDefine.getComponentId()); + if (isClientSide) { + call.setDetectPoint(DetectPoint.CLIENT); + } else { + call.setDetectPoint(DetectPoint.SERVER); + } + call.generateID(); calls.add(call); } } diff --git a/skywalking-ui b/skywalking-ui index 973a272dd..f08fbcfa0 160000 --- a/skywalking-ui +++ b/skywalking-ui @@ -1 +1 @@ -Subproject commit 973a272ddf62a3ec646f33e749eb34a61fe74582 +Subproject commit f08fbcfa05915dc19d48814ad0bfa572c0309dc1