未验证 提交 40190704 编写于 作者: wu-sheng's avatar wu-sheng 提交者: GitHub

Merge branch 'master' into master

......@@ -53,7 +53,8 @@ public class ServiceNameDiscoveryServiceHandler extends ServiceNameDiscoveryServ
for (ServiceNameElement serviceNameElement : serviceNameElementList) {
int applicationId = serviceNameElement.getApplicationId();
String serviceName = serviceNameElement.getServiceName();
int serviceId = serviceNameService.getOrCreate(applicationId, serviceName);
int srcSpanType = serviceNameElement.getSrcSpanTypeValue();
int serviceId = serviceNameService.getOrCreate(applicationId, srcSpanType, serviceName);
if (serviceId != 0) {
ServiceNameMappingElement.Builder mappingElement = ServiceNameMappingElement.newBuilder();
......
......@@ -34,6 +34,7 @@ import org.apache.skywalking.apm.network.proto.ServiceNameCollection;
import org.apache.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc;
import org.apache.skywalking.apm.network.proto.ServiceNameElement;
import org.apache.skywalking.apm.network.proto.ServiceNameMappingCollection;
import org.apache.skywalking.apm.network.proto.SpanType;
import org.apache.skywalking.apm.util.RunnableWithExceptionProtection;
import org.joda.time.DateTime;
import org.slf4j.Logger;
......@@ -95,6 +96,7 @@ class RegisterMock {
ServiceNameElement.Builder serviceNameElement = ServiceNameElement.newBuilder();
serviceNameElement.setApplicationId(applicationMapping.getApplication().getValue());
serviceNameElement.setServiceName("org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()");
serviceNameElement.setSrcSpanType(SpanType.Exit);
serviceNameCollection.addElements(serviceNameElement);
registerServiceName(serviceNameCollection);
......@@ -139,6 +141,7 @@ class RegisterMock {
ServiceNameElement.Builder serviceNameElement = ServiceNameElement.newBuilder();
serviceNameElement.setApplicationId(applicationMapping.getApplication().getValue());
serviceNameElement.setServiceName("org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()");
serviceNameElement.setSrcSpanType(SpanType.Entry);
serviceNameCollection.addElements(serviceNameElement);
registerServiceName(serviceNameCollection);
......
......@@ -44,6 +44,7 @@ public class ServiceNameDiscoveryServiceHandler extends JettyHandler {
private static final String APPLICATION_ID = "ai";
private static final String SERVICE_NAME = "sn";
private static final String SRC_SPAN_TYPE = "st";
private static final String SERVICE_ID = "si";
private static final String ELEMENT = "el";
......@@ -66,8 +67,9 @@ public class ServiceNameDiscoveryServiceHandler extends JettyHandler {
for (JsonElement service : services) {
int applicationId = service.getAsJsonObject().get(APPLICATION_ID).getAsInt();
String serviceName = service.getAsJsonObject().get(SERVICE_NAME).getAsString();
int srcSpanType = service.getAsJsonObject().get(SRC_SPAN_TYPE).getAsInt();
int serviceId = serviceNameService.getOrCreate(applicationId, serviceName);
int serviceId = serviceNameService.getOrCreate(applicationId, srcSpanType, serviceName);
if (serviceId != 0) {
JsonObject responseJson = new JsonObject();
responseJson.addProperty(SERVICE_ID, serviceId);
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.collector.analysis.register.define.service;
import org.apache.skywalking.apm.collector.core.module.Service;
......@@ -25,5 +24,5 @@ import org.apache.skywalking.apm.collector.core.module.Service;
* @author peng-yongsheng
*/
public interface IServiceNameService extends Service {
int getOrCreate(int applicationId, String serviceName);
int getOrCreate(int applicationId, int srcSpanType, String serviceName);
}
......@@ -42,7 +42,7 @@ public class ServiceNameRegisterSerialWorker extends AbstractLocalAsyncWorker<Se
private final IServiceNameRegisterDAO serviceNameRegisterDAO;
private final ServiceIdCacheService serviceIdCacheService;
public ServiceNameRegisterSerialWorker(ModuleManager moduleManager) {
ServiceNameRegisterSerialWorker(ModuleManager moduleManager) {
super(moduleManager);
this.serviceNameRegisterDAO = getModuleManager().find(StorageModule.NAME).getService(IServiceNameRegisterDAO.class);
this.serviceIdCacheService = getModuleManager().find(CacheModule.NAME).getService(ServiceIdCacheService.class);
......@@ -54,7 +54,7 @@ public class ServiceNameRegisterSerialWorker extends AbstractLocalAsyncWorker<Se
@Override protected void onWork(ServiceName serviceName) throws WorkerException {
logger.debug("register service name: {}, application id: {}", serviceName.getServiceName(), serviceName.getApplicationId());
int serviceId = serviceIdCacheService.get(serviceName.getApplicationId(), serviceName.getServiceName());
int serviceId = serviceIdCacheService.get(serviceName.getApplicationId(), serviceName.getSrcSpanType(), serviceName.getServiceName());
if (serviceId == 0) {
ServiceName newServiceName;
......@@ -62,15 +62,17 @@ public class ServiceNameRegisterSerialWorker extends AbstractLocalAsyncWorker<Se
if (min == 0) {
ServiceName noneServiceName = new ServiceName();
noneServiceName.setId("1");
noneServiceName.setApplicationId(0);
noneServiceName.setApplicationId(Const.NONE_APPLICATION_ID);
noneServiceName.setServiceId(Const.NONE_SERVICE_ID);
noneServiceName.setServiceName(Const.NONE_SERVICE_NAME);
noneServiceName.setSrcSpanType(Const.SPAN_TYPE_VIRTUAL);
serviceNameRegisterDAO.save(noneServiceName);
newServiceName = new ServiceName();
newServiceName.setId("-1");
newServiceName.setApplicationId(serviceName.getApplicationId());
newServiceName.setServiceId(-1);
newServiceName.setSrcSpanType(serviceName.getSrcSpanType());
newServiceName.setServiceName(serviceName.getServiceName());
} else {
int max = serviceNameRegisterDAO.getMaxServiceId();
......@@ -80,6 +82,7 @@ public class ServiceNameRegisterSerialWorker extends AbstractLocalAsyncWorker<Se
newServiceName.setId(String.valueOf(serviceId));
newServiceName.setApplicationId(serviceName.getApplicationId());
newServiceName.setServiceId(serviceId);
newServiceName.setSrcSpanType(serviceName.getSrcSpanType());
newServiceName.setServiceName(serviceName.getServiceName());
}
serviceNameRegisterDAO.save(newServiceName);
......
......@@ -59,14 +59,15 @@ public class ServiceNameService implements IServiceNameService {
return serviceNameRegisterGraph;
}
public int getOrCreate(int applicationId, String serviceName) {
int serviceId = getServiceIdCacheService().get(applicationId, serviceName);
@Override public int getOrCreate(int applicationId, int srcSpanType, String serviceName) {
int serviceId = getServiceIdCacheService().get(applicationId, srcSpanType, serviceName);
if (serviceId == 0) {
ServiceName service = new ServiceName();
service.setId("0");
service.setApplicationId(applicationId);
service.setServiceName(serviceName);
service.setSrcSpanType(srcSpanType);
service.setServiceId(0);
getServiceNameRegisterGraph().start(service);
......
......@@ -27,6 +27,7 @@ import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService;
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.StringUtils;
import org.apache.skywalking.apm.network.proto.SpanType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -57,7 +58,7 @@ public class ReferenceIdExchanger implements IdExchanger<ReferenceDecorator> {
@Override public boolean exchange(ReferenceDecorator standardBuilder, int applicationId) {
if (standardBuilder.getEntryServiceId() == 0 && StringUtils.isNotEmpty(standardBuilder.getEntryServiceName())) {
int entryServiceId = serviceNameService.getOrCreate(instanceCacheService.getApplicationId(standardBuilder.getEntryApplicationInstanceId()), standardBuilder.getEntryServiceName());
int entryServiceId = serviceNameService.getOrCreate(instanceCacheService.getApplicationId(standardBuilder.getEntryApplicationInstanceId()), SpanType.Entry_VALUE, standardBuilder.getEntryServiceName());
if (entryServiceId == 0) {
if (logger.isDebugEnabled()) {
......@@ -73,7 +74,7 @@ public class ReferenceIdExchanger implements IdExchanger<ReferenceDecorator> {
}
if (standardBuilder.getParentServiceId() == 0 && StringUtils.isNotEmpty(standardBuilder.getParentServiceName())) {
int parentServiceId = serviceNameService.getOrCreate(instanceCacheService.getApplicationId(standardBuilder.getParentApplicationInstanceId()), standardBuilder.getParentServiceName());
int parentServiceId = serviceNameService.getOrCreate(instanceCacheService.getApplicationId(standardBuilder.getParentApplicationInstanceId()), SpanType.Entry_VALUE, standardBuilder.getParentServiceName());
if (parentServiceId == 0) {
if (logger.isDebugEnabled()) {
......
......@@ -71,7 +71,7 @@ public class SpanIdExchanger implements IdExchanger<SpanDecorator> {
}
if (standardBuilder.getOperationNameId() == 0 && StringUtils.isNotEmpty(standardBuilder.getOperationName())) {
int operationNameId = serviceNameService.getOrCreate(applicationId, standardBuilder.getOperationName());
int operationNameId = serviceNameService.getOrCreate(applicationId, standardBuilder.getSpanTypeValue(), standardBuilder.getOperationName());
if (operationNameId == 0) {
logger.debug("service name: {} from application id: {} exchange failed", standardBuilder.getOperationName(), applicationId);
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.collector.cache.service;
import org.apache.skywalking.apm.collector.core.module.Service;
......@@ -25,5 +24,5 @@ import org.apache.skywalking.apm.collector.core.module.Service;
* @author peng-yongsheng
*/
public interface ServiceIdCacheService extends Service {
int get(int applicationId, String serviceName);
int get(int applicationId, int srcSpanType, String serviceName);
}
......@@ -16,15 +16,14 @@
*
*/
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.util.Const;
import org.apache.skywalking.apm.collector.core.util.ObjectUtils;
import org.apache.skywalking.apm.collector.cache.service.ServiceIdCacheService;
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.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO;
import org.slf4j.Logger;
......@@ -53,18 +52,19 @@ public class ServiceIdCacheGuavaService implements ServiceIdCacheService {
return this.serviceNameCacheDAO;
}
public int get(int applicationId, String serviceName) {
@Override public int get(int applicationId, int srcSpanType, String serviceName) {
int serviceId = 0;
String id = applicationId + Const.ID_SPLIT + srcSpanType + Const.ID_SPLIT + serviceName;
try {
serviceId = serviceIdCache.get(applicationId + Const.ID_SPLIT + serviceName, () -> getServiceNameCacheDAO().getServiceId(applicationId, serviceName));
serviceId = serviceIdCache.get(id, () -> getServiceNameCacheDAO().getServiceId(applicationId, srcSpanType, serviceName));
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
if (serviceId == 0) {
serviceId = getServiceNameCacheDAO().getServiceId(applicationId, serviceName);
serviceId = getServiceNameCacheDAO().getServiceId(applicationId, srcSpanType, serviceName);
if (serviceId != 0) {
serviceIdCache.put(applicationId + Const.ID_SPLIT + serviceName, serviceId);
serviceIdCache.put(id, serviceId);
}
}
return serviceId;
......
......@@ -34,4 +34,5 @@ public class Const {
public static final String EXCEPTION = "Exception";
public static final String EMPTY_STRING = "";
public static final String FILE_SUFFIX = "sw";
public static final int SPAN_TYPE_VIRTUAL = 9;
}
......@@ -27,5 +27,5 @@ import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
public interface IServiceNameCacheDAO extends DAO {
ServiceName get(int serviceId);
int getServiceId(int applicationId, String serviceName);
int getServiceId(int applicationId, int srcSpanType, String serviceName);
}
......@@ -30,4 +30,82 @@ import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
public interface IApplicationMetricUIDAO extends DAO {
List<ApplicationTPS> getTopNApplicationThroughput(Step step, long start, long end, long betweenSecond, int topN,
MetricSource metricSource);
List<ApplicationMetric> getApplications(Step step, long startTimeBucket, long endTimeBucket,
MetricSource metricSource);
class ApplicationMetric {
private int id;
private long calls;
private long errorCalls;
private long durations;
private long errorDurations;
private long satisfiedCount;
private long toleratingCount;
private long frustratedCount;
public void setId(int id) {
this.id = id;
}
public void setCalls(long calls) {
this.calls = calls;
}
public void setErrorCalls(long errorCalls) {
this.errorCalls = errorCalls;
}
public void setDurations(long durations) {
this.durations = durations;
}
public void setErrorDurations(long errorDurations) {
this.errorDurations = errorDurations;
}
public int getId() {
return id;
}
public long getCalls() {
return calls;
}
public long getErrorCalls() {
return errorCalls;
}
public long getDurations() {
return durations;
}
public long getErrorDurations() {
return errorDurations;
}
public long getSatisfiedCount() {
return satisfiedCount;
}
public void setSatisfiedCount(long satisfiedCount) {
this.satisfiedCount = satisfiedCount;
}
public long getToleratingCount() {
return toleratingCount;
}
public void setToleratingCount(long toleratingCount) {
this.toleratingCount = toleratingCount;
}
public long getFrustratedCount() {
return frustratedCount;
}
public void setFrustratedCount(long frustratedCount) {
this.frustratedCount = frustratedCount;
}
}
}
......@@ -21,18 +21,75 @@ package org.apache.skywalking.apm.collector.storage.dao.ui;
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 IApplicationReferenceMetricUIDAO extends DAO {
List<Call> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
List<ApplicationReferenceMetric> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
MetricSource metricSource);
List<Call> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
List<ApplicationReferenceMetric> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
MetricSource metricSource);
List<Call> getApplications(Step step, long startTime, long endTime, MetricSource metricSource);
List<ApplicationReferenceMetric> getReferences(Step step, long startTime, long endTime,
MetricSource metricSource);
class ApplicationReferenceMetric {
private int source;
private int target;
private long calls;
private long errorCalls;
private long durations;
private long errorDurations;
public int getSource() {
return source;
}
public void setSource(int source) {
this.source = source;
}
public int getTarget() {
return target;
}
public void setTarget(int target) {
this.target = target;
}
public long getCalls() {
return calls;
}
public void setCalls(long calls) {
this.calls = calls;
}
public long getErrorCalls() {
return errorCalls;
}
public void setErrorCalls(long errorCalls) {
this.errorCalls = errorCalls;
}
public long getDurations() {
return durations;
}
public void setDurations(long durations) {
this.durations = durations;
}
public long getErrorDurations() {
return errorDurations;
}
public void setErrorDurations(long errorDurations) {
this.errorDurations = errorDurations;
}
}
}
......@@ -38,5 +38,9 @@ public interface IInstanceUIDAO extends DAO {
List<AppServerInfo> searchServer(String keyword, long start, long end);
List<AppServerInfo> getAllServer(int applicationId, long start, long end);
List<AppServerInfo> getAllServer(int applicationId, long startSecondTimeBucket, long endSecondTimeBucket);
long getEarliestRegisterTime(int applicationId);
long getLatestHeartBeatTime(int applicationId);
}
......@@ -40,6 +40,6 @@ public interface IServiceMetricUIDAO extends DAO {
List<Node> getServicesMetric(Step step, long startTime, long endTime,
MetricSource metricSource, Collection<Integer> serviceIds);
List<ServiceMetric> getSlowService(int applicationId, Step step, long start, long end,
Integer top, MetricSource metricSource);
List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket,
Integer topN, MetricSource metricSource);
}
......@@ -32,7 +32,7 @@ public class ServerTypeDefine {
private ServerType[] serverTypes;
private ServerTypeDefine() {
this.serverTypes = new ServerType[29];
this.serverTypes = new ServerType[30];
this.serverTypeNames = new String[11];
addServerType(new ServerType(ComponentsDefine.TOMCAT.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.HTTPCLIENT.getId(), Const.NONE, Const.EMPTY_STRING));
......@@ -62,6 +62,7 @@ public class ServerTypeDefine {
addServerType(new ServerType(ComponentsDefine.HTTP_ASYNC_CLIENT.getId(), Const.NONE, Const.EMPTY_STRING));
addServerType(new ServerType(ComponentsDefine.KAFKA.getId(), 10, ComponentsDefine.KAFKA.getName()));
addServerType(new ServerType(ComponentsDefine.SERVICECOMB.getId(), Const.NONE, ComponentsDefine.SERVICECOMB.getName()));
addServerType(new ServerType(ComponentsDefine.HYSTRIX.getId(), Const.NONE, ComponentsDefine.HYSTRIX.getName()));
}
public static ServerTypeDefine getInstance() {
......
......@@ -36,10 +36,11 @@ public class ServiceName extends StreamData {
private static final Column[] LONG_COLUMNS = {};
private static final Column[] DOUBLE_COLUMNS = {};
private static final Column[] INTEGER_COLUMNS = {
new Column(ServiceNameTable.COLUMN_APPLICATION_ID, new CoverOperation()),
new Column(ServiceNameTable.COLUMN_SERVICE_ID, new CoverOperation()),
new Column(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, new CoverOperation()),
};
private static final Column[] BYTE_COLUMNS = {};
......@@ -87,4 +88,12 @@ public class ServiceName extends StreamData {
public void setServiceId(int serviceId) {
setDataInteger(1, serviceId);
}
public int getSrcSpanType() {
return getDataInteger(2);
}
public void setSrcSpanType(int srcSpanType) {
setDataInteger(2, srcSpanType);
}
}
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.collector.storage.table.register;
import org.apache.skywalking.apm.collector.core.data.CommonTable;
......@@ -27,6 +26,8 @@ import org.apache.skywalking.apm.collector.core.data.CommonTable;
public class ServiceNameTable extends CommonTable {
public static final String TABLE = "service_name";
public static final String COLUMN_SERVICE_NAME = "service_name";
public static final String COLUMN_SERVICE_NAME_KEYWORD = "service_name_keyword";
public static final String COLUMN_SRC_SPAN_TYPE = "src_span_type";
public static final String COLUMN_APPLICATION_ID = "application_id";
public static final String COLUMN_SERVICE_ID = "service_id";
}
......@@ -25,76 +25,76 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Node;
*/
public class ApplicationNode extends Node {
private Float sla;
private Long callsPerSec;
private Long responseTimePerSec;
private Float apdex;
private Boolean isAlarm;
private Integer numOfServer;
private Integer numOfServerAlarm;
private Integer numOfServiceAlarm;
public Float getSla() {
private int sla;
private long callsPerSec;
private long avgResponseTime;
private int apdex;
private boolean isAlarm;
private int numOfServer;
private int numOfServerAlarm;
private int numOfServiceAlarm;
public int getSla() {
return sla;
}
public void setSla(Float sla) {
public void setSla(int sla) {
this.sla = sla;
}
public Long getCallsPerSec() {
public long getCallsPerSec() {
return callsPerSec;
}
public void setCallsPerSec(Long callsPerSec) {
public void setCallsPerSec(long callsPerSec) {
this.callsPerSec = callsPerSec;
}
public Long getResponseTimePerSec() {
return responseTimePerSec;
public long getAvgResponseTime() {
return avgResponseTime;
}
public void setResponseTimePerSec(Long responseTimePerSec) {
this.responseTimePerSec = responseTimePerSec;
public void setAvgResponseTime(long avgResponseTime) {
this.avgResponseTime = avgResponseTime;
}
public Float getApdex() {
public int getApdex() {
return apdex;
}
public void setApdex(Float apdex) {
public void setApdex(int apdex) {
this.apdex = apdex;
}
public Boolean getAlarm() {
public boolean isAlarm() {
return isAlarm;
}
public void setAlarm(Boolean alarm) {
public void setAlarm(boolean alarm) {
isAlarm = alarm;
}
public Integer getNumOfServer() {
public int getNumOfServer() {
return numOfServer;
}
public void setNumOfServer(Integer numOfServer) {
public void setNumOfServer(int numOfServer) {
this.numOfServer = numOfServer;
}
public Integer getNumOfServerAlarm() {
public int getNumOfServerAlarm() {
return numOfServerAlarm;
}
public void setNumOfServerAlarm(Integer numOfServerAlarm) {
public void setNumOfServerAlarm(int numOfServerAlarm) {
this.numOfServerAlarm = numOfServerAlarm;
}
public Integer getNumOfServiceAlarm() {
public int getNumOfServiceAlarm() {
return numOfServiceAlarm;
}
public void setNumOfServiceAlarm(Integer numOfServiceAlarm) {
public void setNumOfServiceAlarm(int numOfServiceAlarm) {
this.numOfServiceAlarm = numOfServiceAlarm;
}
}
......@@ -28,10 +28,8 @@ public class Call {
private String targetName;
private boolean isAlert;
private String callType;
private long calls;
private long callsPerSec;
private long responseTimes;
private long responseTimePerSec;
private long avgResponseTime;
public int getSource() {
return source;
......@@ -81,14 +79,6 @@ public class Call {
this.callType = callType;
}
public long getCalls() {
return calls;
}
public void setCalls(long calls) {
this.calls = calls;
}
public long getCallsPerSec() {
return callsPerSec;
}
......@@ -97,19 +87,11 @@ public class Call {
this.callsPerSec = callsPerSec;
}
public long getResponseTimes() {
return responseTimes;
}
public void setResponseTimes(long responseTimes) {
this.responseTimes = responseTimes;
}
public long getResponseTimePerSec() {
return responseTimePerSec;
public long getAvgResponseTime() {
return avgResponseTime;
}
public void setResponseTimePerSec(long responseTimePerSec) {
this.responseTimePerSec = responseTimePerSec;
public void setAvgResponseTime(long avgResponseTime) {
this.avgResponseTime = avgResponseTime;
}
}
......@@ -24,8 +24,9 @@ package org.apache.skywalking.apm.collector.storage.ui.service;
public class ServiceMetric {
private int id;
private String name;
private long calls;
private int avgResponseTime;
private int tps;
private int callsPerSec;
public int getId() {
return id;
......@@ -51,11 +52,19 @@ public class ServiceMetric {
this.avgResponseTime = avgResponseTime;
}
public int getTps() {
return tps;
public int getCallsPerSec() {
return callsPerSec;
}
public void setTps(int tps) {
this.tps = tps;
public void setCallsPerSec(int callsPerSec) {
this.callsPerSec = callsPerSec;
}
public long getCalls() {
return calls;
}
public void setCalls(long calls) {
this.calls = calls;
}
}
......@@ -52,10 +52,10 @@ public class InstanceHeartBeatEsPersistenceDAO extends EsDAO implements IInstanc
instance.setId(id);
instance.setInstanceId(((Number)source.get(InstanceTable.COLUMN_INSTANCE_ID)).intValue());
instance.setHeartBeatTime(((Number)source.get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue());
logger.debug("getId: {} is exists", id);
logger.debug("getApplicationId: {} is exists", id);
return instance;
} else {
logger.debug("getId: {} is not exists", id);
logger.debug("getApplicationId: {} is not exists", id);
return null;
}
}
......
......@@ -53,7 +53,7 @@ public class SegmentDurationEsPersistenceDAO extends EsDAO implements ISegmentDu
}
@Override public IndexRequestBuilder prepareBatchInsert(SegmentDuration data) {
logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId());
logger.debug("segment cost prepareBatchInsert, getApplicationId: {}", data.getId());
Map<String, Object> source = new HashMap<>();
source.put(SegmentDurationTable.COLUMN_SEGMENT_ID, data.getSegmentId());
source.put(SegmentDurationTable.COLUMN_APPLICATION_ID, data.getApplicationId());
......
......@@ -56,14 +56,15 @@ public class ServiceNameEsCacheDAO extends EsDAO implements IServiceNameCacheDAO
return null;
}
@Override public int getServiceId(int applicationId, String serviceName) {
@Override public int getServiceId(int applicationId, int srcSpanType, String serviceName) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE);
searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_APPLICATION_ID, applicationId));
boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName));
boolQuery.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_APPLICATION_ID, applicationId));
boolQuery.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, srcSpanType));
boolQuery.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_SERVICE_NAME_KEYWORD, serviceName));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(1);
......
......@@ -50,7 +50,7 @@ public class ApplicationRegisterEsDAO extends EsDAO implements IApplicationRegis
}
@Override public void save(Application application) {
logger.debug("save application register info, application getId: {}, application code: {}", application.getId(), application.getApplicationCode());
logger.debug("save application register info, application getApplicationId: {}, application code: {}", application.getId(), application.getApplicationCode());
ElasticSearchClient client = getClient();
Map<String, Object> source = new HashMap<>();
source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode());
......@@ -59,6 +59,6 @@ public class ApplicationRegisterEsDAO extends EsDAO implements IApplicationRegis
source.put(ApplicationTable.COLUMN_IS_ADDRESS, application.getIsAddress());
IndexResponse response = client.prepareIndex(ApplicationTable.TABLE, application.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
logger.debug("save application register info, application getId: {}, application code: {}, status: {}", application.getApplicationId(), application.getApplicationCode(), response.status().name());
logger.debug("save application register info, application getApplicationId: {}, application code: {}, status: {}", application.getApplicationId(), application.getApplicationCode(), response.status().name());
}
}
......@@ -52,7 +52,7 @@ public class InstanceRegisterEsDAO extends EsDAO implements IInstanceRegisterDAO
}
@Override public void save(Instance instance) {
logger.debug("save instance register info, application getId: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID());
logger.debug("save instance register info, application getApplicationId: {}, agentUUID: {}", instance.getApplicationId(), instance.getAgentUUID());
ElasticSearchClient client = getClient();
Map<String, Object> source = new HashMap<>();
source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId());
......@@ -65,7 +65,7 @@ public class InstanceRegisterEsDAO extends EsDAO implements IInstanceRegisterDAO
source.put(InstanceTable.COLUMN_IS_ADDRESS, instance.getIsAddress());
IndexResponse response = client.prepareIndex(InstanceTable.TABLE, instance.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
logger.debug("save instance register info, application getId: {}, agentUUID: {}, status: {}", instance.getApplicationId(), instance.getAgentUUID(), response.status().name());
logger.debug("save instance register info, application getApplicationId: {}, agentUUID: {}, status: {}", instance.getApplicationId(), instance.getAgentUUID(), response.status().name());
}
@Override public void updateHeartbeatTime(int instanceId, long heartbeatTime) {
......
......@@ -50,7 +50,7 @@ public class NetworkAddressRegisterEsDAO extends EsDAO implements INetworkAddres
}
@Override public void save(NetworkAddress networkAddress) {
logger.debug("save network address register info, address getId: {}, network address code: {}", networkAddress.getId(), networkAddress.getNetworkAddress());
logger.debug("save network address register info, address getApplicationId: {}, network address code: {}", networkAddress.getId(), networkAddress.getNetworkAddress());
ElasticSearchClient client = getClient();
Map<String, Object> source = new HashMap<>();
source.put(NetworkAddressTable.COLUMN_NETWORK_ADDRESS, networkAddress.getNetworkAddress());
......@@ -59,7 +59,7 @@ public class NetworkAddressRegisterEsDAO extends EsDAO implements INetworkAddres
source.put(NetworkAddressTable.COLUMN_SERVER_TYPE, networkAddress.getServerType());
IndexResponse response = client.prepareIndex(NetworkAddressTable.TABLE, networkAddress.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
logger.debug("save network address register info, address getId: {}, network address code: {}, status: {}", networkAddress.getAddressId(), networkAddress.getNetworkAddress(), response.status().name());
logger.debug("save network address register info, address getApplicationId: {}, network address code: {}, status: {}", networkAddress.getAddressId(), networkAddress.getNetworkAddress(), response.status().name());
}
@Override public void update(String id, int spanLayer, int serverType) {
......
......@@ -50,14 +50,16 @@ public class ServiceNameRegisterEsDAO extends EsDAO implements IServiceNameRegis
}
@Override public void save(ServiceName serviceName) {
logger.debug("save service name register info, application getId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
logger.debug("save service name register info, application getApplicationId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
ElasticSearchClient client = getClient();
Map<String, Object> source = new HashMap<>();
source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId());
source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId());
source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName());
source.put(ServiceNameTable.COLUMN_SERVICE_NAME_KEYWORD, serviceName.getServiceName());
source.put(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, serviceName.getSrcSpanType());
IndexResponse response = client.prepareIndex(ServiceNameTable.TABLE, serviceName.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
logger.debug("save service name register info, application getId: {}, service name: {}, status: {}", serviceName.getId(), serviceName.getServiceName(), response.status().name());
logger.debug("save service name register info, application getApplicationId: {}, service name: {}, status: {}", serviceName.getId(), serviceName.getServiceName(), response.status().name());
}
}
......@@ -39,6 +39,7 @@ import org.elasticsearch.script.Script;
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;
import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders;
......@@ -88,17 +89,72 @@ public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetri
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<ApplicationTPS> applicationTPSs = new LinkedList<>();
Terms serviceIdTerms = searchResponse.getAggregations().get(ApplicationMetricTable.COLUMN_APPLICATION_ID);
serviceIdTerms.getBuckets().forEach(serviceIdTerm -> {
int applicationId = serviceIdTerm.getKeyAsNumber().intValue();
Terms applicationIdTerms = searchResponse.getAggregations().get(ApplicationMetricTable.COLUMN_APPLICATION_ID);
applicationIdTerms.getBuckets().forEach(applicationIdTerm -> {
int applicationId = applicationIdTerm.getKeyAsNumber().intValue();
ApplicationTPS serviceMetric = new ApplicationTPS();
InternalSimpleValue simpleValue = serviceIdTerm.getAggregations().get(AVG_TPS);
ApplicationTPS applicationTPS = new ApplicationTPS();
InternalSimpleValue simpleValue = applicationIdTerm.getAggregations().get(AVG_TPS);
serviceMetric.setApplicationId(applicationId);
serviceMetric.setTps((int)simpleValue.getValue());
applicationTPSs.add(serviceMetric);
applicationTPS.setApplicationId(applicationId);
applicationTPS.setTps((int)simpleValue.getValue());
applicationTPSs.add(applicationTPS);
});
return applicationTPSs;
}
@Override
public List<ApplicationMetric> getApplications(Step step, long startTimeBucket, long endTimeBucket,
MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
searchRequestBuilder.setTypes(ApplicationMetricTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(ApplicationMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
boolQuery.must().add(QueryBuilders.termQuery(ApplicationMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue()));
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationMetricTable.COLUMN_APPLICATION_ID).field(ApplicationMetricTable.COLUMN_APPLICATION_ID).size(100);
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_SATISFIED_COUNT).field(ApplicationMetricTable.COLUMN_SATISFIED_COUNT));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TOLERATING_COUNT).field(ApplicationMetricTable.COLUMN_TOLERATING_COUNT));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_FRUSTRATED_COUNT).field(ApplicationMetricTable.COLUMN_FRUSTRATED_COUNT));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<ApplicationMetric> applicationMetrics = new LinkedList<>();
Terms applicationIdTerms = searchResponse.getAggregations().get(ApplicationMetricTable.COLUMN_APPLICATION_ID);
applicationIdTerms.getBuckets().forEach(applicationIdTerm -> {
int applicationId = applicationIdTerm.getKeyAsNumber().intValue();
Sum calls = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS);
Sum errorCalls = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
Sum durations = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
Sum errorDurations = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
Sum satisfiedCount = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_SATISFIED_COUNT);
Sum toleratingCount = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_TOLERATING_COUNT);
Sum frustratedCount = applicationIdTerm.getAggregations().get(ApplicationMetricTable.COLUMN_FRUSTRATED_COUNT);
ApplicationMetric applicationMetric = new ApplicationMetric();
applicationMetric.setId(applicationId);
applicationMetric.setCalls((long)calls.getValue());
applicationMetric.setErrorCalls((long)errorCalls.getValue());
applicationMetric.setDurations((long)durations.getValue());
applicationMetric.setErrorDurations((long)errorDurations.getValue());
applicationMetric.setSatisfiedCount((long)satisfiedCount.getValue());
applicationMetric.setToleratingCount((long)toleratingCount.getValue());
applicationMetric.setToleratingCount((long)frustratedCount.getValue());
applicationMetrics.add(applicationMetric);
});
return applicationMetrics;
}
}
......@@ -25,7 +25,6 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceM
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.application.ApplicationReferenceMetricTable;
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;
......@@ -47,7 +46,8 @@ public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplica
super(client);
}
@Override public List<Call> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
@Override public List<ApplicationReferenceMetric> getFrontApplications(Step step, int applicationId, long startTime,
long endTime,
MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE);
......@@ -63,32 +63,12 @@ public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplica
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100);
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<Call> nodes = new LinkedList<>();
Terms frontApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID);
for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) {
int frontApplicationId = frontApplicationIdBucket.getKeyAsNumber().intValue();
Sum calls = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
Sum responseTimes = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
Call call = new Call();
call.setSource(frontApplicationId);
call.setTarget(applicationId);
call.setCalls((int)calls.getValue());
call.setResponseTimes((int)responseTimes.getValue());
nodes.add(call);
}
return nodes;
return buildMetrics(searchRequestBuilder);
}
@Override public List<Call> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
@Override
public List<ApplicationReferenceMetric> getBehindApplications(Step step, int applicationId, long startTime,
long endTime,
MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE);
......@@ -104,32 +84,11 @@ public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplica
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).size(100);
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<Call> nodes = new LinkedList<>();
Terms behindApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) {
int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue();
Sum calls = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
Sum responseTimes = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
Call call = new Call();
call.setTarget(behindApplicationId);
call.setSource(applicationId);
call.setCalls((int)calls.getValue());
call.setResponseTimes((int)responseTimes.getValue());
nodes.add(call);
}
return nodes;
return buildMetrics(searchRequestBuilder);
}
@Override public List<Call> getApplications(Step step, long startTime, long endTime, MetricSource metricSource) {
@Override public List<ApplicationReferenceMetric> getReferences(Step step, long startTime, long endTime,
MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
......@@ -143,35 +102,46 @@ public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplica
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100)
.subAggregation(AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<Call> nodes = new LinkedList<>();
Terms frontApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID);
for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) {
int frontApplicationId = frontApplicationIdBucket.getKeyAsNumber().intValue();
return buildMetrics(searchRequestBuilder);
}
Terms behindApplicationIdTerms = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) {
int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue();
private List<ApplicationReferenceMetric> buildMetrics(SearchRequestBuilder searchRequestBuilder) {
TermsAggregationBuilder frontAggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100);
TermsAggregationBuilder behindAggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).size(100);
frontAggregationBuilder.subAggregation(behindAggregationBuilder);
Sum calls = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
Sum responseTimes = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS));
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS));
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM));
Call call = new Call();
call.setResponseTimes((int)responseTimes.getValue());
call.setSource(frontApplicationId);
call.setTarget(behindApplicationId);
call.setCalls((int)calls.getValue());
nodes.add(call);
searchRequestBuilder.addAggregation(frontAggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<ApplicationReferenceMetric> referenceMetrics = new LinkedList<>();
Terms sourceApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID);
for (Terms.Bucket sourceApplicationIdBucket : sourceApplicationIdTerms.getBuckets()) {
int sourceApplicationId = sourceApplicationIdBucket.getKeyAsNumber().intValue();
Terms targetApplicationIdTerms = sourceApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
for (Terms.Bucket targetApplicationIdBucket : targetApplicationIdTerms.getBuckets()) {
int targetApplicationId = targetApplicationIdBucket.getKeyAsNumber().intValue();
Sum calls = targetApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
Sum errorCalls = targetApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
Sum durations = targetApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
Sum errorDurations = targetApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
ApplicationReferenceMetric referenceMetric = new ApplicationReferenceMetric();
referenceMetric.setSource(sourceApplicationId);
referenceMetric.setTarget(targetApplicationId);
referenceMetric.setCalls((long)calls.getValue());
referenceMetric.setErrorCalls((long)errorCalls.getValue());
referenceMetric.setDurations((long)durations.getValue());
referenceMetric.setErrorDurations((long)errorDurations.getValue());
referenceMetrics.add(referenceMetric);
}
}
return nodes;
return referenceMetrics;
}
}
......@@ -171,15 +171,18 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
return buildAppServerInfo(searchHits);
}
@Override public List<AppServerInfo> getAllServer(int applicationId, long start, long end) {
logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, start, end);
@Override
public List<AppServerInfo> getAllServer(int applicationId, long startSecondTimeBucket, long endSecondTimeBucket) {
logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, startSecondTimeBucket, endSecondTimeBucket);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setSize(1000);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(start).lte(end));
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_REGISTER_TIME).gte(startSecondTimeBucket).lte(endSecondTimeBucket));
boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startSecondTimeBucket));
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE));
searchRequestBuilder.setQuery(boolQuery);
......@@ -190,6 +193,46 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
return buildAppServerInfo(searchHits);
}
@Override public long getEarliestRegisterTime(int applicationId) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setSize(1);
searchRequestBuilder.setQuery(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
searchRequestBuilder.addSort(SortBuilders.fieldSort(InstanceTable.COLUMN_REGISTER_TIME).sortMode(SortMode.MIN));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
if (searchHits.length > 0) {
return ((Number)searchHits[0].getSource().get(InstanceTable.COLUMN_REGISTER_TIME)).longValue();
}
return Long.MIN_VALUE;
}
@Override public long getLatestHeartBeatTime(int applicationId) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setSize(1);
searchRequestBuilder.setQuery(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
searchRequestBuilder.addSort(SortBuilders.fieldSort(InstanceTable.COLUMN_HEARTBEAT_TIME).sortMode(SortMode.MAX));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
if (searchHits.length > 0) {
return ((Number)searchHits[0].getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue();
}
return Long.MAX_VALUE;
}
private List<AppServerInfo> buildAppServerInfo(SearchHit[] searchHits) {
List<AppServerInfo> appServerInfos = new LinkedList<>();
for (SearchHit searchHit : searchHits) {
......
......@@ -175,7 +175,9 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
return nodes;
}
@Override public List<ServiceMetric> getSlowService(int applicationId, Step step, long start, long end, Integer top,
@Override
public List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket,
Integer topN,
MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
......@@ -184,7 +186,7 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.COLUMN_TIME_BUCKET).gte(start).lte(end));
boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
if (applicationId != 0) {
boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_APPLICATION_ID, applicationId));
}
......@@ -193,7 +195,7 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
searchRequestBuilder.setQuery(boolQuery);
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceMetricTable.COLUMN_SERVICE_ID).field(ServiceMetricTable.COLUMN_SERVICE_ID).size(top);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceMetricTable.COLUMN_SERVICE_ID).field(ServiceMetricTable.COLUMN_SERVICE_ID).size(topN);
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));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM));
......@@ -221,7 +223,9 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
ServiceMetric serviceMetric = new ServiceMetric();
InternalSimpleValue simpleValue = serviceIdTerm.getAggregations().get(AVG_DURATION);
Sum calls = serviceIdTerm.getAggregations().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS);
serviceMetric.setCalls((long)calls.getValue());
serviceMetric.setId(serviceId);
serviceMetric.setAvgResponseTime((int)simpleValue.getValue());
serviceMetrics.add(serviceMetric);
......
......@@ -25,6 +25,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUID
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
import org.apache.skywalking.apm.network.proto.SpanType;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
......@@ -44,6 +45,7 @@ public class ServiceNameServiceEsUIDAO extends EsDAO implements IServiceNameServ
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE);
searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.termQuery(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, SpanType.Entry_VALUE));
searchRequestBuilder.setSize(0);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
......
......@@ -177,8 +177,8 @@ public class ServiceReferenceEsMetricUIDAO extends EsDAO implements IServiceRefe
Call call = new Call();
call.setSource(frontServiceId);
call.setTarget(behindServiceId);
call.setCalls((int)callsSum.getValue());
call.setResponseTimes((int)responseTimes.getValue());
// call.setCalls((int)callsSum.getValue());
// call.setResponseTimes((int)responseTimes.getValue());
calls.add(call);
});
}
......@@ -192,8 +192,8 @@ public class ServiceReferenceEsMetricUIDAO extends EsDAO implements IServiceRefe
Call call = new Call();
call.setTarget(behindServiceId);
call.setSource(frontServiceId);
call.setCalls((int)callsSum.getValue());
call.setResponseTimes((int)responseTimes.getValue());
// call.setCalls((int)callsSum.getValue());
// call.setResponseTimes((int)responseTimes.getValue());
calls.add(call);
});
}
......
......@@ -38,6 +38,8 @@ public class ServiceNameEsTableDefine extends ElasticSearchTableDefine {
@Override public void initialize() {
addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name()));
addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME_KEYWORD, ElasticSearchColumnDefine.Type.Keyword.name()));
addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_ID, ElasticSearchColumnDefine.Type.Integer.name()));
addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, ElasticSearchColumnDefine.Type.Integer.name()));
}
}
......@@ -47,7 +47,7 @@ public class SegmentDurationH2PersistenceDAO extends H2DAO implements ISegmentDu
}
@Override public H2SqlEntity prepareBatchInsert(SegmentDuration data) {
logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId());
logger.debug("segment cost prepareBatchInsert, getApplicationId: {}", data.getId());
H2SqlEntity entity = new H2SqlEntity();
Map<String, Object> source = new HashMap<>();
source.put(SegmentDurationTable.COLUMN_ID, data.getId());
......
......@@ -38,7 +38,7 @@ public class ServiceNameH2CacheDAO extends H2DAO implements IServiceNameCacheDAO
private final Logger logger = LoggerFactory.getLogger(ServiceNameH2CacheDAO.class);
private static final String GET_SERVICE_NAME_SQL = "select {0},{1} from {2} where {3} = ?";
private static final String GET_SERVICE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? limit 1";
private static final String GET_SERVICE_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ? and {4} = ? limit 1";
public ServiceNameH2CacheDAO(H2Client client) {
super(client);
......@@ -63,11 +63,12 @@ public class ServiceNameH2CacheDAO extends H2DAO implements IServiceNameCacheDAO
return null;
}
@Override public int getServiceId(int applicationId, String serviceName) {
@Override public int getServiceId(int applicationId, int srcSpanType, String serviceName) {
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID,
ServiceNameTable.TABLE, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME);
Object[] params = new Object[] {applicationId, serviceName};
String sql = SqlBuilder.buildSql(GET_SERVICE_ID_SQL, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.TABLE,
ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SRC_SPAN_TYPE, ServiceNameTable.COLUMN_SERVICE_NAME);
Object[] params = new Object[] {applicationId, srcSpanType, serviceName};
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
return rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID);
......
......@@ -16,18 +16,17 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.dao.register;
import java.util.HashMap;
import java.util.Map;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.register.IServiceNameRegisterDAO;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
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.register.IServiceNameRegisterDAO;
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;
......@@ -54,13 +53,14 @@ public class ServiceNameRegisterH2DAO extends H2DAO implements IServiceNameRegis
@Override
public void save(ServiceName serviceName) {
logger.debug("save service name register info, application getId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
logger.debug("save service name register info, application getApplicationId: {}, service name: {}", serviceName.getId(), serviceName.getServiceName());
H2Client client = getClient();
Map<String, Object> source = new HashMap<>();
source.put(ServiceNameTable.COLUMN_ID, serviceName.getId());
source.put(ServiceNameTable.COLUMN_SERVICE_ID, serviceName.getServiceId());
source.put(ServiceNameTable.COLUMN_APPLICATION_ID, serviceName.getApplicationId());
source.put(ServiceNameTable.COLUMN_SERVICE_NAME, serviceName.getServiceName());
source.put(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, serviceName.getSrcSpanType());
String sql = SqlBuilder.buildBatchInsertSql(ServiceNameTable.TABLE, source.keySet());
Object[] params = source.values().toArray(new Object[0]);
......
......@@ -44,4 +44,9 @@ public class ApplicationMetricH2UIDAO extends H2DAO implements IApplicationMetri
int topN, MetricSource metricSource) {
return null;
}
@Override public List<ApplicationMetric> getApplications(Step step, long startTimeBucket,
long endTimeBucket, MetricSource metricSource) {
return null;
}
}
......@@ -24,7 +24,6 @@ import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -42,7 +41,8 @@ public class ApplicationReferenceMetricH2UIDAO extends H2DAO implements IApplica
super(client);
}
@Override public List<Call> getFrontApplications(Step step, int applicationId, long startTime, long endTime,
@Override public List<ApplicationReferenceMetric> getFrontApplications(Step step, int applicationId, long startTime,
long endTime,
MetricSource metricSource) {
H2Client client = getClient();
JsonArray applicationReferenceMetricArray = new JsonArray();
......@@ -74,12 +74,16 @@ public class ApplicationReferenceMetricH2UIDAO extends H2DAO implements IApplica
return null;
}
@Override public List<Call> getBehindApplications(Step step, int applicationId, long startTime, long endTime,
@Override
public List<ApplicationReferenceMetric> getBehindApplications(Step step, int applicationId, long startTime,
long endTime,
MetricSource metricSource) {
return null;
}
@Override public List<Call> getApplications(Step step, long startTime, long endTime, MetricSource metricSource) {
@Override
public List<ApplicationReferenceMetric> getReferences(Step step, long startTime,
long endTime, MetricSource metricSource) {
return null;
}
}
......@@ -139,11 +139,12 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
return buildAppServerInfo(sql, params);
}
@Override public List<AppServerInfo> getAllServer(int applicationId, long start, long end) {
logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, start, end);
String dynamicSql = "select * from {0} where {1} = ? and {2} >= ? and {2} <= ? and {3} = ?";
String sql = SqlBuilder.buildSql(dynamicSql, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS);
Object[] params = new Object[] {applicationId, start, end, BooleanUtils.FALSE};
@Override
public List<AppServerInfo> getAllServer(int applicationId, long startSecondTimeBucket, long endSecondTimeBucket) {
logger.debug("get instances info, applicationId: {}, startSecondTimeBucket: {}, endSecondTimeBucket: {}", applicationId, startSecondTimeBucket, endSecondTimeBucket);
String dynamicSql = "select * from {0} where {1} = ? and {2} >= ? and {2} <= ? and {3} >= ? and {4} = ?";
String sql = SqlBuilder.buildSql(dynamicSql, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_REGISTER_TIME, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS);
Object[] params = new Object[] {applicationId, startSecondTimeBucket, endSecondTimeBucket, startSecondTimeBucket, BooleanUtils.FALSE};
return buildAppServerInfo(sql, params);
}
......@@ -163,4 +164,14 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
}
return appServerInfos;
}
//TODO
@Override public long getEarliestRegisterTime(int applicationId) {
return 0;
}
//TODO
@Override public long getLatestHeartBeatTime(int applicationId) {
return 0;
}
}
......@@ -116,7 +116,7 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
return null;
}
@Override public List<ServiceMetric> getSlowService(int applicationId, Step step, long start, long end, Integer top,
@Override public List<ServiceMetric> getSlowService(int applicationId, Step step, long startTimeBucket, long endTimeBucket, Integer topN,
MetricSource metricSource) {
return null;
}
......
......@@ -29,6 +29,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUID
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
import org.apache.skywalking.apm.network.proto.SpanType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -44,9 +45,9 @@ public class ServiceNameServiceH2UIDAO extends H2DAO implements IServiceNameServ
}
@Override public int getCount() {
String dynamicSql = "select count({0}) as cnt from {1}";
String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.TABLE);
Object[] params = new Object[] {};
String dynamicSql = "select count({0}) as cnt from {1} where {2} = ?";
String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SRC_SPAN_TYPE);
Object[] params = new Object[] {SpanType.Entry_VALUE};
try (ResultSet rs = getClient().executeQuery(sql, params)) {
if (rs.next()) {
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.collector.storage.h2.define.register;
import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine;
......@@ -37,5 +36,6 @@ public class ServiceNameH2TableDefine extends H2TableDefine {
addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name()));
addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_SERVICE_ID, H2ColumnDefine.Type.Int.name()));
addColumn(new H2ColumnDefine(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, H2ColumnDefine.Type.Int.name()));
}
}
......@@ -21,7 +21,9 @@ package org.apache.skywalking.apm.collector.ui.query;
import java.text.ParseException;
import java.util.List;
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.storage.ui.application.Application;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.apache.skywalking.apm.collector.storage.ui.overview.AlarmTrend;
......@@ -89,10 +91,13 @@ public class OverViewLayerQuery implements Query {
}
public Topology getClusterTopology(Duration duration) throws ParseException {
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
return getClusterTopologyService().getClusterTopology(duration.getStep(), start, end);
long startSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getClusterTopologyService().getClusterTopology(duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
}
public ClusterBrief getClusterBrief(Duration duration) throws ParseException {
......@@ -100,7 +105,22 @@ public class OverViewLayerQuery implements Query {
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
ClusterBrief clusterBrief = new ClusterBrief();
clusterBrief.setNumOfApplication(getApplicationService().getApplications(start, end).size());
List<Application> applications = getApplicationService().getApplications(start, end);
boolean containsUserApplication = false;
for (Application application : applications) {
if (application.getId() == Const.NONE_INSTANCE_ID) {
containsUserApplication = true;
break;
}
}
if (containsUserApplication) {
clusterBrief.setNumOfApplication(applications.size() - 1);
} else {
clusterBrief.setNumOfApplication(applications.size());
}
clusterBrief.setNumOfDatabase(getNetworkAddressService().getNumOfDatabase());
clusterBrief.setNumOfCache(getNetworkAddressService().getNumOfCache());
clusterBrief.setNumOfMQ(getNetworkAddressService().getNumOfMQ());
......@@ -126,10 +146,13 @@ public class OverViewLayerQuery implements Query {
}
public List<ServiceMetric> getTopNSlowService(Duration duration, int topN) throws ParseException {
long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
long startTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long endTimeBucket = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
long startSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getServiceNameService().getSlowService(duration.getStep(), start, end, topN);
return getServiceNameService().getSlowService(duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket, topN);
}
public List<ApplicationTPS> getTopNApplicationThroughput(Duration duration,
......
......@@ -75,7 +75,7 @@ public class ApplicationService {
slowServices.forEach(slowService -> {
slowService.setName(serviceNameCacheService.get(slowService.getId()).getServiceName());
//TODO
slowService.setTps(1);
slowService.setCallsPerSec(1);
});
return slowServices;
}
......
......@@ -20,20 +20,15 @@ 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.core.module.ModuleManager;
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.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
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;
import org.apache.skywalking.apm.collector.storage.ui.common.Topology;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -66,64 +61,64 @@ public class ApplicationTopologyService {
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
List<Call> callerCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Caller);
callerCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Caller));
callerCalls.forEach(callerCall -> callerCall.setCallType(components.get(callerCall.getTarget())));
List<Call> calleeCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Callee);
calleeCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Callee));
calleeCalls.forEach(calleeCall -> calleeCall.setCallType(components.get(calleeCall.getTarget())));
Set<Integer> mappings = new HashSet<>();
applicationMappings.forEach(mapping -> {
if (applicationId == mapping.getApplicationId()) {
mappings.add(mapping.getMappingApplicationId());
}
});
mappings.forEach(mappingApplicationId -> {
List<Call> frontCallerApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
frontCallerApplications.forEach(call -> {
call.setCallType(components.get(call.getTarget()));
call.setTarget(applicationId);
callerCalls.add(call);
});
List<Call> behindCallerApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
behindCallerApplications.forEach(call -> {
call.setCallType(components.get(call.getTarget()));
call.setSource(applicationId);
callerCalls.add(call);
});
List<Call> frontCalleeApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
frontCalleeApplications.forEach(call -> {
call.setCallType(components.get(call.getTarget()));
call.setTarget(applicationId);
calleeCalls.add(call);
});
List<Call> behindCalleeApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
behindCalleeApplications.forEach(call -> {
call.setCallType(components.get(call.getTarget()));
call.setSource(applicationId);
calleeCalls.add(call);
});
});
// List<Call> callerCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Caller);
// callerCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Caller));
//
// callerCalls.forEach(callerCall -> callerCall.setCallType(components.get(callerCall.getTarget())));
//
// List<Call> calleeCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Callee);
// calleeCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Callee));
//
// calleeCalls.forEach(calleeCall -> calleeCall.setCallType(components.get(calleeCall.getTarget())));
//
// Set<Integer> mappings = new HashSet<>();
// applicationMappings.forEach(mapping -> {
// if (applicationId == mapping.getApplicationId()) {
// mappings.add(mapping.getMappingApplicationId());
// }
// });
//
// mappings.forEach(mappingApplicationId -> {
// List<Call> frontCallerApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
// frontCallerApplications.forEach(call -> {
// call.setCallType(components.get(call.getTarget()));
// call.setTarget(applicationId);
// callerCalls.add(call);
// });
//
// List<Call> behindCallerApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller);
// behindCallerApplications.forEach(call -> {
// call.setCallType(components.get(call.getTarget()));
// call.setSource(applicationId);
// callerCalls.add(call);
// });
//
// List<Call> frontCalleeApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
// frontCalleeApplications.forEach(call -> {
// call.setCallType(components.get(call.getTarget()));
// call.setTarget(applicationId);
// calleeCalls.add(call);
// });
//
// List<Call> behindCalleeApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee);
// behindCalleeApplications.forEach(call -> {
// call.setCallType(components.get(call.getTarget()));
// call.setSource(applicationId);
// calleeCalls.add(call);
// });
// });
TopologyBuilder builder = new TopologyBuilder(moduleManager);
long secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTime, endTime);
Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween);
topology.getCalls().forEach(call -> {
long calls = call.getCalls();
long responseTimes = call.getResponseTimes();
call.setCallsPerSec(calls / secondsBetween);
call.setResponseTimePerSec(responseTimes / secondsBetween);
});
return topology;
// long secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTime, endTime);
// Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween);
//
// topology.getCalls().forEach(call -> {
// long calls = call.getCalls();
// long responseTimes = call.getResponseTimes();
// call.setCallsPerSec(calls / secondsBetween);
// call.setAvgResponseTime(responseTimes / secondsBetween);
// });
return null;
}
}
......@@ -26,12 +26,11 @@ import org.apache.skywalking.apm.collector.core.module.ModuleManager;
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.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.table.MetricSource;
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.ui.common.Topology;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -45,6 +44,7 @@ public class ClusterTopologyService {
private final IApplicationComponentUIDAO applicationComponentUIDAO;
private final IApplicationMappingUIDAO applicationMappingUIDAO;
private final IApplicationMetricUIDAO applicationMetricUIDAO;
private final IApplicationReferenceMetricUIDAO applicationReferenceMetricUIDAO;
private final ModuleManager moduleManager;
......@@ -52,35 +52,26 @@ public class ClusterTopologyService {
this.moduleManager = moduleManager;
this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class);
this.applicationMappingUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingUIDAO.class);
this.applicationMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMetricUIDAO.class);
this.applicationReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricUIDAO.class);
}
public Topology getClusterTopology(Step step, long startTime, long endTime) throws ParseException {
logger.debug("startTime: {}, endTime: {}", startTime, endTime);
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTime, endTime);
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTime, endTime);
public Topology getClusterTopology(Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket,
long endSecondTimeBucket) throws ParseException {
logger.debug("startTimeBucket: {}, endTimeBucket: {}, startSecondTimeBucket: {}, endSecondTimeBucket: {}", startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTimeBucket, endTimeBucket);
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTimeBucket, endTimeBucket);
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
List<Call> callerCalls = applicationReferenceMetricUIDAO.getApplications(step, startTime, endTime, MetricSource.Caller);
callerCalls.forEach(callerCall -> callerCall.setCallType(components.get(callerCall.getTarget())));
List<IApplicationMetricUIDAO.ApplicationMetric> applicationMetrics = applicationMetricUIDAO.getApplications(step, startTimeBucket, endTimeBucket, MetricSource.Callee);
List<Call> calleeCalls = applicationReferenceMetricUIDAO.getApplications(step, startTime, endTime, MetricSource.Callee);
calleeCalls.forEach(calleeCall -> calleeCall.setCallType(components.get(calleeCall.getTarget())));
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> callerReferenceMetric = applicationReferenceMetricUIDAO.getReferences(step, startTimeBucket, endTimeBucket, MetricSource.Caller);
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric = applicationReferenceMetricUIDAO.getReferences(step, startTimeBucket, endTimeBucket, MetricSource.Callee);
TopologyBuilder builder = new TopologyBuilder(moduleManager);
long secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTime, endTime);
Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween);
topology.getCalls().forEach(call -> {
long calls = call.getCalls();
long responseTimes = call.getResponseTimes();
call.setCallsPerSec(calls / secondsBetween);
call.setResponseTimePerSec(responseTimes / secondsBetween);
});
return topology;
return builder.build(applicationComponents, applicationMappings, applicationMetrics, callerReferenceMetric, calleeReferenceMetric, startSecondTimeBucket, endSecondTimeBucket);
}
}
/*
* 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.text.SimpleDateFormat;
import java.util.Date;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
import org.joda.time.DateTime;
import org.joda.time.Seconds;
/**
* @author peng-yongsheng
*/
class SecondBetweenService {
private final IInstanceUIDAO instanceUIDAO;
SecondBetweenService(ModuleManager moduleManager) {
this.instanceUIDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class);
}
int calculate(int applicationId, long startSecondTimeBucket,
long endSecondTimeBucket) throws ParseException {
long registerTime = instanceUIDAO.getEarliestRegisterTime(applicationId);
if (startSecondTimeBucket < registerTime) {
startSecondTimeBucket = registerTime;
}
long heartBeatTime = instanceUIDAO.getLatestHeartBeatTime(applicationId);
if (endSecondTimeBucket > heartBeatTime) {
endSecondTimeBucket = heartBeatTime;
}
Date startDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(startSecondTimeBucket));
Date endDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(endSecondTimeBucket));
return Seconds.secondsBetween(new DateTime(startDate), new DateTime(endDate)).getSeconds();
}
}
......@@ -27,6 +27,7 @@ import org.apache.skywalking.apm.collector.storage.StorageModule;
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.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
import org.apache.skywalking.apm.collector.storage.ui.common.SLATrend;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
......@@ -35,20 +36,26 @@ import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
public class ServiceNameService {
private final Logger logger = LoggerFactory.getLogger(ServiceNameService.class);
private final IServiceNameServiceUIDAO serviceNameServiceUIDAO;
private final IServiceMetricUIDAO serviceMetricUIDAO;
private final ServiceNameCacheService serviceNameCacheService;
private final SecondBetweenService secondBetweenService;
public ServiceNameService(ModuleManager moduleManager) {
this.serviceNameServiceUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceNameServiceUIDAO.class);
this.serviceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceMetricUIDAO.class);
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
this.secondBetweenService = new SecondBetweenService(moduleManager);
}
public int getCount() {
......@@ -85,13 +92,18 @@ public class ServiceNameService {
return slaTrend;
}
public List<ServiceMetric> getSlowService(Step step, long start, long end,
Integer top) throws ParseException {
List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(0, step, start, end, top, MetricSource.Callee);
public List<ServiceMetric> getSlowService(Step step, long startTimeBucket, long endTimeBucket,
long startSecondTimeBucket, long endSecondTimeBucket,
Integer topN) throws ParseException {
List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(0, step, startTimeBucket, endTimeBucket, topN, MetricSource.Callee);
slowServices.forEach(slowService -> {
slowService.setName(serviceNameCacheService.get(slowService.getId()).getServiceName());
//TODO
slowService.setTps(1);
ServiceName serviceName = serviceNameCacheService.get(slowService.getId());
slowService.setName(serviceName.getServiceName());
try {
slowService.setCallsPerSec((int)(slowService.getCalls() / secondBetweenService.calculate(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
});
return slowServices;
}
......
......@@ -18,12 +18,11 @@
package org.apache.skywalking.apm.collector.ui.service;
import java.text.ParseException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
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.ApplicationCacheService;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
......@@ -31,6 +30,8 @@ import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.table.register.Application;
import org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode;
import org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode;
......@@ -38,72 +39,134 @@ 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.Topology;
import org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode;
import org.apache.skywalking.apm.collector.ui.utils.ApdexCalculator;
import org.apache.skywalking.apm.collector.ui.utils.SLACalculator;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author peng-yongsheng
*/
class TopologyBuilder {
private final Logger logger = LoggerFactory.getLogger(TopologyBuilder.class);
private final ApplicationCacheService applicationCacheService;
private final ServerService serverService;
private final SecondBetweenService secondBetweenService;
TopologyBuilder(ModuleManager moduleManager) {
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
this.serverService = new ServerService(moduleManager);
this.secondBetweenService = new SecondBetweenService(moduleManager);
}
Topology build(List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents,
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings, List<Call> callerCalls,
List<Call> calleeCalls, long secondsBetween) {
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings,
List<IApplicationMetricUIDAO.ApplicationMetric> applicationMetrics,
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> callerReferenceMetric,
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric,
long startSecondTimeBucket, long endSecondTimeBucket) {
Map<Integer, String> components = changeNodeComp2Map(applicationComponents);
Map<String, String> mappings = changeMapping2Map(applicationMappings);
Map<Integer, Integer> mappings = changeMapping2Map(applicationMappings);
List<Call> calls = buildCalls(callerCalls, calleeCalls);
calleeReferenceMetric = calleeReferenceMetricFilter(calleeReferenceMetric);
Set<Integer> nodeIds = new HashSet<>();
calls.forEach(call -> {
String sourceName = applicationCacheService.getApplicationById(call.getSource()).getApplicationCode();
String targetName = applicationCacheService.getApplicationById(call.getTarget()).getApplicationCode();
List<Node> nodes = new LinkedList<>();
applicationMetrics.forEach(applicationMetric -> {
int applicationId = applicationMetric.getId();
Application application = applicationCacheService.getApplicationById(applicationId);
ApplicationNode applicationNode = new ApplicationNode();
applicationNode.setId(applicationId);
applicationNode.setName(application.getApplicationCode());
applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
applicationNode.setSla(SLACalculator.INSTANCE.calculate(applicationMetric.getErrorCalls(), applicationMetric.getCalls()));
try {
applicationNode.setCallsPerSec(applicationMetric.getCalls() / secondBetweenService.calculate(applicationId, startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
applicationNode.setAvgResponseTime((applicationMetric.getDurations() - applicationMetric.getErrorDurations()) / (applicationMetric.getCalls() - applicationMetric.getErrorCalls()));
applicationNode.setApdex(ApdexCalculator.INSTANCE.calculate(applicationMetric.getSatisfiedCount(), applicationMetric.getToleratingCount(), applicationMetric.getFrustratedCount()));
applicationNode.setAlarm(false);
applicationNode.setNumOfServer(serverService.getAllServer(applicationId, startSecondTimeBucket, endSecondTimeBucket).size());
applicationNode.setNumOfServerAlarm(1);
applicationNode.setNumOfServiceAlarm(1);
nodes.add(applicationNode);
});
call.setSourceName(sourceName);
call.setTargetName(targetName);
List<Call> calls = new LinkedList<>();
callerReferenceMetric.forEach(referenceMetric -> {
Application source = applicationCacheService.getApplicationById(referenceMetric.getSource());
Application target = applicationCacheService.getApplicationById(referenceMetric.getTarget());
if (BooleanUtils.valueToBoolean(target.getIsAddress()) && !mappings.containsKey(target.getApplicationId())) {
ConjecturalNode conjecturalNode = new ConjecturalNode();
conjecturalNode.setId(target.getApplicationId());
conjecturalNode.setName(target.getApplicationCode());
conjecturalNode.setType(components.getOrDefault(target.getApplicationId(), Const.UNKNOWN));
nodes.add(conjecturalNode);
}
nodeIds.add(call.getSource());
nodeIds.add(call.getTarget());
Call call = new Call();
call.setSource(source.getApplicationId());
call.setSourceName(source.getApplicationCode());
int actualTargetId = mappings.getOrDefault(target.getApplicationId(), target.getApplicationId());
call.setTarget(actualTargetId);
call.setTargetName(applicationCacheService.getApplicationById(actualTargetId).getApplicationCode());
call.setAlert(true);
call.setCallType(components.get(referenceMetric.getTarget()));
try {
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(source.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
call.setAvgResponseTime((referenceMetric.getDurations() - referenceMetric.getErrorDurations()) / (referenceMetric.getCalls() - referenceMetric.getErrorCalls()));
calls.add(call);
});
List<Node> nodes = new LinkedList<>();
nodeIds.forEach(nodeId -> {
Application application = applicationCacheService.getApplicationById(nodeId);
if (BooleanUtils.valueToBoolean(application.getAddressId())) {
calleeReferenceMetric.forEach(referenceMetric -> {
Application source = applicationCacheService.getApplicationById(referenceMetric.getSource());
Application target = applicationCacheService.getApplicationById(referenceMetric.getTarget());
if (source.getApplicationId() == Const.NONE_APPLICATION_ID) {
VisualUserNode visualUserNode = new VisualUserNode();
visualUserNode.setId(source.getApplicationId());
visualUserNode.setName(Const.USER_CODE);
visualUserNode.setType(Const.USER_CODE.toUpperCase());
nodes.add(visualUserNode);
}
if (BooleanUtils.valueToBoolean(source.getIsAddress())) {
ConjecturalNode conjecturalNode = new ConjecturalNode();
conjecturalNode.setId(nodeId);
conjecturalNode.setName(application.getApplicationCode());
conjecturalNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
conjecturalNode.setId(source.getApplicationId());
conjecturalNode.setName(source.getApplicationCode());
conjecturalNode.setType(components.getOrDefault(source.getApplicationId(), Const.UNKNOWN));
nodes.add(conjecturalNode);
}
Call call = new Call();
call.setSource(source.getApplicationId());
call.setSourceName(source.getApplicationCode());
call.setTarget(target.getApplicationId());
call.setTargetName(target.getApplicationCode());
call.setAlert(true);
if (source.getApplicationId() == Const.NONE_APPLICATION_ID) {
call.setCallType(Const.EMPTY_STRING);
} else {
if (nodeId == Const.NONE_APPLICATION_ID) {
VisualUserNode node = new VisualUserNode();
node.setId(nodeId);
node.setName(Const.USER_CODE);
node.setType(Const.USER_CODE.toUpperCase());
nodes.add(node);
} else {
ApplicationNode applicationNode = new ApplicationNode();
applicationNode.setId(nodeId);
applicationNode.setName(application.getApplicationCode());
applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
calleeCalls.forEach(call -> {
if (call.getTarget() == nodeId) {
call.setCallsPerSec(call.getCalls() / secondsBetween);
call.setResponseTimePerSec(call.getResponseTimes() / secondsBetween);
}
});
applicationNode.setCallsPerSec(100L);
applicationNode.setResponseTimePerSec(100L);
nodes.add(applicationNode);
}
call.setCallType(components.get(referenceMetric.getTarget()));
}
try {
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(target.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
call.setAvgResponseTime((referenceMetric.getDurations() - referenceMetric.getErrorDurations()) / (referenceMetric.getCalls() - referenceMetric.getErrorCalls()));
calls.add(call);
});
Topology topology = new Topology();
......@@ -112,14 +175,24 @@ class TopologyBuilder {
return topology;
}
private Map<String, String> changeMapping2Map(
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings) {
Map<String, String> mappings = new HashMap<>();
applicationMappings.forEach(applicationMapping -> {
String applicationCode = applicationCacheService.getApplicationById(applicationMapping.getApplicationId()).getApplicationCode();
String address = applicationCacheService.getApplicationById(applicationMapping.getMappingApplicationId()).getApplicationCode();
mappings.put(address, applicationCode);
private List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetricFilter(
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric) {
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> filteredMetrics = new LinkedList<>();
calleeReferenceMetric.forEach(referenceMetric -> {
Application source = applicationCacheService.getApplicationById(referenceMetric.getSource());
if (BooleanUtils.valueToBoolean(source.getIsAddress()) || source.getApplicationId() == Const.NONE_APPLICATION_ID) {
filteredMetrics.add(referenceMetric);
}
});
return filteredMetrics;
}
private Map<Integer, Integer> changeMapping2Map(
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings) {
Map<Integer, Integer> mappings = new HashMap<>();
applicationMappings.forEach(applicationMapping -> mappings.put(applicationMapping.getMappingApplicationId(), applicationMapping.getApplicationId()));
return mappings;
}
......@@ -132,24 +205,4 @@ class TopologyBuilder {
});
return components;
}
private List<Call> buildCalls(List<Call> callerCalls, List<Call> calleeCalls) {
List<Call> calls = new LinkedList<>();
Set<String> distinctCalls = new HashSet<>();
callerCalls.forEach(callerCall -> {
distinctCalls.add(callerCall.getSource() + Const.ID_SPLIT + callerCall.getTarget());
calls.add(callerCall);
});
calleeCalls.forEach(calleeCall -> {
String call = calleeCall.getSource() + Const.ID_SPLIT + calleeCall.getTarget();
if (!distinctCalls.contains(call)) {
distinctCalls.add(call);
calls.add(calleeCall);
}
});
return calls;
}
}
/*
* 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.utils;
/**
* @author peng-yongsheng
*/
public enum ApdexCalculator {
INSTANCE;
public int calculate(long satisfiedCount, long toleratingCount, long frustratedCount) {
return (int)(((satisfiedCount + toleratingCount / 2) * 100) / (satisfiedCount + toleratingCount + frustratedCount));
}
}
/*
* 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.utils;
/**
* @author peng-yongsheng
*/
public enum SLACalculator {
INSTANCE;
public int calculate(long errorCalls, long calls) {
return (int)(((calls - errorCalls) * 100) / calls);
}
}
......@@ -82,6 +82,8 @@ public class ComponentsDefine {
public static final OfficialComponent SERVICECOMB = new OfficialComponent(28, "ServiceComb");
public static final OfficialComponent HYSTRIX = new OfficialComponent(29, "Hystrix");
private static ComponentsDefine INSTANCE = new ComponentsDefine();
private String[] components;
......@@ -91,7 +93,7 @@ public class ComponentsDefine {
}
public ComponentsDefine() {
components = new String[29];
components = new String[30];
addComponent(TOMCAT);
addComponent(HTTPCLIENT);
addComponent(DUBBO);
......@@ -120,6 +122,7 @@ public class ComponentsDefine {
addComponent(HTTP_ASYNC_CLIENT);
addComponent(KAFKA);
addComponent(SERVICECOMB);
addComponent(HYSTRIX);
}
private void addComponent(OfficialComponent component) {
......
......@@ -10,7 +10,7 @@ type ApplicationNode implements Node {
# The number of incoming calls
callsPerSec: Long!
# Unit: millisecond
responseTimePerSec: Long!
avgResponseTime: Long!
# ref: http://www.apdex.org/
# Max value is 100
# 2 Digits after floating point in UI, need to division by 100. 100 -> 1.00
......
......@@ -106,5 +106,5 @@ type Call {
callType: String!
callsPerSec: Long!
# Unit: millisecond
responseTimePerSec: Long!
avgResponseTime: Long!
}
......@@ -21,7 +21,7 @@ type ServiceMetric {
name: String
# The unit is millisecond.
avgResponseTime: Int!
tps: Int!
callsPerSec: Int!
}
type TraceItem {
......
......@@ -16,25 +16,18 @@
*
*/
package org.apache.skywalking.apm.plugin.dubbo;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link DubboInstrumentation} presents that skywalking intercepts {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(com.alibaba.dubbo.rpc.Invoker,
* com.alibaba.dubbo.rpc.Invocation)} by using {@link DubboInterceptor}.
*
* @author zhangxin
*/
public class DubboInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.alibaba.dubbo.monitor.support.MonitorFilter";
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.plugin.feign.http.v9.define;
import net.bytebuddy.description.method.MethodDescription;
......@@ -25,19 +24,10 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link DefaultHttpClientInstrumentation} presents that skywalking intercepts {@link
* feign.Client.Default#execute(feign.Request, feign.Request.Options)} by using {@link DefaultHttpClientInterceptor}.
* If feign did't run in default mode, the instrumentation depend on the http discovery implementation.
* e.g. okhttp discovery implementation depend on okhttp-plugin.
*
* @author peng-yongsheng
*/
public class DefaultHttpClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
/**
......
......@@ -29,13 +29,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link AbstractServerImplBuilderInstrumentation} present that the GRPC plugin intercept the method
* <code>addService</code> in the {@link io.grpc.internal.AbstractServerImplBuilder} class by using the {@link
* org.apache.skywalking.apm.plugin.grpc.v1.AbstractServerImplBuilderInterceptor} class.
*
* @author zhang xin
*/
public class AbstractServerImplBuilderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "io.grpc.internal.AbstractServerImplBuilder";
......
......@@ -29,13 +29,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link AbstractStubInstrumentation} present that the GRPC plugin intercept the method <code>getChannel</code> in the
* {@link io.grpc.stub.AbstractStub} class by using the {@link org.apache.skywalking.apm.plugin.grpc.v1.AbstractStubInterceptor}
* class.
*
* @author zhang xin
*/
public class AbstractStubInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.grpc.v1.AbstractStubInterceptor";
......
......@@ -16,19 +16,11 @@
*
*/
package org.apache.skywalking.apm.plugin.httpClient.v4.define;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.plugin.httpClient.v4.HttpClientExecuteInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
/**
* {@link HttpClientInstrumentation} present that skywalking intercepts {@link HttpClientInstrumentation#enhanceClass()}
* by using {@link HttpClientExecuteInterceptor}
*
* @author zhangxin
*/
public abstract class HttpClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.httpClient.v4.HttpClientExecuteInterceptor";
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-sdk-plugin</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>5.0.0-alpha-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-hystrix-1.x-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.4.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
/*
* 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.plugin.hystrix.v1;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
/**
* {@link EnhanceRequireObjectCache} record the prefix operation name of span and {@link ContextSnapshot} object for
* tracing.
*
* @author zhang xin
*/
public class EnhanceRequireObjectCache {
private final String operationNamePrefix;
private ContextSnapshot contextSnapshot;
public EnhanceRequireObjectCache(String prefix) {
operationNamePrefix = prefix;
}
public String getOperationNamePrefix() {
return operationNamePrefix;
}
public ContextSnapshot getContextSnapshot() {
return contextSnapshot;
}
public void setContextSnapshot(ContextSnapshot contextSnapshot) {
this.contextSnapshot = contextSnapshot;
}
}
/*
* 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.plugin.hystrix.v1;
import com.netflix.hystrix.HystrixCollapser;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixObservableCollapser;
import com.netflix.hystrix.HystrixObservableCommand;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
/**
* {@link HystrixCommandConstructorInterceptor} get <code>CommandKey</code> or <code>CollapserKey</code> as the
* operation name prefix of span when the constructor that the class hierarchy <code>com.netflix.hystrix.HystrixCommand</code>
* invoked.
*
* @author zhang xin
*/
public class HystrixCommandConstructorInterceptor implements InstanceConstructorInterceptor {
public static final String OPERATION_NAME_PREFIX = "Hystrix/";
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
String commandIdentify = "";
if (HystrixCommand.class.isAssignableFrom(objInst.getClass())) {
HystrixCommand hystrixCommand = (HystrixCommand)objInst;
commandIdentify = hystrixCommand.getCommandKey().name();
} else if (HystrixCollapser.class.isAssignableFrom(objInst.getClass())) {
HystrixCollapser hystrixCollapser = (HystrixCollapser)objInst;
commandIdentify = hystrixCollapser.getCollapserKey().name();
} else if (HystrixObservableCollapser.class.isAssignableFrom(objInst.getClass())) {
HystrixObservableCollapser hystrixObservableCollapser = (HystrixObservableCollapser)objInst;
commandIdentify = hystrixObservableCollapser.getCollapserKey().name();
} else if (HystrixObservableCommand.class.isAssignableFrom(objInst.getClass())) {
HystrixObservableCommand hystrixObservableCommand = (HystrixObservableCommand)objInst;
commandIdentify = hystrixObservableCommand.getCommandKey().name();
}
objInst.setSkyWalkingDynamicField(new EnhanceRequireObjectCache(OPERATION_NAME_PREFIX + commandIdentify));
}
}
/*
* 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.plugin.hystrix.v1;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
public class HystrixCommandGetFallbackInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField();
ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot();
AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback");
activeSpan.setComponent(ComponentsDefine.HYSTRIX);
ContextManager.continued(snapshot);
}
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ContextManager.stopSpan();
return ret;
}
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
}
}
/*
* 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.plugin.hystrix.v1;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
public class HystrixCommandRunInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
// create a local span, and continued, The `execution method` running in other thread if the
// hystrix strategy is `THREAD`.
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)objInst.getSkyWalkingDynamicField();
ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot();
AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Execution");
activeSpan.setComponent(ComponentsDefine.HYSTRIX);
ContextManager.continued(snapshot);
// Because of `fall back` method running in other thread. so we need capture concurrent span for tracing.
enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
}
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ContextManager.stopSpan();
return ret;
}
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
}
}
/*
* 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.plugin.hystrix.v1;
import com.netflix.hystrix.strategy.HystrixPlugins;
import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
/**
* {@link HystrixPluginsInterceptor} wrapper the {@link HystrixCommandExecutionHook} object by using {@link
* SWExecutionHookWrapper} when the {@link HystrixPlugins#getCommandExecutionHook()} method invoked.
*
* @author zhang xin
*/
public class HystrixPluginsInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
}
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
return new SWExecutionHookWrapper((HystrixCommandExecutionHook)ret);
}
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
}
}
/*
* 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.plugin.hystrix.v1;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixInvokable;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
/**
* {@link SWExecutionHookWrapper} wrapper the HystrixCommandExecutionHook object for tracing.
*
* @author zhang xin
*/
public class SWExecutionHookWrapper extends HystrixCommandExecutionHook {
private final HystrixCommandExecutionHook actual;
public SWExecutionHookWrapper(HystrixCommandExecutionHook actual) {
this.actual = actual;
}
@Override
public <T> void onStart(HystrixInvokable<T> commandInstance) {
EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance;
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField();
enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
actual.onStart(commandInstance);
}
@Override
public <T> void onExecutionStart(HystrixInvokable<T> commandInstance) {
actual.onExecutionStart(commandInstance);
}
@Override
public <T> Exception onExecutionError(HystrixInvokable<T> commandInstance, Exception e) {
return actual.onExecutionError(commandInstance, e);
}
@Override
public <T> void onExecutionSuccess(HystrixInvokable<T> commandInstance) {
actual.onExecutionSuccess(commandInstance);
}
@Override
public <T> void onFallbackStart(HystrixInvokable<T> commandInstance) {
actual.onFallbackStart(commandInstance);
}
@Override
public <T> Exception onFallbackError(HystrixInvokable<T> commandInstance, Exception e) {
return actual.onFallbackError(commandInstance, e);
}
@Override
public <T> void onFallbackSuccess(HystrixInvokable<T> commandInstance) {
actual.onFallbackSuccess(commandInstance);
}
@Override public <T> Exception onRunError(HystrixInvokable<T> commandInstance, Exception e) {
return actual.onRunError(commandInstance, e);
}
@Override public <T> Exception onRunError(HystrixCommand<T> commandInstance, Exception e) {
return actual.onRunError(commandInstance, e);
}
@Override
public <T> Exception onError(HystrixInvokable<T> commandInstance, HystrixRuntimeException.FailureType failureType,
Exception e) {
return actual.onError(commandInstance, failureType, e);
}
@Override public <T> void onSuccess(HystrixInvokable<T> commandInstance) {
actual.onSuccess(commandInstance);
}
@Override public <T> T onEmit(HystrixInvokable<T> commandInstance, T value) {
return actual.onEmit(commandInstance, value);
}
@Override public <T> T onExecutionEmit(HystrixInvokable<T> commandInstance, T value) {
return actual.onExecutionEmit(commandInstance, value);
}
@Override public <T> T onFallbackEmit(HystrixInvokable<T> commandInstance, T value) {
return actual.onFallbackEmit(commandInstance, value);
}
@Override public <T> void onCacheHit(HystrixInvokable<T> commandInstance) {
actual.onCacheHit(commandInstance);
}
@Override public <T> void onThreadComplete(HystrixInvokable<T> commandInstance) {
actual.onThreadComplete(commandInstance);
}
@Override public <T> void onThreadStart(HystrixInvokable<T> commandInstance) {
actual.onThreadStart(commandInstance);
}
@Override
public <T> Exception onError(HystrixCommand<T> commandInstance, HystrixRuntimeException.FailureType failureType,
Exception e) {
return actual.onError(commandInstance, failureType, e);
}
@Override public <T> Exception onFallbackError(HystrixCommand<T> commandInstance, Exception e) {
return actual.onFallbackError(commandInstance, e);
}
@Override public <T> T onComplete(HystrixCommand<T> commandInstance, T response) {
return actual.onComplete(commandInstance, response);
}
@Override public <T> T onComplete(HystrixInvokable<T> commandInstance, T response) {
return actual.onComplete(commandInstance, response);
}
@Override public <T> T onFallbackSuccess(HystrixCommand<T> commandInstance, T fallbackResponse) {
return actual.onFallbackSuccess(commandInstance, fallbackResponse);
}
@Override public <T> T onFallbackSuccess(HystrixInvokable<T> commandInstance, T fallbackResponse) {
return actual.onFallbackSuccess(commandInstance, fallbackResponse);
}
@Override public <T> T onRunSuccess(HystrixCommand<T> commandInstance, T response) {
return actual.onRunSuccess(commandInstance, response);
}
@Override public <T> T onRunSuccess(HystrixInvokable<T> commandInstance, T response) {
return actual.onRunSuccess(commandInstance, response);
}
@Override public <T> void onFallbackStart(HystrixCommand<T> commandInstance) {
actual.onFallbackStart(commandInstance);
}
@Override public <T> void onRunStart(HystrixCommand<T> commandInstance) {
actual.onRunStart(commandInstance);
}
@Override public <T> void onRunStart(HystrixInvokable<T> commandInstance) {
actual.onRunStart(commandInstance);
}
@Override public <T> void onStart(HystrixCommand<T> commandInstance) {
EnhancedInstance enhancedInstance = (EnhancedInstance)commandInstance;
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache)enhancedInstance.getSkyWalkingDynamicField();
enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
actual.onStart(commandInstance);
}
@Override public <T> void onThreadComplete(HystrixCommand<T> commandInstance) {
actual.onThreadComplete(commandInstance);
}
@Override public <T> void onThreadStart(HystrixCommand<T> commandInstance) {
actual.onThreadStart(commandInstance);
}
}
/*
* 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.plugin.hystrix.v1.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
public class HystrixCommandInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandConstructorInterceptor";
public static final String ENHANCE_CLASS = "com.netflix.hystrix.HystrixCommand";
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[] {
new ConstructorInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getConstructorMatcher() {
return any();
}
@Override public String getConstructorInterceptor() {
return INTERCEPT_CLASS;
}
}
};
}
@Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("run");
}
@Override public String getMethodsInterceptor() {
return "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandRunInterceptor";
}
@Override public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("getFallback");
}
@Override public String getMethodsInterceptor() {
return "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixCommandGetFallbackInterceptor";
}
@Override public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override protected ClassMatch enhanceClass() {
return byHierarchyMatch(new String[] {ENHANCE_CLASS});
}
}
/*
* 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.plugin.hystrix.v1.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
public class HystrixPluginsInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.hystrix.v1.HystrixPluginsInterceptor";
public static final String ENHANCE_METHOD = "getCommandExecutionHook";
public static final String ENHANCE_CLASS = "com.netflix.hystrix.strategy.HystrixPlugins";
@Override
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(ENHANCE_METHOD);
}
@Override public String getMethodsInterceptor() {
return INTERCEPT_CLASS;
}
@Override public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
}
hystrix-1.x=org.apache.skywalking.apm.plugin.hystrix.v1.define.HystrixCommandInstrumentation
hystrix-1.x=org.apache.skywalking.apm.plugin.hystrix.v1.define.HystrixPluginsInstrumentation
......@@ -16,23 +16,16 @@
*
*/
package org.apache.skywalking.apm.plugin.jdbc.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.plugin.jdbc.JDBCDriverInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* JDBC plugin using {@link JDBCDriverInterceptor} to intercept the <code>connect</code> method of all driver class.
*
* @author zhangxin
*/
public abstract class AbstractDriverInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String DRIVER_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.JDBCDriverInterceptor";
......
......@@ -16,34 +16,21 @@
*
*/
package org.apache.skywalking.apm.plugin.jedis.v2.define;
import java.util.Set;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.jedis.v2.JedisClusterConstructorWithHostAndPortArgInterceptor;
import org.apache.skywalking.apm.plugin.jedis.v2.JedisClusterConstructorWithListHostAndPortArgInterceptor;
import org.apache.skywalking.apm.plugin.jedis.v2.JedisMethodInterceptor;
import org.apache.skywalking.apm.plugin.jedis.v2.RedisMethodMatch;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link JedisClusterInstrumentation} presents that skywalking intercepts all constructors and methods of {@link
* redis.clients.jedis.JedisCluster}. {@link JedisClusterConstructorWithHostAndPortArgInterceptor}
* intercepts all constructor with argument {@link redis.clients.jedis.HostAndPort} and the other constructor intercept
* by class {@link JedisClusterConstructorWithListHostAndPortArgInterceptor}. {@link JedisMethodInterceptor} intercept
* all methods of {@link redis.clients.jedis.JedisCluster}
*
* @author zhangxin
*/
public class JedisClusterInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ARGUMENT_TYPE_NAME = "redis.clients.jedis.HostAndPort";
......
......@@ -16,35 +16,21 @@
*
*/
package org.apache.skywalking.apm.plugin.jedis.v2.define;
import java.net.URI;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.plugin.jedis.v2.JedisConstructorWithShardInfoArgInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.jedis.v2.JedisConstructorWithUriArgInterceptor;
import org.apache.skywalking.apm.plugin.jedis.v2.JedisMethodInterceptor;
import org.apache.skywalking.apm.plugin.jedis.v2.RedisMethodMatch;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link JedisInstrumentation} presents that skywalking intercept all constructors and methods of {@link
* redis.clients.jedis.Jedis}. {@link JedisConstructorWithShardInfoArgInterceptor} intercepts all constructor with
* argument {@link redis.clients.jedis.HostAndPort} ,{@link JedisConstructorWithUriArgInterceptor} intercepts the
* constructors with uri argument and the other constructor intercept by class {@link
* JedisConstructorWithShardInfoArgInterceptor}. {@link JedisMethodInterceptor} intercept all methods of {@link
* redis.clients.jedis.Jedis}.
*
* @author zhangxin
*/
public class JedisInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String HOST_AND_PORT_ARG_TYPE_NAME = "redis.clients.jedis.HostAndPort";
......
......@@ -24,17 +24,10 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.kafka.v1.CallbackInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
/**
* {@link CallbackInstrumentation} defined that {@link CallbackInterceptor}
* intercept the method onCompletion in the class <code>org.apache.kafka.clients.producer.Callback</code>.
*
* @author zhangxin
*/
public class CallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "org.apache.kafka.clients.producer.Callback";
......
......@@ -24,18 +24,14 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.kafka.v1.KafkaConsumerInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link KafkaProducerInstrumentation} define that {@link KafkaConsumerInterceptor}
* intercept the method <code>send</code> in the class <code>org.apache.kafka.clients.producer.KafkaProducer</code>.
* Here is the intercept process steps.
*
*
* <pre>
* 1. Record the topic when the client invoke <code>subscribed</code> method
* 2. Create the entry span when the client invoke the method <code>pollOnce</code>.
......
......@@ -24,18 +24,14 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.kafka.v1.KafkaProducerInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link KafkaProducerInstrumentation} define that {@link KafkaProducerInterceptor}
* intercept the method <code>send</code> in the class <code>org.apache.kafka.clients.producer.KafkaProducer</code>.
* Here is the intercept process steps.
*
*
* <pre>
* 1. Record the broker address when the client create the <code>org.apache.kafka.clients.producer.KafkaProducer</code>
* instance
......
......@@ -24,19 +24,10 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.kafka.v1.ProducerRecordConstructorInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link ProducerRecordInstrumentation} define that {@link ProducerRecordConstructorInterceptor}
* intercept the constructor in the class <code>org.apache.kafka.clients.producer.ProducerRecord</code> for record the
* topic name and propagate the <code>Context</code> of trace.
*
* @author zhang xin
* @see org.apache.skywalking.apm.plugin.kafka.v1.define.KafkaProducerInstrumentation
*/
public class ProducerRecordInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v1.ProducerRecordConstructorInterceptor";
......
......@@ -16,26 +16,18 @@
*
*/
package org.apache.skywalking.apm.plugin.motan.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.plugin.motan.MotanProviderInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link MotanConsumerInstrumentation} presents that skywalking intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(com.weibo.api.motan.rpc.Request)}
* by using {@link MotanProviderInterceptor}.
*
* @author zhangxin
*/
public class MotanConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.weibo.api.motan.transport.ProviderMessageRouter";
......
......@@ -16,30 +16,20 @@
*
*/
package org.apache.skywalking.apm.plugin.motan.define;
import com.weibo.api.motan.rpc.Request;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
import org.apache.skywalking.apm.plugin.motan.MotanConsumerInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
import static net.bytebuddy.matcher.ElementMatchers.any;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link MotanProviderInstrumentation} presents that skywalking will use
* {@link MotanConsumerInterceptor} to intercept
* all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and
* {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}.
*
* @author zhangxin
*/
public class MotanProviderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
/**
......
......@@ -29,13 +29,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.PREPARED_STATEMENT_INTERCEPT_CLASS;
/**
* {@link OracleCallableInstrumentation} define that the oracle plugin intercept the <code>execute, executeQuery and
* executeUpdate</code> method in {@link oracle.jdbc.driver.OracleCallableStatement} class by
* {@link org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor}
*
* @author zhangxin
*/
public class OracleCallableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleCallableStatement";
......
......@@ -29,13 +29,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.PREPARED_STATEMENT_INTERCEPT_CLASS;
/**
* {@link OraclePrepareStatementInstrumentation} define that the oracle plugin intercept the <code>execute,
* executeQuery, executeUpdate and executeLargeUpdate</code> method in oracle.jdbc.driver.OraclePreparedStatement
* class by ${@link org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor}
*
* @author zhangxin
*/
public class OraclePrepareStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OraclePreparedStatement";
......
......@@ -29,13 +29,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.STATEMENT_INTERCEPT_CLASS;
/**
* {@link OracleStatementInstrumentation} define that the oracle plugin intercept the <code>execute, executeQuery,
* executeUpdate and executeLargeUpdate</code> method in {@link oracle.jdbc.driver.OracleStatement} class by
* {@link org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor}
*
* @author zhangxin
*/
public class OracleStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleStatement";
......
......@@ -56,6 +56,7 @@
<module>httpasyncclient-4.x-plugin</module>
<module>kafka-v1-plugin</module>
<module>servicecomb-plugin</module>
<module>hystrix-1.x-plugin</module>
</modules>
<packaging>pom</packaging>
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.plugin.jdbc.postgresql.define;
import net.bytebuddy.description.method.MethodDescription;
......@@ -25,7 +24,6 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.jdbc.postgresql.StatementExecuteMethodsInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
......@@ -33,26 +31,10 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName
import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR;
/**
* {@link AbstractJdbc2StatementInstrumentation} intercept the following methods that the class which extend
* org.postgresql.jdbc2.AbstractJdbc2Statement by {@link StatementExecuteMethodsInterceptor}.
* 1. the <code>execute</code> with non parameter
* 2. the <code>execute</code> with one parameter
* 3. the <code>executeBatch</code>
* 4. the <code>executeQuery</code> with non parameter
* 5. the <code>executeQuery</code> with one parameter
* 6. the <code>executeUpdate</code> with non parameter
* 7. the <code>executeUpdate</code> with one parameter
* 8. the <code>addBatch</code> with non parameter
* 9. the <code>addBatch</code> with one parameter
*
* @author zhangxin
*/
public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "org.postgresql.jdbc2.AbstractJdbc2Statement";
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
......
......@@ -16,27 +16,18 @@
*
*/
package org.apache.skywalking.apm.plugin.resin.v3.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
import org.apache.skywalking.apm.plugin.resin.v3.ResinV3Interceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link ResinV3Instrumentation} presents that skywalking intercepts
* {@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest,javax.servlet.ServletResponse)}
* by using {@link ResinV3Interceptor}.
*
* @author baiyang
*/
public class ResinV3Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.caucho.server.dispatch.ServletInvocation";
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.plugin.resin.v4.define;
import net.bytebuddy.description.method.MethodDescription;
......@@ -25,18 +24,10 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.resin.v4.ResinV4Interceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link ResinV4Instrumentation} presents that skywalking intercepts
* {@link com.caucho.server.dispatch.ServletInvocation#service(javax.servlet.ServletRequest,javax.servlet.ServletResponse)}
* by using {@link ResinV4Interceptor}.
*
* @author baiyang
*/
public class ResinV4Instrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.caucho.server.dispatch.ServletInvocation";
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.plugin.rocketMQ.v4.define;
import net.bytebuddy.description.method.MethodDescription;
......@@ -29,13 +28,6 @@ import org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link ConsumeMessageConcurrentlyInstrumentation} intercepts the {@link org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently#consumeMessage(java.util.List,
* org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)} method by using {@link
* org.apache.skywalking.apm.plugin.rocketMQ.v4.MessageConcurrentlyConsumeInterceptor}.
*
* @author zhang xin
*/
public class ConsumeMessageConcurrentlyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently";
private static final String CONSUMER_MESSAGE_METHOD = "consumeMessage";
......
......@@ -16,26 +16,18 @@
*
*/
package org.apache.skywalking.apm.plugin.rocketMQ.v4.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
/**
* {@link ConsumeMessageOrderlyInstrumentation} intercepts the {@link org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly#consumeMessage(java.util.List,
* org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext)} method by using {@link
* org.apache.skywalking.apm.plugin.rocketMQ.v4.MessageConcurrentlyConsumeInterceptor}.
*
* @author zhang xin
*/
public class ConsumeMessageOrderlyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly";
private static final String ENHANCE_METHOD = "consumeMessage";
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.plugin.rocketMQ.v4.define;
import net.bytebuddy.description.method.MethodDescription;
......@@ -25,22 +24,11 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.rocketMQ.v4.MessageSendInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link MQClientAPIImplInstrumentation} intercepts the {@link org.apache.rocketmq.client.impl.MQClientAPIImpl#sendMessage(String,
* String, org.apache.rocketmq.common.message.Message, org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader,
* long, org.apache.rocketmq.client.impl.CommunicationMode, org.apache.rocketmq.client.producer.SendCallback,
* org.apache.rocketmq.client.impl.producer.TopicPublishInfo, org.apache.rocketmq.client.impl.factory.MQClientInstance,
* int, org.apache.rocketmq.client.hook.SendMessageContext, org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl)}
* method by using {@link MessageSendInterceptor}.
*
* @author zhang xin
*/
public class MQClientAPIImplInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.impl.MQClientAPIImpl";
......
......@@ -16,29 +16,19 @@
*
*/
package org.apache.skywalking.apm.plugin.rocketMQ.v4.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
/**
* {@link SendCallbackInstrumentation} intercepts {@link org.apache.rocketmq.client.producer.SendCallback#onSuccess(SendResult)}
* method by using {@link org.apache.skywalking.apm.plugin.rocketMQ.v4.OnSuccessInterceptor} and also intercepts {@link
* org.apache.rocketmq.client.producer.SendCallback#onException(Throwable)} by using {@link
* org.apache.skywalking.apm.plugin.rocketMQ.v4.OnExceptionInterceptor}.
*
* @author zhang xin
*/
public class SendCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.producer.SendCallback";
......
......@@ -16,26 +16,18 @@
*
*/
package org.apache.skywalking.apm.plugin.spring.concurrent.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.spring.concurrent.FailureCallbackInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.plugin.spring.concurrent.match.FailedCallbackMatch.failedCallbackMatch;
/**
* {@link FailureCallbackInstrumentation} enhance the onFailure method that class inherited
* <code>org.springframework.util.concurrent.FailureCallback</code> by {@link FailureCallbackInterceptor}.
*
* @author zhangxin
*/
public class FailureCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String FAILURE_CALLBACK_INTERCEPTOR = "org.apache.skywalking.apm.plugin.spring.concurrent.FailureCallbackInterceptor";
......
......@@ -16,7 +16,6 @@
*
*/
package org.apache.skywalking.apm.plugin.spring.patch.define;
import net.bytebuddy.description.method.MethodDescription;
......@@ -29,13 +28,6 @@ import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
/**
* {@link AopProxyFactoryInstrumentation} indicate that spring core patch plugin intercepts the {@link
* org.springframework.aop.framework.DefaultAopProxyFactory#hasNoUserSuppliedProxyInterfaces} method by using {@link
* org.apache.skywalking.apm.plugin.spring.patch.CreateAopProxyInterceptor} class.
*
* @author zhangxin
*/
public class AopProxyFactoryInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "org.springframework.aop.framework.DefaultAopProxyFactory";
......
......@@ -16,26 +16,18 @@
*
*/
package org.apache.skywalking.apm.plugin.spring.cloud.netflix.feign.v11.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.feign.http.v9.DefaultHttpClientInterceptor;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
/**
* {@link NetflixFeignInstrumentation} presents that skywalking intercepts {@link org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient#execute(feign.Request,
* feign.Request.Options)} by using {@link DefaultHttpClientInterceptor}.
*
* @author zhangxin
*/
public class NetflixFeignInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
/**
* Enhance class.
......
......@@ -38,12 +38,17 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName
* @author wusheng
*/
public class TraceIdPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternConverter";
public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.log.log4j.v1.x.PrintTraceIdInterceptor";
public static final String ENHANCE_METHOD = "convert";
/**
* @return the target class, which needs active.
*/
@Override
protected ClassMatch enhanceClass() {
return byName("TraceIdPatternConverter");
return byName(ENHANCE_CLASS);
}
/**
......@@ -64,12 +69,12 @@ public class TraceIdPatternConverterActivation extends ClassInstanceMethodsEnhan
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("convert");
return named(ENHANCE_METHOD);
}
@Override
public String getMethodsInterceptor() {
return "PrintTraceIdInterceptor";
return INTERCEPT_CLASS;
}
@Override public boolean isOverrideArgs() {
......
......@@ -37,12 +37,17 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
* @author wusheng
*/
public class Log4j2OutputAppenderActivation extends ClassStaticMethodsEnhancePluginDefine {
public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.log.log4j.v2.x.Log4j2OutputAppender";
public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.log.log4j.v2.x.PrintTraceIdInterceptor";
public static final String ENHANCE_METHOD = "append";
/**
* @return the target class, which needs active.
*/
@Override
protected ClassMatch enhanceClass() {
return NameMatch.byName("org.apache.skywalking.apm.toolkit.log.log4j.v2.x.Log4j2OutputAppender");
return NameMatch.byName(ENHANCE_CLASS);
}
/**
......@@ -55,12 +60,12 @@ public class Log4j2OutputAppenderActivation extends ClassStaticMethodsEnhancePlu
new StaticMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("append");
return named(ENHANCE_METHOD);
}
@Override
public String getMethodsInterceptor() {
return "PrintTraceIdInterceptor";
return INTERCEPT_CLASS;
}
@Override public boolean isOverrideArgs() {
......
......@@ -39,12 +39,17 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName
* Created by wusheng on 2016/12/7.
*/
public class LogbackPatternConverterActivation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.PrintTraceIdInterceptor";
public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter";
public static final String ENHANCE_METHOD = "convert";
/**
* @return the target class, which needs active.
*/
@Override
protected ClassMatch enhanceClass() {
return byName("org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter");
return byName(ENHANCE_CLASS);
}
/**
......@@ -65,12 +70,12 @@ public class LogbackPatternConverterActivation extends ClassInstanceMethodsEnhan
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("convert");
return named(ENHANCE_METHOD);
}
@Override
public String getMethodsInterceptor() {
return "PrintTraceIdInterceptor";
return INTERCEPT_CLASS;
}
@Override public boolean isOverrideArgs() {
......
......@@ -34,6 +34,10 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
*/
public class MDCConverterActivation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String INTERCEPT_CLASS = "org.apache.skywalking.apm.toolkit.activation.log.logback.v1.x.mdc.PrintMDCTraceIdInterceptor";
public static final String ENHANCE_CLASS = "org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.LogbackMDCPatternConverter";
public static final String ENHANCE_METHOD = "convertTID";
@Override
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return null;
......@@ -45,12 +49,12 @@ public class MDCConverterActivation extends ClassInstanceMethodsEnhancePluginDef
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("convertTID");
return named(ENHANCE_METHOD);
}
@Override
public String getMethodsInterceptor() {
return "PrintMDCTraceIdInterceptor";
return INTERCEPT_CLASS;
}
@Override public boolean isOverrideArgs() {
......@@ -62,6 +66,6 @@ public class MDCConverterActivation extends ClassInstanceMethodsEnhancePluginDef
@Override
protected ClassMatch enhanceClass() {
return NameMatch.byName("org.apache.skywalking.apm.toolkit.log.logback.v1.x.mdc.LogbackMDCPatternConverter");
return NameMatch.byName(ENHANCE_CLASS);
}
}
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册