Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use english comment #211

Merged
merged 27 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9aa096b
Merge pull request #4 from alipay/master
glmapper Oct 10, 2018
3a897b4
Merge branch 'master-alipay'
Nov 8, 2018
d50a8a2
Merge branch 'master-alipay'
Nov 21, 2018
27923f4
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Dec 14, 2018
c6461b8
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Dec 27, 2018
c4652c4
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Jan 4, 2019
7758538
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Jan 7, 2019
1c94b31
Merge branch 'master-alipay'
Jan 25, 2019
518d87f
Merge branch 'master-alipay'
Jan 30, 2019
f74b0b3
Merge branch 'master-alipay'
Jan 31, 2019
3c09b2a
Merge branch 'master-alipay'
Feb 13, 2019
7747345
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Feb 20, 2019
2832112
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Feb 22, 2019
72b0467
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Feb 22, 2019
ad04066
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Mar 4, 2019
824628f
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Mar 12, 2019
50d352c
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Mar 15, 2019
954d037
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Mar 22, 2019
ad9793a
Merge remote-tracking branch 'upstream/master'
Mar 26, 2019
298a782
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Mar 28, 2019
9160ad1
Merge branch 'master-alipay'
Mar 28, 2019
1590434
Merge branch 'master' of https://github.com/alipay/sofa-tracer into m…
Apr 4, 2019
c6e47d4
Merge branch 'master-alipay'
Apr 7, 2019
f866abf
use english commnet
Apr 8, 2019
5b5bfe9
Merge pull request #6 from alipay/master
glmapper Apr 9, 2019
455577e
Merge pull request #7 from glmapper/remove-chinese-annotation-and-sta…
glmapper Apr 9, 2019
ee95b73
use english commnet
Apr 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class StatementInterceptorChainImpl extends BaseStatementInterceptorChain {
super(sql, sql, invocation);
}

@Override
protected void beforeInvoke(Invocation invocation) {
invocation.getArgs()[0] = getProcessingSql();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.alipay.common.tracer.core.utils.StringUtils;
import com.alipay.sofa.tracer.plugins.datasource.tracer.*;
import com.alipay.sofa.tracer.plugins.datasource.utils.DataSourceUtils;
import com.alipay.sofa.tracer.plugins.datasource.tracer.Endpoint;

import javax.sql.DataSource;
import java.util.ArrayList;
Expand Down Expand Up @@ -93,6 +92,7 @@ public List<KeyValueAnnotation> getTraceAnnotations() {
/**
* init method must be invoked first after construction
*/
@Override
public void init() {
if (initialized.compareAndSet(false, true)) {
if (StringUtils.isBlank(dbType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
statKey.setEnd(TracerUtils.getLoadTestMark(sofaTracerSpan));
//value the count and duration
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long values[] = new long[] { 1, duration };
long[] values = new long[] { 1, duration };
//reserve
this.addStat(statKey, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public static String resolveDatabaseFromUrl(String url) {
int start = url.lastIndexOf("/");
if (start < 0) {
/**
* oracle sid 格式,{@see jdbc:oracle:thin:@host:port:SID}
* oracle sid format,{@see jdbc:oracle:thin:@host:port:SID}
*/
if ("oracle".equals(resolveDbTypeFromUrl(url))) {
start = url.lastIndexOf(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import static org.mockito.Mockito.when;

/**
* @author qilong.zql 18/8/27-上午9:23
* @author qilong.zql 18/8/27-AM 9:23
*/
public class DruidTest extends BaseTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,23 @@
@Activate(group = { Constants.PROVIDER, Constants.CONSUMER }, value = "dubboSofaTracerFilter", order = 1)
public class DubboSofaTracerFilter implements Filter {

private String appName = StringUtils.EMPTY_STRING;
private String appName = StringUtils.EMPTY_STRING;

private static final String BLANK = StringUtils.EMPTY_STRING;
private static final String BLANK = StringUtils.EMPTY_STRING;

private static final String SUCCESS_CODE = "00";
private static final String SUCCESS_CODE = "00";

private static final String FAILED_CODE = "99";
private static final String FAILED_CODE = "99";

private static final String SPAN_INVOKE_KEY = "sofa.current.span.key";
private static final String TIME_OUT_ERROR_CODE = "03";

private static final String SPAN_INVOKE_KEY = "sofa.current.span.key";

private DubboConsumerSofaTracer dubboConsumerSofaTracer;

private DubboProviderSofaTracer dubboProviderSofaTracer;

private static Map<String, SofaTracerSpan> TracerSpanMap = new ConcurrentHashMap<String, SofaTracerSpan>();
private static Map<String, SofaTracerSpan> TracerSpanMap = new ConcurrentHashMap<String, SofaTracerSpan>();

@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
Expand Down Expand Up @@ -90,7 +92,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
public Result onResponse(Result result, Invoker<?> invoker, Invocation invocation) {
String spanKey = getTracerSpanMapKey(invoker);
try {
// 只有异步才进行回调打印
// only the asynchronous callback to print
boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);
if (!isAsync) {
return result;
Expand Down Expand Up @@ -206,17 +208,17 @@ private Result doClientFilter(RpcContext rpcContext, Invoker<?> invoker, Invocat
// Record client send event
sofaTracerSpan.log(LogData.CLIENT_SEND_EVENT_VALUE);
}
// 将当前 span 缓存
// cache the current span
TracerSpanMap.put(getTracerSpanMapKey(invoker), sofaTracerSpan);
if (clientSpan != null && clientSpan.getParentSofaTracerSpan() != null) {
//restore parent
sofaTraceContext.push(clientSpan.getParentSofaTracerSpan());
}
CompletableFuture<Object> future = (CompletableFuture<Object>) RpcContext.getContext().getFuture();
future.whenComplete((object, throwable)-> {
if (throwable != null && throwable instanceof TimeoutException) {
if (throwable instanceof TimeoutException) {
sofaTracerSpan.setTag(Tags.ERROR.getKey(),throwable.getMessage());
dubboConsumerSofaTracer.clientReceiveTagFinish(sofaTracerSpan, "03");
dubboConsumerSofaTracer.clientReceiveTagFinish(sofaTracerSpan, TIME_OUT_ERROR_CODE);
}
});
}
Expand All @@ -242,7 +244,6 @@ private Result doServerFilter(RpcContext rpcContext, Invoker<?> invoker, Invocat
Throwable exception = null;
try {
result = invoker.invoke(invocation);
// 处理返回结果
if (result == null) {
return null;
} else {
Expand Down Expand Up @@ -277,7 +278,6 @@ private Result doServerFilter(RpcContext rpcContext, Invoker<?> invoker, Invocat

private SofaTracerSpan serverReceived(Invocation invocation) {
Map<String, String> tags = new HashMap<String, String>();
//server tags 必须设置
tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
String serializeSpanContext = invocation.getAttachments()
.get(CommonSpanTags.RPC_TRACE_NAME);
Expand Down Expand Up @@ -305,7 +305,6 @@ private SofaTracerSpan serverReceived(Invocation invocation) {
SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext();
// Record server receive event
serverSpan.log(LogData.SERVER_RECV_EVENT_VALUE);
// 放到线程上下文
sofaTraceContext.push(serverSpan);
return serverSpan;
}
Expand All @@ -322,10 +321,10 @@ private void appendElapsedTimeTags(Invocation invocation, SofaTracerSpan sofaTra
if (isClient) {
elapsed = invocation.getAttachment(CommonSpanTags.CLIENT_SERIALIZE_TIME);
deElapsed = invocation.getAttachment(CommonSpanTags.CLIENT_DESERIALIZE_TIME);
//客户端请求序列化耗时
//The client request serialization time-consuming
sofaTracerSpan
.setTag(CommonSpanTags.CLIENT_SERIALIZE_TIME, parseAttachment(elapsed, 0));
//客户端接受响应反序列化耗时
//The client accepted response deserialization time-consuming
sofaTracerSpan.setTag(CommonSpanTags.CLIENT_DESERIALIZE_TIME,
parseAttachment(deElapsed, 0));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
String methodName = tagsWithStr.get(CommonSpanTags.METHOD);
statKey.setKey(buildString(new String[] { fromApp, toApp, serviceName, methodName }));
String resultCode = tagsWithStr.get(CommonSpanTags.RESULT_CODE);
statKey.setResult(resultCode.equals("00") ? "Y" : "N");
statKey.setResult("00".equals(resultCode) ? "Y" : "N");
statKey.setEnd(buildString(new String[] { getLoadTestMark(sofaTracerSpan) }));
statKey.setLoadTest(TracerUtils.isLoadTest(sofaTracerSpan));
statKey.addKey(CommonSpanTags.LOCAL_APP, fromApp);
statKey.addKey(CommonSpanTags.REMOTE_APP, toApp);
statKey.addKey(CommonSpanTags.SERVICE, serviceName);
statKey.addKey(CommonSpanTags.METHOD, methodName);
//次数和耗时,最后一个耗时是单独打印的字段
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long[] values = new long[] { 1, duration };
this.addStat(statKey, values);
Expand All @@ -82,7 +81,7 @@ protected String getLoadTestMark(SofaTracerSpan span) {
@Override
public void print(StatKey statKey, long[] values) {
if (this.isClosePrint.get()) {
//关闭统计日志输出
//Close the statistics log output
return;
}

Expand All @@ -102,7 +101,7 @@ public void print(StatKey statKey, long[] values) {
} else {
appender.append(jsonBuffer.toString());
}
// 这里强制刷一次
// Forced to flush
appender.flush();
} catch (Throwable t) {
SelfLog.error("stat log<" + statTracerName + "> error!", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
String methodName = tagsWithStr.get(CommonSpanTags.METHOD);
statKey.setKey(buildString(new String[] { fromApp, toApp, serviceName, methodName }));
String resultCode = tagsWithStr.get(CommonSpanTags.RESULT_CODE);
statKey.setResult(resultCode.equals("00") ? "Y" : "N");
statKey.setResult("00".equals(resultCode) ? "Y" : "N");
statKey.setEnd(buildString(new String[] { getLoadTestMark(sofaTracerSpan) }));
statKey.setLoadTest(TracerUtils.isLoadTest(sofaTracerSpan));
statKey.addKey(CommonSpanTags.LOCAL_APP, fromApp);
Expand All @@ -82,7 +82,7 @@ protected String getLoadTestMark(SofaTracerSpan span) {
@Override
public void print(StatKey statKey, long[] values) {
if (this.isClosePrint.get()) {
//关闭统计日志输出
//Close the statistics log output
return;
}

Expand All @@ -102,7 +102,7 @@ public void print(StatKey statKey, long[] values) {
} else {
appender.append(jsonBuffer.toString());
}
// 这里强制刷一次
// Forced to flush
appender.flush();
} catch (Throwable t) {
SelfLog.error("stat log <" + statTracerName + "> error!", t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,21 @@ public void encode(Channel channel, ChannelBuffer buffer, Object message) throws
return;
}
}
// 其它走原来
codec.encode(channel, buffer, message);
}

/**
* @param channel 长连接
* @param buffer UnsafeByteArrayOutputStream
* @param message 原生Request对象
* @param invocation Request里的Invocation
* @throws IOException 序列化出现异常
* @param channel a long connection
* @param buffer buffer
* @param message the original Request object
* @param invocation Invocation in Request
* @throws IOException serialization exception
*/
protected void encodeRequestWithTracer(Channel channel, ChannelBuffer buffer, Object message,
RpcInvocation invocation) throws IOException {
long startTime = System.currentTimeMillis();
int index = buffer.writerIndex();
// 序列化
// serialization
codec.encode(channel, buffer, message);
int reqSize = buffer.writerIndex() - index;
long elapsed = System.currentTimeMillis() - startTime;
Expand All @@ -82,11 +81,11 @@ protected void encodeRequestWithTracer(Channel channel, ChannelBuffer buffer, Ob
}

/**
* @param channel 长连接
* @param buffer UnsafeByteArrayOutputStream
* @param result 原生Resopnse对象
* @param rpcResult Resopnse对象的结果
* @throws IOException 序列化出现异常
* @param channel a long connection
* @param buffer buffer
* @param result the original Request object
* @param rpcResult result of Response
* @throws IOException serialization exception
*/
protected void encodeResultWithTracer(Channel channel, ChannelBuffer buffer, Object result,
RpcResult rpcResult) throws IOException {
Expand All @@ -101,7 +100,7 @@ protected void encodeResultWithTracer(Channel channel, ChannelBuffer buffer, Obj
}

/**
* 反序列化操作
* deserialization operation
* @param channel
* @param input
* @return
Expand All @@ -115,7 +114,7 @@ public Object decode(Channel channel, ChannelBuffer input) throws IOException {
int size = input.readerIndex() - index;
long elapsed = System.currentTimeMillis() - startTime;
if (ret instanceof Request) {
// 服务端反序列化Request
// server-side deserialize the Request
Object data = ((Request) ret).getData();
if (data instanceof RpcInvocation) {
RpcInvocation invocation = (RpcInvocation) data;
Expand All @@ -125,7 +124,7 @@ public Object decode(Channel channel, ChannelBuffer input) throws IOException {
}

} else if (ret instanceof Response) {
// 客户端反序列化Response
// client-side deserialize the Response
Object result = ((Response) ret).getResult();
if (result instanceof RpcResult) {
RpcResult rpcResult = (RpcResult) result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,24 @@ public void testBefore() throws Exception {
// registry
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("N/A");
// 服务提供者协议配置
// protocolConfig
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("dubbo");
protocol.setThreadpool("fixed");
protocol.setPort(12280);
protocol.setSerialization("hessian2");
// 服务提供者连接注册中心,设置属性
DubboServiceImpl dubboServiceImpl = new DubboServiceImpl();
ServiceConfig<DubboService> service = new ServiceConfig<DubboService>();
ServiceConfig<DubboService> service = new ServiceConfig<>();
service.setApplication(application);
service.setProtocol(protocol); // 多个协议可以用setProtocols()
//Multiple protocols can be used with setProtocols()
service.setProtocol(protocol);
service.setInterface(DubboService.class.getName());
service.setRef(dubboServiceImpl);
service.setGroup("tracer");
service.setVersion("1.0");
service.setFilter("dubboSofaTracerFilter");
service.setRegistry(registryConfig);
//services.setRegister(false);
// 暴露及注册服务
// Exposure and registration services
service.export();
List<URL> exportedUrls = service.getExportedUrls();
Assert.assertTrue(exportedUrls.size() == 1);
Expand All @@ -80,8 +79,8 @@ public void testBefore() throws Exception {
public void testTracer() throws Exception {
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("N/A");
// 服务调用者连接注册中心,设置属性
ReferenceConfig<DubboService> reference = new ReferenceConfig<DubboService>(); // 此实例很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏
//The service caller connects to the registry and sets the properties.
ReferenceConfig<DubboService> reference = new ReferenceConfig<>();
reference.setInterface(DubboService.class);
reference.setRegistry(registryConfig);
reference.setUrl(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
statKey.setEnd(TracerUtils.getLoadTestMark(sofaTracerSpan));
//value the count and duration
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long values[] = new long[] { 1, duration };
long[] values = new long[] { 1, duration };
//reserve
this.addStat(statKey, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public abstract class AbstractHttpRequestInterceptor {

protected AbstractTracer httpClientTracer;

protected String appName = null;
protected String appName;

protected String targetAppName = null;
protected String targetAppName;

public AbstractHttpRequestInterceptor(AbstractTracer httpClientTracer, String appName,
String targetAppName) {
Expand All @@ -68,7 +68,6 @@ public void appendHttpClientRequestSpanTags(HttpRequest httpRequest,
//targetAppName
httpClientSpan.setTag(CommonSpanTags.REMOTE_APP,
this.targetAppName == null ? StringUtils.EMPTY_STRING : this.targetAppName);
//url ((HttpRequestWrapper) request).getOriginal().getRequestLine().getUri()
if (httpRequest instanceof HttpRequestWrapper) {
HttpRequestWrapper httpRequestWrapper = (HttpRequestWrapper) httpRequest;
httpClientSpan.setTag(CommonSpanTags.REQUEST_URL, httpRequestWrapper.getOriginal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
statKey.setEnd(TracerUtils.getLoadTestMark(sofaTracerSpan));
//value the count and duration
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long values[] = new long[] { 1, duration };
long[] values = new long[] { 1, duration };
//reserve
this.addStat(statKey, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
*/
public class SofaTracerOkHttpInterceptor implements okhttp3.Interceptor {

protected String appName = null;
protected String appName;

protected String targetAppName = null;
protected String targetAppName;

protected AbstractTracer okHttpTracer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) {
statKey.setEnd(TracerUtils.getLoadTestMark(sofaTracerSpan));
//value the count and duration
long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime();
long values[] = new long[] { 1, duration };
long[] values = new long[] { 1, duration };
//reserve
this.addStat(statKey, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static AsyncRestTemplate buildAsyncRestTemplate() {
return asyncRestTemplate;
}

public synchronized static AbstractTracer getRestTemplateTracer() {
public static AbstractTracer getRestTemplateTracer() {
if (restTemplateTracer == null) {
synchronized (RestTemplateTracer.class) {
if (restTemplateTracer == null) {
Expand Down
Loading