Skip to content

Commit

Permalink
Merge pull request #836 from sunnights/dev
Browse files Browse the repository at this point in the history
support custom slow threshold & trace tag
  • Loading branch information
rayzhang0603 authored Jul 4, 2019
2 parents 38dd567 + 95ed157 commit a56ac46
Show file tree
Hide file tree
Showing 62 changed files with 1,306 additions and 989 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## [1.1.6](/~https://github.com/weibocom/motan/tree/1.1.6) (2019-07-04)
[Full Changelog](/~https://github.com/weibocom/motan/compare/1.1.5...1.1.6)

**Implemented enhancements:**

- add trace tag in request&response [\#836](/~https://github.com/weibocom/motan/pull/836) ([sunnights](/~https://github.com/sunnights))
- support custom slow threshold [\#836](/~https://github.com/weibocom/motan/pull/836) ([sunnights](/~https://github.com/sunnights))

**Fixed bugs:**

- remove request exception stacktrace in transport-netty4 [\#836](/~https://github.com/weibocom/motan/pull/836) ([sunnights](/~https://github.com/sunnights))

## [1.1.5](/~https://github.com/weibocom/motan/tree/1.1.5) (2019-05-16)
[Full Changelog](/~https://github.com/weibocom/motan/compare/1.1.4...1.1.5)

Expand Down
2 changes: 1 addition & 1 deletion motan-benchmark/motan-benchmark-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>motan-benchmark</artifactId>
<groupId>com.weibo</groupId>
<version>1.1.6-SNAPSHOT</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion motan-benchmark/motan-benchmark-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>motan-benchmark</artifactId>
<groupId>com.weibo</groupId>
<version>1.1.6-SNAPSHOT</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion motan-benchmark/motan-benchmark-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>motan-benchmark</artifactId>
<groupId>com.weibo</groupId>
<version>1.1.6-SNAPSHOT</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion motan-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>motan</artifactId>
<groupId>com.weibo</groupId>
<version>1.1.6-SNAPSHOT</version>
<version>1.1.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion motan-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>motan</artifactId>
<groupId>com.weibo</groupId>
<version>1.1.6-SNAPSHOT</version>
<version>1.1.6</version>
</parent>
<artifactId>motan-core</artifactId>
<name>motan-core</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.weibo.api.motan.rpc.URL;
import com.weibo.api.motan.util.ExceptionUtil;
import com.weibo.api.motan.util.LoggerUtil;
import com.weibo.api.motan.util.MotanFrameworkUtil;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -70,7 +69,6 @@ public Response call(Request request, LoadBalance<T> loadBalance) {
Referer<T> refer = referers.get(i % referers.size());
try {
request.setRetries(i);
MotanFrameworkUtil.logRequestEvent(request.getRequestId(), "start retry " + i + " " + refer.getServiceUrl().getServerPortStr(), System.currentTimeMillis());
return refer.call(request);
} catch (RuntimeException e) {
// 对于业务异常,直接抛出
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class MotanConstants {
public static final String ZOOKEEPER_REGISTRY_COMMAND = "/command";

public static final String REGISTRY_HEARTBEAT_SWITCHER = "feature.configserver.heartbeat";
public static final String REQUEST_TRACK_LOG_SWITCHER = "feature.request.track.log";
public static final String MOTAN_TRACE_INFO_SWITCHER = "feature.motan.trace.info";

/**
* 默认的consistent的hash的数量
Expand All @@ -139,6 +139,20 @@ public class MotanConstants {
public static final String M2_ERROR = "M_e";
public static final String M2_PROCESS_TIME = "M_pt";

public static final String TRACE_INVOKE = "TRACE_INVOKE";
public static final String TRACE_CONNECTION = "TRACE_CONNECTION";
public static final String TRACE_CENCODE = "TRACE_CENCODE";
public static final String TRACE_CSEND = "TRACE_CSEND";
public static final String TRACE_SRECEIVE = "TRACE_SRECEIVE";
public static final String TRACE_SDECODE = "TRACE_SDECODE";
public static final String TRACE_SEXECUTOR_START = "TRACE_SEXECUTOR_START";
public static final String TRACE_BEFORE_BIZ = "TRACE_BEFORE_BIZ";
public static final String TRACE_AFTER_BIZ = "TRACE_AFTER_BIZ";
public static final String TRACE_PROCESS = "TRACE_PROCESS";
public static final String TRACE_SENCODE = "TRACE_SENCODE";
public static final String TRACE_SSEND = "TRACE_SSEND";
public static final String TRACE_CRECEIVE = "TRACE_CRECEIVE";
public static final String TRACE_CDECODE = "TRACE_CDECODE";

private MotanConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public enum URLParamType {
check("check", "true"),
directUrl("directUrl", ""),
registrySessionTimeout("registrySessionTimeout", 1 * MotanConstants.MINUTE_MILLS),
slowThreshold("slowThreshold", 200),

register("register", true),
subscribe("subscribe", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class AbstractInterfaceConfig extends AbstractConfig {
// 是否需要传输rpc server 端业务异常栈。默认true
protected Boolean transExceptionStack;

protected Integer slowThreshold;

public Integer getRetries() {
return retries;
Expand Down Expand Up @@ -471,4 +472,11 @@ protected String getLocalHostAddress(List<URL> registryURLs) {
MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
}

public Integer getSlowThreshold() {
return slowThreshold;
}

public void setSlowThreshold(int slowThreshold) {
this.slowThreshold = slowThreshold;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MethodConfig extends AbstractConfig {
private Integer actives;
// 参数类型(逗号分隔)
private String argumentTypes;
private Integer slowThreshold;

@ConfigDesc(excluded = true)
public String getName() {
Expand Down Expand Up @@ -75,4 +76,12 @@ public String getArgumentTypes() {
public void setArgumentTypes(String argumentTypes) {
this.argumentTypes = argumentTypes;
}

public Integer getSlowThreshold() {
return slowThreshold;
}

public void setSlowThreshold(Integer slowThreshold) {
this.slowThreshold = slowThreshold;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.weibo.api.motan.filter;

import com.weibo.api.motan.common.MotanConstants;
import com.weibo.api.motan.common.URLParamType;
import com.weibo.api.motan.core.extension.SpiMeta;
import com.weibo.api.motan.rpc.*;
import com.weibo.api.motan.util.ExceptionUtil;
Expand Down Expand Up @@ -62,21 +63,25 @@ public Response filter(final Caller<?> caller, final Request request) {
}

final String statName = caller.getUrl().getProtocol() + MotanConstants.PROTOCOL_SEPARATOR + MotanFrameworkUtil.getGroupMethodString(request);
final int slowCost = caller.getUrl().getIntParameter(URLParamType.slowThreshold.getName(), URLParamType.slowThreshold.getIntValue());
final Response finalResponse = response;
if (caller instanceof Provider) {
StatsUtil.accessStatistic(statName, APPLICATION_STATISTIC, RPC_SERVICE, end, end - start, bizProcessTime, accessStatus);
if (request instanceof TraceableRequest) {
StatsUtil.accessStatistic(statName, APPLICATION_STATISTIC, RPC_SERVICE, end, end - start, bizProcessTime, slowCost, accessStatus);
if (response instanceof Callbackable) {
final AccessStatus finalAccessStatus = accessStatus;
((TraceableRequest) request).addFinishCallback(new Runnable() {
((Callbackable) response).addFinishCallback(new Runnable() {
@Override
public void run() {
long requestEnd = ((TraceableRequest) request).getEndTime();
long requestStart = ((TraceableRequest) request).getStartTime();
StatsUtil.accessStatistic(statName + "_WHOLE", caller.getUrl().getApplication(), caller.getUrl().getModule(), requestEnd, requestEnd - requestStart, bizProcessTime, finalAccessStatus);
if (request instanceof Traceable && finalResponse instanceof Traceable) {
long responseSend = ((Traceable) finalResponse).getTraceableContext().getSendTime();
long requestReceive = ((Traceable) request).getTraceableContext().getReceiveTime();
StatsUtil.accessStatistic(statName + "_WHOLE", caller.getUrl().getApplication(), caller.getUrl().getModule(), responseSend, responseSend - requestReceive, bizProcessTime, slowCost, finalAccessStatus);
}
}
}, null);
}
}
StatsUtil.accessStatistic(statName, caller.getUrl().getApplication(), caller.getUrl().getModule(), end, end - start, bizProcessTime, accessStatus);
StatsUtil.accessStatistic(statName, caller.getUrl().getApplication(), caller.getUrl().getModule(), end, end - start, bizProcessTime, slowCost, accessStatus);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ Object invokeRequest(Request request, Class returnType, boolean async) throws Th
request.setAttachment(URLParamType.application.getName(), cluster.getUrl().getApplication());
request.setAttachment(URLParamType.module.getName(), cluster.getUrl().getModule());

Response response;
Response response = null;
boolean throwException = Boolean.parseBoolean(cluster.getUrl().getParameter(URLParamType.throwException.getName(), URLParamType.throwException.getValue()));
try {
MotanFrameworkUtil.logRequestEvent(request.getRequestId(), "invoke rpc request: " + MotanFrameworkUtil.getFullMethodString(request), System.currentTimeMillis());
MotanFrameworkUtil.logEvent(request, MotanConstants.TRACE_INVOKE);
response = cluster.call(request);
if (async) {
if (response instanceof ResponseFuture) {
Expand Down Expand Up @@ -118,8 +118,6 @@ Object invokeRequest(Request request, Class returnType, boolean async) throws Th
LoggerUtil.error("RefererInvocationHandler invoke Error: uri=" + cluster.getUrl().getUri() + " " + MotanFrameworkUtil.toString(request), e);
throw e;
}
} finally {
MotanFrameworkUtil.logRequestEvent(request.getRequestId(), "rpc finish", System.currentTimeMillis());
}
}
throw new MotanServiceException("Referer call Error: cluster not exist, interface=" + interfaceName + " " + MotanFrameworkUtil.toString(request), MotanErrorMsgConstant.SERVICE_UNFOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.weibo.api.motan.rpc;

import com.weibo.api.motan.common.MotanConstants;
import com.weibo.api.motan.util.MotanFrameworkUtil;
import com.weibo.api.motan.util.ReflectUtil;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -46,7 +48,9 @@ public AbstractProvider(URL url, Class<T> clz) {

@Override
public Response call(Request request) {
MotanFrameworkUtil.logEvent(request, MotanConstants.TRACE_BEFORE_BIZ);
Response response = invoke(request);
MotanFrameworkUtil.logEvent(response, MotanConstants.TRACE_AFTER_BIZ);

return response;
}
Expand Down

This file was deleted.

13 changes: 13 additions & 0 deletions motan-core/src/main/java/com/weibo/api/motan/rpc/Callbackable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.weibo.api.motan.rpc;

import java.util.concurrent.Executor;

/**
* @author sunnights
*/
public interface Callbackable {

void addFinishCallback(Runnable runnable, Executor executor);

void onFinish();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @author fishermen
* @version V1.0 created at: 2013-5-16
*/
public class DefaultRequest extends AbstractTraceableRequest implements Serializable {
public class DefaultRequest implements Request, Traceable, Serializable {

private static final long serialVersionUID = 1168814620391610215L;

Expand All @@ -41,6 +41,7 @@ public class DefaultRequest extends AbstractTraceableRequest implements Serializ
private int retries = 0;
private long requestId;
private byte rpcProtocolVersion = RpcProtocolVersion.VERSION_1.getVersion();
private TraceableContext traceableContext = new TraceableContext();

@Override
public String getInterfaceName() {
Expand Down Expand Up @@ -79,9 +80,8 @@ public void setArguments(Object[] arguments) {
}

@Override
@SuppressWarnings("unchecked")
public Map<String, String> getAttachments() {
return attachments != null ? attachments : Collections.EMPTY_MAP;
return attachments != null ? attachments : Collections.<String, String>emptyMap();
}

public void setAttachments(Map<String, String> attachments) {
Expand Down Expand Up @@ -131,5 +131,8 @@ public void setRpcProtocolVersion(byte rpcProtocolVersion) {
this.rpcProtocolVersion = rpcProtocolVersion;
}


@Override
public TraceableContext getTraceableContext() {
return traceableContext;
}
}
Loading

0 comments on commit a56ac46

Please sign in to comment.