Merge pull request #4 from apache/master

Merge from origin
This commit is contained in:
Gao Hongtao 2018-02-28 15:38:26 +08:00 committed by GitHub
commit e729290f0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
80 changed files with 2086 additions and 434 deletions

View File

@ -4,7 +4,7 @@ Apache SkyWalking | [中文](README_ZH.md)
<img src="https://skywalkingtest.github.io/page-resources/3.0/skywalking.png" alt="Sky Walking logo" height="90px" align="right" />
**SkyWalking**: APM (application performance monitor) tool for distributed systems, especially designed for
microservices, cloud native and container-based (Docker, K8s, Mesos) architectures.
microservices, cloud native and container-based (Docker, Kubernetes, Mesos) architectures.
Underlying technology is a distributed tracing system.
[![GitHub stars](https://img.shields.io/github/stars/apache/incubator-skywalking.svg?style=for-the-badge&label=Stars&logo=github)](https://github.com/apache/incubator-skywalking)

View File

@ -3,7 +3,7 @@ Apache SkyWalking | [English](README.md)
<img src="https://skywalkingtest.github.io/page-resources/3.0/skywalking.png" alt="Sky Walking logo" height="90px" align="right" />
**SkyWalking**: 针对分布式系统的APM应用性能监控系统特别针对微服务、cloud native和容器化(Docker, K8s, Mesos)架构,
**SkyWalking**: 针对分布式系统的APM应用性能监控系统特别针对微服务、cloud native和容器化(Docker, Kubernetes, Mesos)架构,
其核心是个分布式追踪系统。
[![GitHub stars](https://img.shields.io/github/stars/apache/incubator-skywalking.svg?style=for-the-badge&label=Stars&logo=github)](https://github.com/apache/incubator-skywalking)

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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()) {

View File

@ -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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
}

View File

@ -28,6 +28,84 @@ import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
* @author peng-yongsheng
*/
public interface IApplicationMetricUIDAO extends DAO {
List<ApplicationTPS> getTopNApplicationThroughput(Step step, long start, long end, long betweenSecond, int topN,
List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int 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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -32,11 +32,15 @@ public interface IInstanceUIDAO extends DAO {
Long instanceLastHeartBeatTime(long applicationInstanceId);
List<Application> getApplications(long startTime, long endTime, int... applicationIds);
List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket, int... applicationIds);
Instance getInstance(int instanceId);
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);
}

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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";
}

View File

@ -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;
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 Float getSla() {
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;
}
}

View File

@ -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 long getAvgResponseTime() {
return avgResponseTime;
}
public void setResponseTimes(long responseTimes) {
this.responseTimes = responseTimes;
}
public long getResponseTimePerSec() {
return responseTimePerSec;
}
public void setResponseTimePerSec(long responseTimePerSec) {
this.responseTimePerSec = responseTimePerSec;
public void setAvgResponseTime(long avgResponseTime) {
this.avgResponseTime = avgResponseTime;
}
}

View File

@ -24,7 +24,7 @@ package org.apache.skywalking.apm.collector.storage.ui.overview;
public class ApplicationTPS {
private int applicationId;
private String applicationCode;
private int tps;
private int callsPerSec;
public int getApplicationId() {
return applicationId;
@ -42,11 +42,11 @@ public class ApplicationTPS {
this.applicationCode = applicationCode;
}
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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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());

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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());
}
}

View File

@ -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;
@ -54,9 +55,8 @@ public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetri
private static final String AVG_TPS = "avg_tps";
@Override
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long start, long end, long betweenSecond,
int topN,
MetricSource metricSource) {
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int betweenSecond, int topN, MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
@ -64,7 +64,7 @@ public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetri
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.rangeQuery(ApplicationMetricTable.COLUMN_TIME_BUCKET).gte(start).lte(end));
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);
@ -88,17 +88,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.setCallsPerSec((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;
}
}

View File

@ -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));
return buildMetrics(searchRequestBuilder);
}
searchRequestBuilder.addAggregation(aggregationBuilder);
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);
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));
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();
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();
Terms targetApplicationIdTerms = sourceApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
for (Terms.Bucket targetApplicationIdBucket : targetApplicationIdTerms.getBuckets()) {
int targetApplicationId = targetApplicationIdBucket.getKeyAsNumber().intValue();
Terms behindApplicationIdTerms = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID);
for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) {
int behindApplicationId = behindApplicationIdBucket.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);
Sum calls = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS);
Sum responseTimes = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_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);
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;
}
}

View File

@ -97,14 +97,14 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO {
return heartBeatTime;
}
@Override public List<Application> getApplications(long startTime, long endTime, int... applicationIds) {
logger.debug("application list get, start time: {}, end time: {}", startTime, endTime);
@Override public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket, int... applicationIds) {
logger.debug("application list get, start time: {}, end time: {}", startSecondTimeBucket, endSecondTimeBucket);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startTime));
boolQueryBuilder.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startSecondTimeBucket));
boolQueryBuilder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE));
if (applicationIds.length > 0) {
boolQueryBuilder.must().add(QueryBuilders.termsQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationIds));
@ -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) {

View File

@ -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);

View File

@ -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();

View File

@ -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);
});
}

View File

@ -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()));
}
}

View File

@ -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());

View File

@ -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);

View File

@ -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]);

View File

@ -40,8 +40,13 @@ public class ApplicationMetricH2UIDAO extends H2DAO implements IApplicationMetri
}
@Override
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long start, long end, long betweenSecond,
int topN, MetricSource metricSource) {
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int betweenSecond, int topN, MetricSource metricSource) {
return null;
}
@Override public List<ApplicationMetric> getApplications(Step step, long startTimeBucket,
long endTimeBucket, MetricSource metricSource) {
return null;
}
}

View File

@ -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;
}
}

View File

@ -88,12 +88,12 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO {
}
@Override
public List<Application> getApplications(long startTime, long endTime, int... applicationIds) {
public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket, int... applicationIds) {
H2Client client = getClient();
List<Application> applications = new LinkedList<>();
String sql = SqlBuilder.buildSql(GET_APPLICATIONS_SQL, InstanceTable.COLUMN_INSTANCE_ID,
InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_APPLICATION_ID);
Object[] params = new Object[] {startTime};
Object[] params = new Object[] {startSecondTimeBucket};
try (ResultSet rs = client.executeQuery(sql, params)) {
while (rs.next()) {
Integer applicationId = rs.getInt(InstanceTable.COLUMN_APPLICATION_ID);
@ -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;
}
}

View File

@ -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;
}

View File

@ -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()) {

View File

@ -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()));
}
}

View File

@ -69,10 +69,10 @@ public class ApplicationQuery implements Query {
}
public List<Application> getAllApplication(Duration duration) throws ParseException {
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
long startSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getApplicationService().getApplications(start, end);
return getApplicationService().getApplications(startSecondTimeBucket, endSecondTimeBucket);
}
public Topology getApplicationTopology(int applicationId, Duration duration) throws ParseException {

View File

@ -89,18 +89,21 @@ 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 {
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
long startSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
ClusterBrief clusterBrief = new ClusterBrief();
clusterBrief.setNumOfApplication(getApplicationService().getApplications(start, end).size());
clusterBrief.setNumOfApplication(getApplicationService().getApplications(startSecondTimeBucket, endSecondTimeBucket).size());
clusterBrief.setNumOfDatabase(getNetworkAddressService().getNumOfDatabase());
clusterBrief.setNumOfCache(getNetworkAddressService().getNumOfCache());
clusterBrief.setNumOfMQ(getNetworkAddressService().getNumOfMQ());
@ -126,17 +129,20 @@ 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());
return getServiceNameService().getSlowService(duration.getStep(), start, end, topN);
long startSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long endSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getServiceNameService().getSlowService(duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket, topN);
}
public List<ApplicationTPS> getTopNApplicationThroughput(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());
return getApplicationService().getTopNApplicationThroughput(duration.getStep(), start, end, topN);
return getApplicationService().getTopNApplicationThroughput(duration.getStep(), startTimeBucket, endTimeBucket, topN);
}
}

View File

@ -24,6 +24,7 @@ import org.apache.skywalking.apm.collector.cache.CacheModule;
import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService;
import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO;
@ -37,6 +38,7 @@ import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalApp;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalAppBrief;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.ui.utils.DurationUtils;
/**
* @author peng-yongsheng
@ -59,8 +61,15 @@ public class ApplicationService {
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
}
public List<Application> getApplications(long startTime, long endTime, int... applicationIds) {
List<Application> applications = instanceDAO.getApplications(startTime, endTime, applicationIds);
public List<Application> getApplications(long startSecondTimeBucket, long endSecondTimeBucket,
int... applicationIds) {
List<Application> applications = instanceDAO.getApplications(startSecondTimeBucket, endSecondTimeBucket, applicationIds);
applications.forEach(application -> {
if (application.getId() == Const.NONE_APPLICATION_ID) {
applications.remove(application);
}
});
applications.forEach(application -> {
String applicationCode = applicationCacheService.getApplicationById(application.getId()).getApplicationCode();
@ -75,15 +84,15 @@ public class ApplicationService {
slowServices.forEach(slowService -> {
slowService.setName(serviceNameCacheService.get(slowService.getId()).getServiceName());
//TODO
slowService.setTps(1);
slowService.setCallsPerSec(1);
});
return slowServices;
}
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long start, long end,
public List<ApplicationTPS> getTopNApplicationThroughput(Step step, long startTimeBucket, long endTimeBucket,
int topN) throws ParseException {
//TODO
List<ApplicationTPS> applicationThroughput = applicationMetricUIDAO.getTopNApplicationThroughput(step, start, end, 1000, topN, MetricSource.Callee);
int secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTimeBucket, endTimeBucket);
List<ApplicationTPS> applicationThroughput = applicationMetricUIDAO.getTopNApplicationThroughput(step, startTimeBucket, endTimeBucket, secondsBetween, topN, MetricSource.Callee);
applicationThroughput.forEach(applicationTPS -> {
String applicationCode = applicationCacheService.getApplicationById(applicationTPS.getApplicationId()).getApplicationCode();
applicationTPS.setApplicationCode(applicationCode);

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -0,0 +1,58 @@
/*
* 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();
}
}

View File

@ -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;
}

View File

@ -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);
Set<Integer> nodeIds = new HashSet<>();
calls.forEach(call -> {
String sourceName = applicationCacheService.getApplicationById(call.getSource()).getApplicationCode();
String targetName = applicationCacheService.getApplicationById(call.getTarget()).getApplicationCode();
call.setSourceName(sourceName);
call.setTargetName(targetName);
nodeIds.add(call.getSource());
nodeIds.add(call.getTarget());
});
calleeReferenceMetric = calleeReferenceMetricFilter(calleeReferenceMetric);
List<Node> nodes = new LinkedList<>();
nodeIds.forEach(nodeId -> {
Application application = applicationCacheService.getApplicationById(nodeId);
if (BooleanUtils.valueToBoolean(application.getAddressId())) {
ConjecturalNode conjecturalNode = new ConjecturalNode();
conjecturalNode.setId(nodeId);
conjecturalNode.setName(application.getApplicationCode());
conjecturalNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
nodes.add(conjecturalNode);
} 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));
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));
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);
}
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);
});
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);
}
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);
});
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(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 {
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;
}
}

View File

@ -0,0 +1,30 @@
/*
* 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));
}
}

View File

@ -64,36 +64,36 @@ public enum DurationUtils {
return secondTimeBucket;
}
public long secondsBetween(Step step, long start, long end) throws ParseException {
public int secondsBetween(Step step, long startTimeBucket, long endTimeBucket) throws ParseException {
Date startDate = null;
Date endDate = null;
switch (step) {
case MONTH:
startDate = new SimpleDateFormat("yyyyMM").parse(String.valueOf(start));
endDate = new SimpleDateFormat("yyyyMM").parse(String.valueOf(end));
startDate = new SimpleDateFormat("yyyyMM").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMM").parse(String.valueOf(endTimeBucket));
break;
case DAY:
startDate = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(start));
endDate = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(end));
startDate = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(endTimeBucket));
break;
case HOUR:
startDate = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(start));
endDate = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(end));
startDate = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(endTimeBucket));
break;
case MINUTE:
startDate = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(start));
endDate = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(end));
startDate = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(endTimeBucket));
break;
case SECOND:
startDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(start));
endDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(end));
startDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(startTimeBucket));
endDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(endTimeBucket));
break;
}
return Seconds.secondsBetween(new DateTime(startDate), new DateTime(endDate)).getSeconds();
}
public long secondsBetween(Step step, DateTime dateTime) throws ParseException {
public int secondsBetween(Step step, DateTime dateTime) throws ParseException {
switch (step) {
case MONTH:
return dateTime.dayOfMonth().getMaximumValue() * 24 * 60 * 60;

View File

@ -0,0 +1,30 @@
/*
* 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);
}
}

View File

@ -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

View File

@ -106,5 +106,5 @@ type Call {
callType: String!
callsPerSec: Long!
# Unit: millisecond
responseTimePerSec: Long!
avgResponseTime: Long!
}

View File

@ -30,7 +30,7 @@ type ConjecturalApp {
type ApplicationTPS {
applicationId: Int!
applicationCode: String
tps: Int!
callsPerSec: Int!
}
extend type Query {

View File

@ -21,7 +21,7 @@ type ServiceMetric {
name: String
# The unit is millisecond.
avgResponseTime: Int!
tps: Int!
callsPerSec: Int!
}
type TraceItem {

View File

@ -49,6 +49,7 @@
<module>mysql-5.x-plugin</module>
<module>h2-1.x-plugin</module>
<module>postgresql-8.x-plugin</module>
<module>rocketMQ-3.x-plugin</module>
<module>rocketMQ-4.x-plugin</module>
<module>elastic-job-2.x-plugin</module>
<module>mongodb-2.x-plugin</module>

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<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-rocketmq-3.x-plugin</artifactId>
<name>rocketMQ-3.x-plugin</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba.rocketmq</groupId>
<artifactId>rocketmq-client</artifactId>
<version>3.6.2.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
<plugin>
<!-- 源码插件 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<!-- 发布时自动将源码同时发布的配置 -->
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,78 @@
/*
* 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.rocketMQ.v3;
import java.lang.reflect.Method;
import java.util.List;
import com.alibaba.rocketmq.common.message.MessageExt;
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
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;
/**
* {@link AbstractMessageConsumeInterceptor} create entry span when the <code>consumeMessage</code> in the {@link
* com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently} and {@link
* com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly} class.
*
* @author carlvine500
*/
public abstract class AbstractMessageConsumeInterceptor implements InstanceMethodsAroundInterceptor {
public static final String CONSUMER_OPERATION_NAME_PREFIX = "RocketMQ/";
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
List<MessageExt> msgs = (List<MessageExt>)allArguments[0];
ContextCarrier contextCarrier = getContextCarrierFromMessage(msgs.get(0));
AbstractSpan span = ContextManager.createEntrySpan(CONSUMER_OPERATION_NAME_PREFIX + msgs.get(0).getTopic() + "/Consumer", contextCarrier);
span.setComponent(ComponentsDefine.ROCKET_MQ);
span.setLayer(SpanLayer.MQ);
for (int i = 1; i < msgs.size(); i++) {
ContextManager.extract(getContextCarrierFromMessage(msgs.get(i)));
}
}
@Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
ContextManager.activeSpan().errorOccurred().log(t);
}
private ContextCarrier getContextCarrierFromMessage(MessageExt message) {
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
next.setHeadValue(message.getUserProperty(next.getHeadKey()));
}
return contextCarrier;
}
}

View File

@ -0,0 +1,50 @@
/*
* 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.rocketMQ.v3;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
/**
* {@link MessageConcurrentlyConsumeInterceptor} set the process status after the {@link
* com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently#consumeMessage(java.util.List,
* com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)} method execute.
*
* @author carlvine500
*/
public class MessageConcurrentlyConsumeInterceptor extends AbstractMessageConsumeInterceptor {
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ConsumeConcurrentlyStatus status = (ConsumeConcurrentlyStatus)ret;
if (status == ConsumeConcurrentlyStatus.RECONSUME_LATER) {
AbstractSpan activeSpan = ContextManager.activeSpan();
activeSpan.errorOccurred();
Tags.STATUS_CODE.set(activeSpan, status.name());
}
ContextManager.stopSpan();
return ret;
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.rocketMQ.v3;
import java.lang.reflect.Method;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
/**
* {@link MessageOrderlyConsumeInterceptor} set the process status after the {@link
* com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly#consumeMessage(java.util.List,
* com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyContext)} method execute.
*
* @author carlvine500
*/
public class MessageOrderlyConsumeInterceptor extends AbstractMessageConsumeInterceptor {
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ConsumeOrderlyStatus status = (ConsumeOrderlyStatus)ret;
if (status == ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT) {
AbstractSpan activeSpan = ContextManager.activeSpan();
activeSpan.errorOccurred();
Tags.STATUS_CODE.set(activeSpan, status.name());
}
ContextManager.stopSpan();
return ret;
}
}

View File

@ -0,0 +1,100 @@
/*
* 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.rocketMQ.v3;
import com.alibaba.rocketmq.common.message.Message;
import com.alibaba.rocketmq.common.protocol.header.SendMessageRequestHeader;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
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;
import org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo;
import org.apache.skywalking.apm.util.StringUtil;
import static com.alibaba.rocketmq.common.message.MessageDecoder.NAME_VALUE_SEPARATOR;
import static com.alibaba.rocketmq.common.message.MessageDecoder.PROPERTY_SEPARATOR;
/**
* {@link MessageSendInterceptor} create exit span when the method {@link com.alibaba.rocketmq.client.impl.MQClientAPIImpl#sendMessage(String,
* String, Message, com.alibaba.rocketmq.common.protocol.header.SendMessageRequestHeader, long,
* com.alibaba.rocketmq.client.impl.CommunicationMode, com.alibaba.rocketmq.client.producer.SendCallback,
* com.alibaba.rocketmq.client.impl.producer.TopicPublishInfo, com.alibaba.rocketmq.client.impl.factory.MQClientInstance,
* int, com.alibaba.rocketmq.client.hook.SendMessageContext, com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl)}
* execute.
*
* @author carlvine500
*/
public class MessageSendInterceptor implements InstanceMethodsAroundInterceptor {
private static final String ASYNC_SEND_OPERATION_NAME_PREFIX = "RocketMQ/";
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
Message message = (Message)allArguments[2];
ContextCarrier contextCarrier = new ContextCarrier();
String namingServiceAddress = String.valueOf(objInst.getSkyWalkingDynamicField());
AbstractSpan span = ContextManager.createExitSpan(buildOperationName(message.getTopic()), contextCarrier, namingServiceAddress);
span.setComponent(ComponentsDefine.ROCKET_MQ);
Tags.MQ_BROKER.set(span, (String)allArguments[0]);
Tags.MQ_TOPIC.set(span, message.getTopic());
SpanLayer.asMQ(span);
SendMessageRequestHeader requestHeader = (SendMessageRequestHeader)allArguments[3];
StringBuilder properties = new StringBuilder(requestHeader.getProperties());
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
if (!StringUtil.isEmpty(next.getHeadValue())) {
properties.append(next.getHeadKey());
properties.append(NAME_VALUE_SEPARATOR);
properties.append(next.getHeadValue());
properties.append(PROPERTY_SEPARATOR);
}
}
requestHeader.setProperties(properties.toString());
if (allArguments[6] != null) {
((EnhancedInstance)allArguments[6]).setSkyWalkingDynamicField(new SendCallBackEnhanceInfo(message.getTopic(), 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);
}
private String buildOperationName(String topicName) {
return ASYNC_SEND_OPERATION_NAME_PREFIX + topicName + "/Producer";
}
}

View File

@ -0,0 +1,61 @@
/*
* 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.rocketMQ.v3;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
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;
import org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo;
/**
* {@link OnExceptionInterceptor} create local span when the method {@link com.alibaba.rocketmq.client.producer.SendCallback#onException(Throwable)}
* execute.
*
* @author carlvine500
*/
public class OnExceptionInterceptor implements InstanceMethodsAroundInterceptor {
private static final String CALLBACK_OPERATION_NAME_PREFIX = "RocketMQ/";
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo)objInst.getSkyWalkingDynamicField();
AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
activeSpan.setComponent(ComponentsDefine.ROCKET_MQ);
activeSpan.errorOccurred().log((Throwable)allArguments[0]);
ContextManager.continued(enhanceInfo.getContextSnapshot());
}
@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().log(t);
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.rocketMQ.v3;
import com.alibaba.rocketmq.client.producer.SendResult;
import com.alibaba.rocketmq.client.producer.SendStatus;
import java.lang.reflect.Method;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
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;
import org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo;
/**
* {@link OnSuccessInterceptor} create local span when the method {@link com.alibaba.rocketmq.client.producer.SendCallback#onSuccess(SendResult)}
* execute.
*
* @author carlvine500
*/
public class OnSuccessInterceptor implements InstanceMethodsAroundInterceptor {
public static final String CALLBACK_OPERATION_NAME_PREFIX = "RocketMQ/";
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo)objInst.getSkyWalkingDynamicField();
AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
activeSpan.setComponent(ComponentsDefine.ROCKET_MQ);
SendStatus sendStatus = ((SendResult)allArguments[0]).getSendStatus();
if (sendStatus != SendStatus.SEND_OK) {
activeSpan.errorOccurred();
Tags.STATUS_CODE.set(activeSpan, sendStatus.name());
}
ContextManager.continued(enhanceInfo.getContextSnapshot());
}
@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);
}
}

View File

@ -0,0 +1,43 @@
/*
* 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.rocketMQ.v3;
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;
public class UpdateNameServerInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
objInst.setSkyWalkingDynamicField(allArguments[0]);
}
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
return ret;
}
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.rocketMQ.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 static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
/**
* {@link ConsumeMessageConcurrentlyInstrumentation} intercepts the {@link com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently#consumeMessage(java.util.List,
* com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)} method by using {@link
* org.apache.skywalking.apm.plugin.rocketMQ.v3.MessageConcurrentlyConsumeInterceptor}.
*
* @author carlvine500
*/
public class ConsumeMessageConcurrentlyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently";
private static final String CONSUMER_MESSAGE_METHOD = "consumeMessage";
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.rocketMQ.v3.MessageConcurrentlyConsumeInterceptor";
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(CONSUMER_MESSAGE_METHOD);
}
@Override public String getMethodsInterceptor() {
return INTERCEPTOR_CLASS;
}
@Override public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override protected ClassMatch enhanceClass() {
return byHierarchyMatch(new String[] {ENHANCE_CLASS});
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.rocketMQ.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 static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch;
/**
* {@link ConsumeMessageOrderlyInstrumentation} intercepts the {@link com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly#consumeMessage(java.util.List,
* com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyContext)} method by using {@link
* org.apache.skywalking.apm.plugin.rocketMQ.v3.MessageConcurrentlyConsumeInterceptor}.
*
* @author carlvine500
*/
public class ConsumeMessageOrderlyInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly";
private static final String ENHANCE_METHOD = "consumeMessage";
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.rocketMQ.v3.MessageOrderlyConsumeInterceptor";
@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 INTERCEPTOR_CLASS;
}
@Override public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override protected ClassMatch enhanceClass() {
return byHierarchyMatch(new String[] {ENHANCE_CLASS});
}
}

View File

@ -0,0 +1,89 @@
/*
* 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.rocketMQ.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 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 MQClientAPIImplInstrumentation} intercepts the {@link com.alibaba.rocketmq.client.impl.MQClientAPIImpl#sendMessage(String,
* String, com.alibaba.rocketmq.common.message.Message, com.alibaba.rocketmq.common.protocol.header.SendMessageRequestHeader,
* long, com.alibaba.rocketmq.client.impl.CommunicationMode, com.alibaba.rocketmq.client.producer.SendCallback,
* com.alibaba.rocketmq.client.impl.producer.TopicPublishInfo, com.alibaba.rocketmq.client.impl.factory.MQClientInstance,
* int, com.alibaba.rocketmq.client.hook.SendMessageContext, com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl)}
* method by using {@link org.apache.skywalking.apm.plugin.rocketMQ.v3.MessageSendInterceptor}.
*
* @author carlvine500
*/
public class MQClientAPIImplInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.alibaba.rocketmq.client.impl.MQClientAPIImpl";
private static final String SEND_MESSAGE_METHOD_NAME = "sendMessage";
private static final String ASYNC_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.rocketMQ.v3.MessageSendInterceptor";
private static final String UPDATE_NAME_SERVER_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.rocketMQ.v3.UpdateNameServerInterceptor";
private static final String UPDATE_NAME_SERVER_METHOD_NAME = "updateNameServerAddressList";
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(SEND_MESSAGE_METHOD_NAME).and(takesArgumentWithType(6, "com.alibaba.rocketmq.client.producer.SendCallback"));
}
@Override public String getMethodsInterceptor() {
return ASYNC_METHOD_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(UPDATE_NAME_SERVER_METHOD_NAME);
}
@Override public String getMethodsInterceptor() {
return UPDATE_NAME_SERVER_INTERCEPT_CLASS;
}
@Override public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
}

View File

@ -0,0 +1,44 @@
/*
* 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.rocketMQ.v3.define;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
/**
* {@link SendCallBackEnhanceInfo} saves the topic Id and {@link ContextSnapshot} instance for trace.
*
* @author carlvine500
*/
public class SendCallBackEnhanceInfo {
private String topicId;
private ContextSnapshot contextSnapshot;
public SendCallBackEnhanceInfo(String topicId, ContextSnapshot contextSnapshot) {
this.topicId = topicId;
this.contextSnapshot = contextSnapshot;
}
public String getTopicId() {
return topicId;
}
public ContextSnapshot getContextSnapshot() {
return contextSnapshot;
}
}

View File

@ -0,0 +1,86 @@
/*
* 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.rocketMQ.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 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 com.alibaba.rocketmq.client.producer.SendCallback#onSuccess(com.alibaba.rocketmq.client.producer.SendResult sendResult)}
* method by using {@link org.apache.skywalking.apm.plugin.rocketMQ.v3.OnSuccessInterceptor} and also intercepts {@link
* com.alibaba.rocketmq.client.producer.SendCallback#onException(Throwable)} by using {@link
* org.apache.skywalking.apm.plugin.rocketMQ.v3.OnExceptionInterceptor}.
*
* @author carlvine500
*/
public class SendCallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.alibaba.rocketmq.client.producer.SendCallback";
private static final String ON_SUCCESS_ENHANCE_METHOD = "onSuccess";
private static final String ON_SUCCESS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.rocketMQ.v3.OnSuccessInterceptor";
private static final String ON_EXCEPTION_METHOD = "onException";
private static final String ON_EXCEPTION_INTERCEPTOR = "org.apache.skywalking.apm.plugin.rocketMQ.v3.OnExceptionInterceptor";
@Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[] {
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(ON_SUCCESS_ENHANCE_METHOD).and(takesArgumentWithType(0, "com.alibaba.rocketmq.client.producer.SendResult"));
}
@Override public String getMethodsInterceptor() {
return ON_SUCCESS_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
return false;
}
},
new InstanceMethodsInterceptPoint() {
@Override public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(ON_EXCEPTION_METHOD).and(takesArgumentWithType(0, "java.lang.Throwable"));
}
@Override public String getMethodsInterceptor() {
return ON_EXCEPTION_INTERCEPTOR;
}
@Override public boolean isOverrideArgs() {
return false;
}
}
};
}
@Override protected ClassMatch enhanceClass() {
return byHierarchyMatch(new String[] {ENHANCE_CLASS});
}
}

View File

@ -0,0 +1,4 @@
rocketMQ-3.x=org.apache.skywalking.apm.plugin.rocketMQ.v3.define.ConsumeMessageConcurrentlyInstrumentation
rocketMQ-3.x=org.apache.skywalking.apm.plugin.rocketMQ.v3.define.ConsumeMessageOrderlyInstrumentation
rocketMQ-3.x=org.apache.skywalking.apm.plugin.rocketMQ.v3.define.MQClientAPIImplInstrumentation
rocketMQ-3.x=org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallbackInstrumentation

View File

@ -0,0 +1,136 @@
/*
* 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.rocketMQ.v3;
import java.util.List;
import com.alibaba.rocketmq.client.impl.CommunicationMode;
import com.alibaba.rocketmq.common.message.Message;
import com.alibaba.rocketmq.common.protocol.header.SendMessageRequestHeader;
import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.agent.test.tools.SpanAssert;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
public class MessageSendInterceptorTest {
private MessageSendInterceptor messageSendInterceptor;
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
private Object[] arguments;
private Object[] argumentsWithoutCallback;
@Mock
private Message message;
@Mock
private SendMessageRequestHeader messageRequestHeader;
@Mock
private EnhancedInstance callBack;
private EnhancedInstance enhancedInstance;
@Before
public void setUp() {
messageSendInterceptor = new MessageSendInterceptor();
enhancedInstance = new EnhancedInstance() {
@Override public Object getSkyWalkingDynamicField() {
return "127.0.0.1:6543";
}
@Override public void setSkyWalkingDynamicField(Object value) {
}
};
arguments = new Object[] {"127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, callBack};
argumentsWithoutCallback = new Object[] {"127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, null};
when(messageRequestHeader.getProperties()).thenReturn("");
when(message.getTags()).thenReturn("TagA");
}
@Test
public void testSendMessage() throws Throwable {
messageSendInterceptor.beforeMethod(enhancedInstance, null, arguments, null, null);
messageSendInterceptor.afterMethod(enhancedInstance, null, arguments, null, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertThat(spans.size(), is(1));
AbstractTracingSpan mqSpan = spans.get(0);
SpanAssert.assertLayer(mqSpan, SpanLayer.MQ);
SpanAssert.assertComponent(mqSpan, ComponentsDefine.ROCKET_MQ);
SpanAssert.assertTag(mqSpan, 0, "127.0.0.1");
verify(messageRequestHeader, times(1)).setProperties(anyString());
verify(callBack, times(1)).setSkyWalkingDynamicField(Matchers.any());
}
@Test
public void testSendMessageWithoutCallBack() throws Throwable {
messageSendInterceptor.beforeMethod(enhancedInstance, null, argumentsWithoutCallback, null, null);
messageSendInterceptor.afterMethod(enhancedInstance, null, argumentsWithoutCallback, null, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertThat(spans.size(), is(1));
AbstractTracingSpan mqSpan = spans.get(0);
SpanAssert.assertLayer(mqSpan, SpanLayer.MQ);
SpanAssert.assertComponent(mqSpan, ComponentsDefine.ROCKET_MQ);
SpanAssert.assertTag(mqSpan, 0, "127.0.0.1");
verify(messageRequestHeader, times(1)).setProperties(anyString());
}
}

View File

@ -0,0 +1,88 @@
/*
* 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.rocketMQ.v3;
import java.util.List;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
import org.apache.skywalking.apm.agent.test.helper.SpanHelper;
import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.agent.test.tools.SpanAssert;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
public class OnExceptionInterceptorTest {
private OnExceptionInterceptor exceptionInterceptor;
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Mock
private ContextSnapshot contextSnapshot;
private SendCallBackEnhanceInfo enhanceInfo;
@Mock
private EnhancedInstance enhancedInstance;
@Before
public void setUp() {
exceptionInterceptor = new OnExceptionInterceptor();
enhanceInfo = new SendCallBackEnhanceInfo("test", contextSnapshot);
when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo);
}
@Test
public void testOnException() throws Throwable {
exceptionInterceptor.beforeMethod(enhancedInstance, null, new Object[] {new RuntimeException()}, null, null);
exceptionInterceptor.afterMethod(enhancedInstance, null, new Object[] {new RuntimeException()}, null, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertThat(spans.size(), is(1));
AbstractTracingSpan exceptionSpan = spans.get(0);
SpanAssert.assertException(SpanHelper.getLogs(exceptionSpan).get(0), RuntimeException.class);
SpanAssert.assertOccurException(exceptionSpan, true);
}
}

View File

@ -0,0 +1,114 @@
/*
* 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.rocketMQ.v3;
import java.util.List;
import com.alibaba.rocketmq.client.producer.SendResult;
import com.alibaba.rocketmq.client.producer.SendStatus;
import org.apache.skywalking.apm.agent.core.context.ContextSnapshot;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
import org.apache.skywalking.apm.agent.test.tools.SpanAssert;
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
public class OnSuccessInterceptorTest {
private OnSuccessInterceptor successInterceptor;
@SegmentStoragePoint
private SegmentStorage segmentStorage;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Mock
private ContextSnapshot contextSnapshot;
@Mock
private SendResult sendResult;
private SendCallBackEnhanceInfo enhanceInfo;
@Mock
private EnhancedInstance enhancedInstance;
@Before
public void setUp() {
successInterceptor = new OnSuccessInterceptor();
enhanceInfo = new SendCallBackEnhanceInfo("test", contextSnapshot);
when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo);
when(sendResult.getSendStatus()).thenReturn(SendStatus.SEND_OK);
}
@Test
public void testOnSuccess() throws Throwable {
successInterceptor.beforeMethod(enhancedInstance, null, new Object[] {sendResult}, null, null);
successInterceptor.afterMethod(enhancedInstance, null, new Object[] {sendResult}, null, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertThat(spans.size(), is(1));
AbstractTracingSpan successSpan = spans.get(0);
SpanAssert.assertComponent(successSpan, ComponentsDefine.ROCKET_MQ);
}
@Test
public void testOnSuccessWithErrorStatus() throws Throwable {
when(sendResult.getSendStatus()).thenReturn(SendStatus.FLUSH_SLAVE_TIMEOUT);
successInterceptor.beforeMethod(enhancedInstance, null, new Object[] {sendResult}, null, null);
successInterceptor.afterMethod(enhancedInstance, null, new Object[] {sendResult}, null, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertThat(spans.size(), is(1));
AbstractTracingSpan successSpan = spans.get(0);
SpanAssert.assertComponent(successSpan, ComponentsDefine.ROCKET_MQ);
SpanAssert.assertOccurException(successSpan, true);
}
}