Provide the getServiceTopology query.
This commit is contained in:
parent
2c6b03bfbb
commit
62477a5318
|
|
@ -26,7 +26,7 @@
|
|||
"pii": 2, //上级的实例编号
|
||||
"psp": 1, //上级的埋点编号span_id
|
||||
"psi": 0, //上级的服务编号(org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()注册后的ID)
|
||||
"psn": "org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()", //上级的服务名
|
||||
"psn": "/dubbox-case/case/dubbox-rest", //上级的服务名
|
||||
"ni": 0, //上级调用时使用的地址注册后的ID
|
||||
"nn": "172.25.0.4:20880", //上级的地址
|
||||
"eii": 2, //入口的实例编号
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public class MetricGraphIdDefine {
|
|||
|
||||
public static final int APPLICATION_COMPONENT_GRAPH_ID = 406;
|
||||
public static final int APPLICATION_MAPPING_GRAPH_ID = 407;
|
||||
public static final int SERVICE_MAPPING_GRAPH_ID = 408;
|
||||
public static final int GLOBAL_TRACE_GRAPH_ID = 409;
|
||||
public static final int SEGMENT_DURATION_GRAPH_ID = 410;
|
||||
public static final int INSTANCE_MAPPING_GRAPH_ID = 411;
|
||||
|
|
|
|||
|
|
@ -22,35 +22,45 @@ package org.apache.skywalking.apm.collector.analysis.metric.define.graph;
|
|||
* @author peng-yongsheng
|
||||
*/
|
||||
public class MetricWorkerIdDefine {
|
||||
public static final int SERVICE_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4100;
|
||||
public static final int SERVICE_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4101;
|
||||
public static final int SERVICE_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4102;
|
||||
public static final int SERVICE_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4103;
|
||||
public static final int SERVICE_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4104;
|
||||
public static final int SERVICE_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4105;
|
||||
public static final int SERVICE_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4106;
|
||||
public static final int SERVICE_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4107;
|
||||
public static final int SERVICE_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4108;
|
||||
public static final int SERVICE_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4010;
|
||||
public static final int SERVICE_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4011;
|
||||
public static final int SERVICE_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4012;
|
||||
public static final int SERVICE_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4013;
|
||||
public static final int SERVICE_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4014;
|
||||
public static final int SERVICE_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4015;
|
||||
public static final int SERVICE_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4016;
|
||||
public static final int SERVICE_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4017;
|
||||
public static final int SERVICE_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4018;
|
||||
|
||||
public static final int INSTANCE_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4200;
|
||||
public static final int INSTANCE_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4201;
|
||||
public static final int INSTANCE_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4202;
|
||||
public static final int INSTANCE_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4203;
|
||||
public static final int INSTANCE_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4204;
|
||||
public static final int INSTANCE_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4205;
|
||||
public static final int INSTANCE_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4206;
|
||||
public static final int INSTANCE_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4207;
|
||||
public static final int INSTANCE_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4208;
|
||||
public static final int INSTANCE_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4020;
|
||||
public static final int INSTANCE_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4021;
|
||||
public static final int INSTANCE_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4022;
|
||||
public static final int INSTANCE_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4023;
|
||||
public static final int INSTANCE_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4024;
|
||||
public static final int INSTANCE_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4025;
|
||||
public static final int INSTANCE_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4026;
|
||||
public static final int INSTANCE_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4027;
|
||||
public static final int INSTANCE_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4028;
|
||||
|
||||
public static final int APPLICATION_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4300;
|
||||
public static final int APPLICATION_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4301;
|
||||
public static final int APPLICATION_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4302;
|
||||
public static final int APPLICATION_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4303;
|
||||
public static final int APPLICATION_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4304;
|
||||
public static final int APPLICATION_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4305;
|
||||
public static final int APPLICATION_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4306;
|
||||
public static final int APPLICATION_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4307;
|
||||
public static final int APPLICATION_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4308;
|
||||
public static final int APPLICATION_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4030;
|
||||
public static final int APPLICATION_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4031;
|
||||
public static final int APPLICATION_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4032;
|
||||
public static final int APPLICATION_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4033;
|
||||
public static final int APPLICATION_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4034;
|
||||
public static final int APPLICATION_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4035;
|
||||
public static final int APPLICATION_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4036;
|
||||
public static final int APPLICATION_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4037;
|
||||
public static final int APPLICATION_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4038;
|
||||
|
||||
public static final int SERVICE_MAPPING_MINUTE_AGGREGATION_WORKER_ID = 4040;
|
||||
public static final int SERVICE_MAPPING_MINUTE_REMOTE_WORKER_ID = 4041;
|
||||
public static final int SERVICE_MAPPING_MINUTE_PERSISTENCE_WORKER_ID = 4042;
|
||||
public static final int SERVICE_MAPPING_HOUR_PERSISTENCE_WORKER_ID = 4043;
|
||||
public static final int SERVICE_MAPPING_HOUR_TRANSFORM_NODE_ID = 4044;
|
||||
public static final int SERVICE_MAPPING_DAY_PERSISTENCE_WORKER_ID = 4045;
|
||||
public static final int SERVICE_MAPPING_DAY_TRANSFORM_NODE_ID = 4046;
|
||||
public static final int SERVICE_MAPPING_MONTH_PERSISTENCE_WORKER_ID = 4047;
|
||||
public static final int SERVICE_MAPPING_MONTH_TRANSFORM_NODE_ID = 4048;
|
||||
|
||||
public static final int SERVICE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4400;
|
||||
public static final int SERVICE_MINUTE_METRIC_REMOTE_WORKER_ID = 4401;
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class SegmentDurationSpanListener implements EntrySpanListener, ExitSpanL
|
|||
if (spanDecorator.getOperationNameId() == 0) {
|
||||
segmentDuration.setServiceName(spanDecorator.getOperationName());
|
||||
} else {
|
||||
segmentDuration.setServiceName(serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(spanDecorator.getOperationNameId())));
|
||||
segmentDuration.setServiceName(serviceNameCacheService.get(spanDecorator.getOperationNameId()).getServiceName());
|
||||
}
|
||||
|
||||
segmentDurations.add(segmentDuration);
|
||||
|
|
|
|||
|
|
@ -16,16 +16,14 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.skywalking.apm.collector.cache.service;
|
||||
|
||||
import org.apache.skywalking.apm.collector.core.module.Service;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface ServiceNameCacheService extends Service {
|
||||
String get(int serviceId);
|
||||
|
||||
String getSplitServiceName(String serviceName);
|
||||
ServiceName get(int serviceId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,18 +16,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.skywalking.apm.collector.cache.guava.service;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.core.util.ObjectUtils;
|
||||
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
|
||||
import org.apache.skywalking.apm.collector.core.util.StringUtils;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.core.util.ObjectUtils;
|
||||
import org.apache.skywalking.apm.collector.storage.StorageModule;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -38,7 +36,7 @@ public class ServiceNameCacheGuavaService implements ServiceNameCacheService {
|
|||
|
||||
private final Logger logger = LoggerFactory.getLogger(ServiceNameCacheGuavaService.class);
|
||||
|
||||
private final Cache<Integer, String> serviceNameCache = CacheBuilder.newBuilder().maximumSize(10000).build();
|
||||
private final Cache<Integer, ServiceName> serviceCache = CacheBuilder.newBuilder().maximumSize(10000).build();
|
||||
|
||||
private final ModuleManager moduleManager;
|
||||
private IServiceNameCacheDAO serviceNameCacheDAO;
|
||||
|
|
@ -54,34 +52,21 @@ public class ServiceNameCacheGuavaService implements ServiceNameCacheService {
|
|||
return this.serviceNameCacheDAO;
|
||||
}
|
||||
|
||||
public String get(int serviceId) {
|
||||
String serviceName = Const.EMPTY_STRING;
|
||||
public ServiceName get(int serviceId) {
|
||||
ServiceName serviceName = null;
|
||||
try {
|
||||
serviceName = serviceNameCache.get(serviceId, () -> getServiceNameCacheDAO().getServiceName(serviceId));
|
||||
serviceName = serviceCache.get(serviceId, () -> getServiceNameCacheDAO().get(serviceId));
|
||||
} catch (Throwable e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(serviceName)) {
|
||||
serviceName = getServiceNameCacheDAO().getServiceName(serviceId);
|
||||
if (StringUtils.isNotEmpty(serviceName)) {
|
||||
serviceNameCache.put(serviceId, serviceName);
|
||||
if (ObjectUtils.isEmpty(serviceName)) {
|
||||
serviceName = getServiceNameCacheDAO().get(serviceId);
|
||||
if (ObjectUtils.isNotEmpty(serviceName)) {
|
||||
serviceCache.put(serviceId, serviceName);
|
||||
}
|
||||
}
|
||||
|
||||
return serviceName;
|
||||
}
|
||||
|
||||
public String getSplitServiceName(String serviceName) {
|
||||
if (StringUtils.isNotEmpty(serviceName)) {
|
||||
String[] serviceNames = serviceName.split(Const.ID_SPLIT, 2);
|
||||
if (serviceNames.length == 2) {
|
||||
return serviceNames[1];
|
||||
} else {
|
||||
return Const.EMPTY_STRING;
|
||||
}
|
||||
} else {
|
||||
return Const.EMPTY_STRING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO;
|
|||
import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
|
|
@ -251,7 +251,7 @@ public class StorageModule extends Module {
|
|||
classes.add(IApplicationReferenceMetricUIDAO.class);
|
||||
classes.add(ISegmentDurationUIDAO.class);
|
||||
classes.add(ISegmentUIDAO.class);
|
||||
classes.add(IServiceReferenceUIDAO.class);
|
||||
classes.add(IServiceReferenceMetricUIDAO.class);
|
||||
}
|
||||
|
||||
private void addAlarmDAO(List<Class> classes) {
|
||||
|
|
|
|||
|
|
@ -19,12 +19,13 @@
|
|||
package org.apache.skywalking.apm.collector.storage.dao.cache;
|
||||
|
||||
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface IServiceNameCacheDAO extends DAO {
|
||||
String getServiceName(int serviceId);
|
||||
ServiceName get(int serviceId);
|
||||
|
||||
int getServiceId(int applicationId, String serviceName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.dao.ui;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
|
||||
|
|
@ -30,4 +33,7 @@ public interface IServiceMetricUIDAO extends DAO {
|
|||
List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, List<DurationPoint> durationPoints);
|
||||
|
||||
List<Integer> getServiceSLATrend(int serviceId, Step step, List<DurationPoint> durationPoints);
|
||||
|
||||
List<Node> getServicesMetric(Step step, long startTime, long endTime,
|
||||
MetricSource metricSource, Collection<Integer> serviceIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,26 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.dao.ui;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.storage.base.dao.DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public interface IServiceReferenceUIDAO extends DAO {
|
||||
Map<String, JsonObject> load(int entryServiceId, long startTime, long endTime);
|
||||
public interface IServiceReferenceMetricUIDAO extends DAO {
|
||||
|
||||
List<Call> getFrontServices(Step step, long startTime, long endTime,
|
||||
MetricSource metricSource, int behindServiceId);
|
||||
|
||||
List<Call> getBehindServices(Step step, long startTime, long endTime,
|
||||
MetricSource metricSource, int frontServiceId);
|
||||
|
||||
List<Call> getFrontServices(Step step, long startTime, long endTime,
|
||||
MetricSource metricSource, List<Integer> behindServiceIds);
|
||||
|
||||
List<Call> getBehindServices(Step step, long startTime, long endTime,
|
||||
MetricSource metricSource, List<Integer> frontServiceIds);
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.ui.common;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -28,6 +29,11 @@ public class Topology {
|
|||
private List<Node> nodes;
|
||||
private List<Call> calls;
|
||||
|
||||
public Topology() {
|
||||
this.nodes = new LinkedList<>();
|
||||
this.calls = new LinkedList<>();
|
||||
}
|
||||
|
||||
public List<Node> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,16 +24,16 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Node;
|
|||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ServiceNode extends Node {
|
||||
private float sla;
|
||||
private int sla;
|
||||
private long calls;
|
||||
private int numOfServiceAlarm;
|
||||
private int applicationId;
|
||||
|
||||
public float getSla() {
|
||||
public int getSla() {
|
||||
return sla;
|
||||
}
|
||||
|
||||
public void setSla(float sla) {
|
||||
public void setSla(int sla) {
|
||||
this.sla = sla;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,5 +16,4 @@
|
|||
#
|
||||
#
|
||||
|
||||
|
||||
org.apache.skywalking.apm.collector.storage.StorageModule
|
||||
org.apache.skywalking.apm.collector.storage.StorageModule
|
||||
|
|
@ -126,7 +126,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO;
|
|||
import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.base.dao.BatchEsDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchStorageInstaller;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.GlobalTraceEsPersistenceDAO;
|
||||
|
|
@ -224,7 +224,7 @@ import org.apache.skywalking.apm.collector.storage.es.dao.ui.SegmentDurationEsUI
|
|||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.SegmentEsUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.ServiceMetricEsUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.ServiceNameServiceEsUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.ServiceReferenceEsUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.dao.ui.ServiceReferenceEsMetricUIDAO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -410,7 +410,7 @@ public class StorageModuleEsProvider extends ModuleProvider {
|
|||
this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricEsUIDAO(elasticSearchClient));
|
||||
this.registerServiceImplementation(ISegmentDurationUIDAO.class, new SegmentDurationEsUIDAO(elasticSearchClient));
|
||||
this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentEsUIDAO(elasticSearchClient));
|
||||
this.registerServiceImplementation(IServiceReferenceUIDAO.class, new ServiceReferenceEsUIDAO(elasticSearchClient));
|
||||
this.registerServiceImplementation(IServiceReferenceMetricUIDAO.class, new ServiceReferenceEsMetricUIDAO(elasticSearchClient));
|
||||
}
|
||||
|
||||
private void registerAlarmDAO() throws ServiceNotProvidedException {
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
package org.apache.skywalking.apm.collector.storage.es.dao.cache;
|
||||
|
||||
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
|
||||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
|
||||
import org.elasticsearch.action.get.GetRequestBuilder;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
|
|
@ -41,16 +41,19 @@ public class ServiceNameEsCacheDAO extends EsDAO implements IServiceNameCacheDAO
|
|||
super(client);
|
||||
}
|
||||
|
||||
@Override public String getServiceName(int serviceId) {
|
||||
@Override public ServiceName get(int serviceId) {
|
||||
GetRequestBuilder getRequestBuilder = getClient().prepareGet(ServiceNameTable.TABLE, String.valueOf(serviceId));
|
||||
|
||||
GetResponse getResponse = getRequestBuilder.get();
|
||||
|
||||
if (getResponse.isExists()) {
|
||||
String serviceName = (String)getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME);
|
||||
int applicationId = ((Number)getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue();
|
||||
return applicationId + Const.ID_SPLIT + serviceName;
|
||||
ServiceName serviceName = new ServiceName();
|
||||
serviceName.setApplicationId(((Number)getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue());
|
||||
serviceName.setServiceId(serviceId);
|
||||
serviceName.setServiceName((String)getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME));
|
||||
return serviceName;
|
||||
}
|
||||
return Const.EMPTY_STRING;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public int getServiceId(int applicationId, String serviceName) {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.apache.skywalking.apm.collector.storage.es.dao.ui;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
|
||||
|
|
@ -26,12 +27,23 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
|
|||
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
|
||||
import org.elasticsearch.action.get.MultiGetItemResponse;
|
||||
import org.elasticsearch.action.get.MultiGetRequestBuilder;
|
||||
import org.elasticsearch.action.get.MultiGetResponse;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
|
|
@ -90,4 +102,45 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
|
|||
}
|
||||
return trends;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Node> getServicesMetric(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
Collection<Integer> serviceIds) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
|
||||
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
|
||||
searchRequestBuilder.setTypes(ServiceMetricTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
|
||||
boolQuery.must().add(QueryBuilders.termsQuery(ServiceMetricTable.COLUMN_SERVICE_ID, serviceIds));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
|
||||
|
||||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceMetricTable.COLUMN_SERVICE_ID).field(ServiceMetricTable.COLUMN_SERVICE_ID).size(100);
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
|
||||
|
||||
searchRequestBuilder.addAggregation(aggregationBuilder);
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
List<Node> nodes = new LinkedList<>();
|
||||
Terms serviceIdTerms = searchResponse.getAggregations().get(ServiceMetricTable.COLUMN_SERVICE_ID);
|
||||
serviceIdTerms.getBuckets().forEach(serviceIdBucket -> {
|
||||
int serviceId = serviceIdBucket.getKeyAsNumber().intValue();
|
||||
|
||||
Sum callsSum = serviceIdBucket.getAggregations().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
Sum errorCallsSum = serviceIdBucket.getAggregations().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
|
||||
|
||||
ServiceNode serviceNode = new ServiceNode();
|
||||
serviceNode.setId(serviceId);
|
||||
serviceNode.setCalls((long)callsSum.getValue());
|
||||
serviceNode.setSla((int)(((callsSum.getValue() - errorCallsSum.getValue()) / callsSum.getValue()) * 10000));
|
||||
nodes.add(serviceNode);
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* 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.apm.collector.storage.es.dao.ui;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ServiceReferenceEsMetricUIDAO extends EsDAO implements IServiceReferenceMetricUIDAO {
|
||||
|
||||
public ServiceReferenceEsMetricUIDAO(ElasticSearchClient client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
@Override public List<Call> getFrontServices(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
int behindServiceId) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE);
|
||||
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
|
||||
searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID, behindServiceId));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
|
||||
|
||||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).size(100);
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
|
||||
|
||||
searchRequestBuilder.addAggregation(aggregationBuilder);
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
List<Call> calls = new LinkedList<>();
|
||||
Terms frontServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID);
|
||||
buildNodeByBehindServiceId(calls, frontServiceIdTerms, behindServiceId);
|
||||
|
||||
return calls;
|
||||
}
|
||||
|
||||
@Override public List<Call> getBehindServices(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
int frontServiceId) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE);
|
||||
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
|
||||
searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID, frontServiceId));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
|
||||
|
||||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).size(100);
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
|
||||
|
||||
searchRequestBuilder.addAggregation(aggregationBuilder);
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
List<Call> calls = new LinkedList<>();
|
||||
Terms behindServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID);
|
||||
buildNodeByFrontServiceId(calls, behindServiceIdTerms, frontServiceId);
|
||||
|
||||
return calls;
|
||||
}
|
||||
|
||||
@Override public List<Call> getFrontServices(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
List<Integer> behindServiceIds) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE);
|
||||
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
|
||||
searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
|
||||
boolQuery.must().add(QueryBuilders.termsQuery(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID, behindServiceIds));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
|
||||
|
||||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
return executeAggregation(searchRequestBuilder);
|
||||
}
|
||||
|
||||
@Override public List<Call> getBehindServices(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
List<Integer> frontServiceIds) {
|
||||
String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE);
|
||||
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
|
||||
searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
|
||||
boolQuery.must().add(QueryBuilders.termsQuery(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID, frontServiceIds));
|
||||
boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
|
||||
|
||||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
return executeAggregation(searchRequestBuilder);
|
||||
}
|
||||
|
||||
private List<Call> executeAggregation(SearchRequestBuilder searchRequestBuilder) {
|
||||
TermsAggregationBuilder frontAggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).size(100);
|
||||
TermsAggregationBuilder behindAggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).size(100);
|
||||
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
|
||||
frontAggregationBuilder.subAggregation(behindAggregationBuilder);
|
||||
|
||||
searchRequestBuilder.addAggregation(frontAggregationBuilder);
|
||||
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
|
||||
|
||||
List<Call> nodes = new LinkedList<>();
|
||||
Terms frontServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID);
|
||||
frontServiceIdTerms.getBuckets().forEach(frontServiceIdBucket -> {
|
||||
int frontServiceId = frontServiceIdBucket.getKeyAsNumber().intValue();
|
||||
|
||||
Terms behindServiceIdTerms = frontServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID);
|
||||
buildNodeByFrontServiceId(nodes, behindServiceIdTerms, frontServiceId);
|
||||
});
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private void buildNodeByFrontServiceId(List<Call> calls, Terms behindServiceIdTerms, int frontServiceId) {
|
||||
behindServiceIdTerms.getBuckets().forEach(behindServiceIdBucket -> {
|
||||
int behindServiceId = behindServiceIdBucket.getKeyAsNumber().intValue();
|
||||
|
||||
Sum callsSum = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
Sum responseTimes = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
|
||||
Call call = new Call();
|
||||
call.setSource(frontServiceId);
|
||||
call.setTarget(behindServiceId);
|
||||
call.setCalls((int)callsSum.getValue());
|
||||
call.setResponseTimes((int)responseTimes.getValue());
|
||||
calls.add(call);
|
||||
});
|
||||
}
|
||||
|
||||
private void buildNodeByBehindServiceId(List<Call> calls, Terms frontServiceIdTerms, int behindServiceId) {
|
||||
frontServiceIdTerms.getBuckets().forEach(frontServiceIdBucket -> {
|
||||
int frontServiceId = frontServiceIdBucket.getKeyAsNumber().intValue();
|
||||
Sum callsSum = frontServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
Sum responseTimes = frontServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
|
||||
Call call = new Call();
|
||||
call.setTarget(behindServiceId);
|
||||
call.setSource(frontServiceId);
|
||||
call.setCalls((int)callsSum.getValue());
|
||||
call.setResponseTimes((int)responseTimes.getValue());
|
||||
calls.add(call);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* 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.apm.collector.storage.es.dao.ui;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
|
||||
import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils;
|
||||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ServiceReferenceEsUIDAO extends EsDAO implements IServiceReferenceUIDAO {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ServiceReferenceEsUIDAO.class);
|
||||
|
||||
public ServiceReferenceEsUIDAO(ElasticSearchClient client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, JsonObject> load(int entryServiceId, long startTime, long endTime) {
|
||||
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceReferenceMetricTable.TABLE);
|
||||
searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE);
|
||||
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
|
||||
|
||||
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
|
||||
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
|
||||
|
||||
searchRequestBuilder.setQuery(boolQuery);
|
||||
searchRequestBuilder.setSize(0);
|
||||
|
||||
return load(searchRequestBuilder);
|
||||
}
|
||||
|
||||
private Map<String, JsonObject> load(SearchRequestBuilder searchRequestBuilder) {
|
||||
searchRequestBuilder.addAggregation(AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).size(100)
|
||||
.subAggregation(AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).size(100)
|
||||
.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS))
|
||||
.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS))
|
||||
.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM))
|
||||
.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM))));
|
||||
|
||||
Map<String, JsonObject> serviceReferenceMap = new LinkedHashMap<>();
|
||||
|
||||
SearchResponse searchResponse = searchRequestBuilder.get();
|
||||
Terms frontServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID);
|
||||
for (Terms.Bucket frontServiceBucket : frontServiceIdTerms.getBuckets()) {
|
||||
int frontServiceId = frontServiceBucket.getKeyAsNumber().intValue();
|
||||
if (frontServiceId != 0) {
|
||||
parseSubAggregate(serviceReferenceMap, frontServiceBucket, frontServiceId);
|
||||
}
|
||||
}
|
||||
|
||||
return serviceReferenceMap;
|
||||
}
|
||||
|
||||
private void parseSubAggregate(Map<String, JsonObject> serviceReferenceMap,
|
||||
Terms.Bucket frontServiceBucket,
|
||||
int frontServiceId) {
|
||||
Terms behindServiceIdTerms = frontServiceBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID);
|
||||
for (Terms.Bucket behindServiceIdBucket : behindServiceIdTerms.getBuckets()) {
|
||||
int behindServiceId = behindServiceIdBucket.getKeyAsNumber().intValue();
|
||||
if (behindServiceId != 0) {
|
||||
Sum calls = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
Sum errorCalls = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
|
||||
Sum durationSum = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
Sum errorDurationSum = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
|
||||
|
||||
JsonObject serviceReference = new JsonObject();
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID), frontServiceId);
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID), behindServiceId);
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS), (long)calls.getValue());
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS), (long)errorCalls.getValue());
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM), (long)durationSum.getValue());
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM), (long)errorDurationSum.getValue());
|
||||
|
||||
String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID));
|
||||
serviceReferenceMap.put(id, serviceReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO;
|
|||
import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.base.dao.BatchH2DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.base.define.H2StorageInstaller;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.GlobalTraceH2PersistenceDAO;
|
||||
|
|
@ -220,7 +220,7 @@ import org.apache.skywalking.apm.collector.storage.h2.dao.ui.SegmentDurationH2UI
|
|||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.SegmentH2UIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ServiceMetricH2UIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ServiceNameServiceH2UIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ServiceReferenceH2UIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ServiceReferenceH2MetricUIDAO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -386,7 +386,7 @@ public class StorageModuleH2Provider extends ModuleProvider {
|
|||
this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricH2UIDAO(h2Client));
|
||||
this.registerServiceImplementation(ISegmentDurationUIDAO.class, new SegmentDurationH2UIDAO(h2Client));
|
||||
this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentH2UIDAO(h2Client));
|
||||
this.registerServiceImplementation(IServiceReferenceUIDAO.class, new ServiceReferenceH2UIDAO(h2Client));
|
||||
this.registerServiceImplementation(IServiceReferenceMetricUIDAO.class, new ServiceReferenceH2MetricUIDAO(h2Client));
|
||||
}
|
||||
|
||||
private void registerAlarmDAO() throws ServiceNotProvidedException {
|
||||
|
|
|
|||
|
|
@ -16,17 +16,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.skywalking.apm.collector.storage.h2.dao.cache;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
|
||||
import org.apache.skywalking.apm.collector.client.h2.H2Client;
|
||||
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
|
||||
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -45,21 +44,23 @@ public class ServiceNameH2CacheDAO extends H2DAO implements IServiceNameCacheDAO
|
|||
super(client);
|
||||
}
|
||||
|
||||
@Override public String getServiceName(int serviceId) {
|
||||
@Override public ServiceName get(int serviceId) {
|
||||
H2Client client = getClient();
|
||||
String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME,
|
||||
ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID);
|
||||
Object[] params = new Object[] {serviceId};
|
||||
try (ResultSet rs = client.executeQuery(sql, params)) {
|
||||
if (rs.next()) {
|
||||
String serviceName = rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME);
|
||||
int applicationId = rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID);
|
||||
return applicationId + Const.ID_SPLIT + serviceName;
|
||||
ServiceName serviceName = new ServiceName();
|
||||
serviceName.setServiceId(serviceId);
|
||||
serviceName.setApplicationId(rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID));
|
||||
serviceName.setServiceName(rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME));
|
||||
return serviceName;
|
||||
}
|
||||
} catch (SQLException | H2ClientException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return Const.EMPTY_STRING;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public int getServiceId(int applicationId, String serviceName) {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
|
|||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.client.h2.H2Client;
|
||||
|
|
@ -30,6 +31,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
|
|||
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
|
||||
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
|
||||
|
|
@ -103,4 +105,10 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
|
|||
|
||||
return trends;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Node> getServicesMetric(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
Collection<Integer> serviceIds) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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.apm.collector.storage.h2.dao.ui;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.client.h2.H2Client;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ServiceReferenceH2MetricUIDAO extends H2DAO implements IServiceReferenceMetricUIDAO {
|
||||
|
||||
public ServiceReferenceH2MetricUIDAO(H2Client client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
@Override public List<Call> getFrontServices(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
int behindServiceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public List<Call> getBehindServices(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
int frontServiceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public List<Call> getFrontServices(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
List<Integer> behindServiceIds) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public List<Call> getBehindServices(Step step, long startTime, long endTime, MetricSource metricSource,
|
||||
List<Integer> frontServiceIds) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* 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.apm.collector.storage.h2.dao.ui;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.skywalking.apm.collector.client.h2.H2Client;
|
||||
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
|
||||
import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils;
|
||||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng, clevertension
|
||||
*/
|
||||
public class ServiceReferenceH2UIDAO extends H2DAO implements IServiceReferenceUIDAO {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ServiceReferenceH2UIDAO.class);
|
||||
|
||||
public ServiceReferenceH2UIDAO(H2Client client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
private static final String GET_SRV_REF_LOAD1 = "select {3}, {4}, sum({5}) as {5}, sum({6}) as {6}, sum({7}) as {7}" +
|
||||
",sum({8}) as {8} from {0} where {1} >= ? and {1} <= ? and {2} = ? group by {3}, {4}";
|
||||
|
||||
@Override
|
||||
public Map<String, JsonObject> load(int entryServiceId, long startTime, long endTime) {
|
||||
H2Client client = getClient();
|
||||
String sql = SqlBuilder.buildSql(GET_SRV_REF_LOAD1, ServiceReferenceMetricTable.TABLE,
|
||||
ServiceReferenceMetricTable.COLUMN_TIME_BUCKET,
|
||||
ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID, ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID,
|
||||
ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS, ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM,
|
||||
ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
|
||||
Object[] params = new Object[] {startTime, endTime, entryServiceId};
|
||||
|
||||
return load(client, params, sql);
|
||||
}
|
||||
|
||||
private Map<String, JsonObject> load(H2Client client, Object[] params, String sql) {
|
||||
Map<String, JsonObject> serviceReferenceMap = new LinkedHashMap<>();
|
||||
|
||||
try (ResultSet rs = client.executeQuery(sql, params)) {
|
||||
while (rs.next()) {
|
||||
int frontServiceId = rs.getInt(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID);
|
||||
parseSubAggregate(serviceReferenceMap, rs, frontServiceId);
|
||||
}
|
||||
} catch (SQLException | H2ClientException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return serviceReferenceMap;
|
||||
}
|
||||
|
||||
private void parseSubAggregate(Map<String, JsonObject> serviceReferenceMap, ResultSet rs,
|
||||
int frontServiceId) {
|
||||
try {
|
||||
int behindServiceId = rs.getInt(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID);
|
||||
if (behindServiceId != 0) {
|
||||
long calls = rs.getLong(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
|
||||
long errorCalls = rs.getLong(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
|
||||
long durationSum = rs.getLong(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
|
||||
long errorDurationSum = rs.getLong(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
|
||||
|
||||
JsonObject serviceReference = new JsonObject();
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID), frontServiceId);
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID), behindServiceId);
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS), calls);
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS), errorCalls);
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM), durationSum);
|
||||
serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM), errorDurationSum);
|
||||
|
||||
String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID));
|
||||
serviceReferenceMap.put(id, serviceReference);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -80,10 +80,12 @@ org.apache.skywalking.apm.collector.storage.h2.define.alarm.ApplicationAlarmH2Ta
|
|||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.ApplicationAlarmListH2TableDefine
|
||||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.ApplicationReferenceAlarmH2TableDefine
|
||||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.ApplicationReferenceAlarmListH2TableDefine
|
||||
|
||||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.InstanceAlarmH2TableDefine
|
||||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.InstanceAlarmListH2TableDefine
|
||||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.InstanceReferenceAlarmH2TableDefine
|
||||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.InstanceReferenceAlarmListH2TableDefine
|
||||
|
||||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.ServiceAlarmH2TableDefine
|
||||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.ServiceAlarmListH2TableDefine
|
||||
org.apache.skywalking.apm.collector.storage.h2.define.alarm.ServiceReferenceAlarmH2TableDefine
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
|
|||
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
|
||||
import org.apache.skywalking.apm.collector.ui.graphql.Query;
|
||||
import org.apache.skywalking.apm.collector.ui.service.ServiceNameService;
|
||||
import org.apache.skywalking.apm.collector.ui.service.ServiceTopologyService;
|
||||
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
|
||||
|
||||
/**
|
||||
|
|
@ -39,6 +40,7 @@ public class ServiceQuery implements Query {
|
|||
|
||||
private final ModuleManager moduleManager;
|
||||
private ServiceNameService serviceNameService;
|
||||
private ServiceTopologyService serviceTopologyService;
|
||||
|
||||
public ServiceQuery(ModuleManager moduleManager) {
|
||||
this.moduleManager = moduleManager;
|
||||
|
|
@ -51,6 +53,13 @@ public class ServiceQuery implements Query {
|
|||
return serviceNameService;
|
||||
}
|
||||
|
||||
private ServiceTopologyService getServiceTopologyService() {
|
||||
if (ObjectUtils.isEmpty(serviceTopologyService)) {
|
||||
this.serviceTopologyService = new ServiceTopologyService(moduleManager);
|
||||
}
|
||||
return serviceTopologyService;
|
||||
}
|
||||
|
||||
public List<ServiceInfo> searchService(String keyword, int topN) throws ParseException {
|
||||
return getServiceNameService().searchService(keyword, topN);
|
||||
}
|
||||
|
|
@ -71,7 +80,9 @@ public class ServiceQuery implements Query {
|
|||
return getServiceNameService().getServiceSLATrend(serviceId, duration.getStep(), start, end);
|
||||
}
|
||||
|
||||
public Topology getServiceTopology(int serviceId, Duration duration) {
|
||||
return null;
|
||||
public Topology getServiceTopology(int serviceId, Duration duration) throws ParseException {
|
||||
long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
|
||||
long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
|
||||
return getServiceTopologyService().getServiceTopology(duration.getStep(), serviceId, start, end);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* 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.apm.collector.ui.service;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.apache.skywalking.apm.collector.cache.CacheModule;
|
||||
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.storage.StorageModule;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Call;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ServiceTopologyService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ServiceTopologyService.class);
|
||||
|
||||
private final IApplicationComponentUIDAO applicationComponentUIDAO;
|
||||
private final IServiceMetricUIDAO serviceMetricUIDAO;
|
||||
private final IServiceReferenceMetricUIDAO serviceReferenceMetricUIDAO;
|
||||
private final ServiceNameCacheService serviceNameCacheService;
|
||||
|
||||
public ServiceTopologyService(ModuleManager moduleManager) {
|
||||
this.serviceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceMetricUIDAO.class);
|
||||
this.serviceReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceReferenceMetricUIDAO.class);
|
||||
this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class);
|
||||
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
|
||||
}
|
||||
|
||||
public Topology getServiceTopology(Step step, int serviceId, long start, long end) throws ParseException {
|
||||
logger.debug("start: {}, end: {}", start, end);
|
||||
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, start, end);
|
||||
|
||||
Map<Integer, String> components = new HashMap<>();
|
||||
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
|
||||
|
||||
List<Call> calleeCalls = serviceReferenceMetricUIDAO.getFrontServices(step, start, end, MetricSource.Callee, serviceId);
|
||||
calleeCalls.addAll(serviceReferenceMetricUIDAO.getBehindServices(step, start, end, MetricSource.Caller, serviceId));
|
||||
|
||||
Set<Integer> nodeIds = new HashSet<>();
|
||||
calleeCalls.forEach(call -> {
|
||||
call.setCallType(Const.EMPTY_STRING);
|
||||
nodeIds.add(call.getSource());
|
||||
nodeIds.add(call.getTarget());
|
||||
});
|
||||
|
||||
List<Node> serviceNodes = serviceMetricUIDAO.getServicesMetric(step, start, end, MetricSource.Callee, nodeIds);
|
||||
|
||||
serviceNodes.forEach(serviceNode -> {
|
||||
ServiceName serviceName = serviceNameCacheService.get(serviceNode.getId());
|
||||
serviceNode.setName(serviceName.getServiceName());
|
||||
});
|
||||
|
||||
Topology topology = new Topology();
|
||||
topology.setCalls(calleeCalls);
|
||||
topology.setNodes(serviceNodes);
|
||||
return topology;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* 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.apm.collector.ui.service;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import org.apache.skywalking.apm.collector.cache.CacheModule;
|
||||
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
|
||||
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils;
|
||||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.core.util.ObjectUtils;
|
||||
import org.apache.skywalking.apm.collector.storage.StorageModule;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class ServiceTreeService {
|
||||
|
||||
private final IServiceReferenceUIDAO serviceReferenceDAO;
|
||||
private final ApplicationCacheService applicationCacheService;
|
||||
private final ServiceNameCacheService serviceNameCacheService;
|
||||
|
||||
public ServiceTreeService(ModuleManager moduleManager) {
|
||||
this.serviceReferenceDAO = moduleManager.find(StorageModule.NAME).getService(IServiceReferenceUIDAO.class);
|
||||
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
|
||||
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
|
||||
}
|
||||
|
||||
public JsonArray loadServiceTree(int entryServiceId, long startTime, long endTime) {
|
||||
Map<String, JsonObject> serviceReferenceMap = serviceReferenceDAO.load(entryServiceId, startTime, endTime);
|
||||
serviceReferenceMap.values().forEach(serviceReference -> {
|
||||
int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)).getAsInt();
|
||||
int behindServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
|
||||
String frontServiceName = serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(frontServiceId));
|
||||
String behindServiceName = serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(behindServiceId));
|
||||
serviceReference.addProperty("frontServiceName", frontServiceName);
|
||||
serviceReference.addProperty("behindServiceName", behindServiceName);
|
||||
});
|
||||
return buildTreeData(serviceReferenceMap);
|
||||
}
|
||||
|
||||
private JsonArray buildTreeData(Map<String, JsonObject> serviceReferenceMap) {
|
||||
JsonArray serviceReferenceArray = new JsonArray();
|
||||
JsonObject rootServiceReference = findRoot(serviceReferenceMap);
|
||||
if (ObjectUtils.isNotEmpty(rootServiceReference)) {
|
||||
serviceReferenceArray.add(rootServiceReference);
|
||||
String id = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID));
|
||||
serviceReferenceMap.remove(id);
|
||||
|
||||
int rootServiceId = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
|
||||
sortAsTree(rootServiceId, serviceReferenceArray, serviceReferenceMap);
|
||||
}
|
||||
|
||||
return serviceReferenceArray;
|
||||
}
|
||||
|
||||
private JsonObject findRoot(Map<String, JsonObject> serviceReferenceMap) {
|
||||
for (JsonObject serviceReference : serviceReferenceMap.values()) {
|
||||
int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)).getAsInt();
|
||||
if (frontServiceId == 1) {
|
||||
return serviceReference;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sortAsTree(int serviceId, JsonArray serviceReferenceArray,
|
||||
Map<String, JsonObject> serviceReferenceMap) {
|
||||
Iterator<JsonObject> iterator = serviceReferenceMap.values().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
JsonObject serviceReference = iterator.next();
|
||||
int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)).getAsInt();
|
||||
if (serviceId == frontServiceId) {
|
||||
serviceReferenceArray.add(serviceReference);
|
||||
|
||||
int behindServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt();
|
||||
sortAsTree(behindServiceId, serviceReferenceArray, serviceReferenceMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void merge(Map<String, JsonObject> serviceReferenceMap, JsonObject serviceReference) {
|
||||
String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID));
|
||||
|
||||
if (serviceReferenceMap.containsKey(id)) {
|
||||
JsonObject reference = serviceReferenceMap.get(id);
|
||||
add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
|
||||
add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
|
||||
add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
|
||||
add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM));
|
||||
} else {
|
||||
serviceReferenceMap.put(id, serviceReference);
|
||||
}
|
||||
}
|
||||
|
||||
private void add(JsonObject oldReference, JsonObject newReference, String key) {
|
||||
long oldValue = oldReference.get(key).getAsLong();
|
||||
long newValue = newReference.get(key).getAsLong();
|
||||
oldReference.addProperty(key, oldValue + newValue);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,25 +16,24 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
package org.apache.skywalking.apm.collector.ui.service;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.util.List;
|
||||
import org.apache.skywalking.apm.collector.cache.CacheModule;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
|
||||
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
|
||||
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
||||
import org.apache.skywalking.apm.collector.core.util.StringUtils;
|
||||
import org.apache.skywalking.apm.collector.storage.StorageModule;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
|
||||
import org.apache.skywalking.apm.network.proto.KeyWithStringValue;
|
||||
import org.apache.skywalking.apm.network.proto.LogMessage;
|
||||
import org.apache.skywalking.apm.network.proto.SpanObject;
|
||||
import org.apache.skywalking.apm.network.proto.TraceSegmentObject;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
|
|
@ -60,9 +59,9 @@ public class SpanService {
|
|||
if (spanId == spanObject.getSpanId()) {
|
||||
String operationName = spanObject.getOperationName();
|
||||
if (spanObject.getOperationNameId() != 0) {
|
||||
String serviceName = serviceNameCacheService.get(spanObject.getOperationNameId());
|
||||
ServiceName serviceName = serviceNameCacheService.get(spanObject.getOperationNameId());
|
||||
if (StringUtils.isNotEmpty(serviceName)) {
|
||||
operationName = serviceName.split(Const.ID_SPLIT)[1];
|
||||
operationName = serviceName.getServiceName();
|
||||
}
|
||||
}
|
||||
spanJson.addProperty("operationName", operationName);
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ import org.apache.skywalking.apm.collector.core.module.ModuleManager;
|
|||
import org.apache.skywalking.apm.collector.core.util.CollectionUtils;
|
||||
import org.apache.skywalking.apm.collector.core.util.Const;
|
||||
import org.apache.skywalking.apm.collector.core.util.ObjectUtils;
|
||||
import org.apache.skywalking.apm.collector.core.util.StringUtils;
|
||||
import org.apache.skywalking.apm.collector.storage.StorageModule;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.IGlobalTraceUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO;
|
||||
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.trace.KeyValue;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.trace.LogEntity;
|
||||
import org.apache.skywalking.apm.collector.storage.ui.trace.Ref;
|
||||
|
|
@ -137,9 +137,9 @@ public class TraceStackService {
|
|||
|
||||
String operationName = spanObject.getOperationName();
|
||||
if (spanObject.getOperationNameId() != 0) {
|
||||
String serviceName = serviceNameCacheService.get(spanObject.getOperationNameId());
|
||||
if (StringUtils.isNotEmpty(serviceName)) {
|
||||
operationName = serviceName.split(Const.ID_SPLIT)[1];
|
||||
ServiceName serviceName = serviceNameCacheService.get(spanObject.getOperationNameId());
|
||||
if (ObjectUtils.isNotEmpty(serviceName)) {
|
||||
operationName = serviceName.getServiceName();
|
||||
} else {
|
||||
operationName = Const.EMPTY_STRING;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ type ServiceNode implements Node {
|
|||
name: String!
|
||||
type: String
|
||||
# Success rate of all incoming requests.
|
||||
# Max value is 100.
|
||||
# 2 Digits after floating point.
|
||||
sla: Float!
|
||||
# Max value is 10000.
|
||||
sla: Int!
|
||||
# The number of incoming calls
|
||||
calls: Long!
|
||||
# The number of services alerting
|
||||
|
|
|
|||
Loading…
Reference in New Issue