From 2a0a3f2583939e925992fe9111f636d647a06d3f Mon Sep 17 00:00:00 2001 From: GuoLei Song <35319286+glmapper@users.noreply.github.com> Date: Thu, 11 Apr 2019 21:25:24 +0800 Subject: [PATCH] Use english comment (#211) --- .../plugins/datasource/ExtendedStatement.java | 1 + .../plugins/datasource/SmartDataSource.java | 2 +- .../DataSourceClientStatJsonReporter.java | 2 +- .../datasource/utils/DataSourceUtils.java | 2 +- .../tracer/plugins/datasource/DruidTest.java | 2 +- .../plugins/dubbo/DubboSofaTracerFilter.java | 29 ++-- .../stat/DubboClientStatJsonReporter.java | 7 +- .../stat/DubboServerStatJsonReporter.java | 6 +- .../dubbo/wrapper/DataSizeCodecWrapper.java | 29 ++-- .../plugins/dubbo/DubboSofaTracerTest.java | 15 +- .../HttpClientStatJsonReporter.java | 2 +- .../AbstractHttpRequestInterceptor.java | 5 +- .../okhttp/OkHttpStatJsonReporter.java | 2 +- .../SofaTracerOkHttpInterceptor.java | 4 +- .../rest/RestTemplateStatJsonReporter.java | 2 +- .../rest/SofaTracerRestTemplateBuilder.java | 2 +- .../springmvc/SpringMvcDigestJsonEncoder.java | 15 +- .../springmvc/SpringMvcHeadersCarrier.java | 3 + .../springmvc/SpringMvcJsonStatReporter.java | 16 +- .../plugins/springmvc/SpringMvcLogEnum.java | 6 +- .../springmvc/SpringMvcSofaTracerFilter.java | 2 - .../springmvc/SpringMvcStatReporter.java | 5 +- .../SpringMvcSofaTracerFilterTest.java | 4 +- .../ZipkinSofaTracerSpanRemoteReporter.java | 8 +- .../zipkin/adapter/ZipkinV2SpanAdapter.java | 4 +- .../zipkin/ZipkinRestTemplateSenderTest.java | 4 +- .../alipay/common/tracer/core/SofaTracer.java | 76 ++++----- .../tracer/core/appender/TraceAppender.java | 17 +- .../core/appender/TracerLogRootDaemon.java | 18 ++- .../appender/builder/JsonStringBuilder.java | 4 +- .../core/appender/builder/XStringBuilder.java | 100 ++++++------ .../core/appender/encoder/SpanEncoder.java | 14 +- .../file/AbstractRollingFileAppender.java | 27 ++-- .../appender/file/CompositeTraceAppender.java | 17 +- .../appender/file/LoadTestAwareAppender.java | 4 +- .../file/TimedRollingFileAppender.java | 91 +++++------ .../manager/AsyncCommonAppenderManager.java | 12 +- .../AsyncCommonDigestAppenderManager.java | 3 +- .../manager/ConsumerExceptionHandler.java | 2 +- .../manager/ConsumerThreadFactory.java | 2 +- .../manager/SofaTracerSpanEventFactory.java | 2 +- .../StringConsumerExceptionHandler.java | 4 +- .../core/appender/manager/StringEvent.java | 2 +- .../appender/manager/StringEventFactory.java | 2 +- .../tracer/core/appender/self/SelfLog.java | 25 ++- .../appender/self/SynchronizingSelfLog.java | 29 ++-- .../core/appender/self/TracerDaemon.java | 13 +- .../tracer/core/async/SofaTracerCallable.java | 3 +- .../tracer/core/async/SofaTracerRunnable.java | 3 +- .../async/TracerScheduleExecutorService.java | 5 +- .../SofaTracerConfiguration.java | 104 +++++++------ .../SofaTracerExternalConfiguration.java | 14 +- .../core/constants/SofaTracerConstant.java | 28 ++-- .../context/span/SofaTracerSpanContext.java | 118 +++++++------- .../core/context/trace/SofaTraceContext.java | 6 +- .../EmptyTracerStateStringException.java | 2 +- .../SamplingStrategyErrorException.java | 4 +- .../exception/SofaTracerRuntimeException.java | 1 + .../exception/UnsupportedFormatException.java | 4 +- .../tracer/core/extensions/SpanExtension.java | 19 ++- .../core/extensions/SpanExtensionFactory.java | 2 +- .../core/holder/SofaTraceContextHolder.java | 4 +- .../core/listener/SpanReportListener.java | 7 +- .../parent/AbstractDigestSpanEncoder.java | 15 +- .../tracer/core/mock/MockSofaTracer.java | 6 +- .../registry/AbstractTextB3Formatter.java | 6 +- .../core/registry/AbstractTextFormatter.java | 20 +-- .../tracer/core/registry/BinaryFormater.java | 19 ++- .../registry/RegistryExtractorInjector.java | 25 +-- .../reporter/common/CommonSpanEncoder.java | 9 +- .../reporter/common/CommonTracerManager.java | 39 +++-- .../reporter/digest/AbstractDiskReporter.java | 52 +++---- .../reporter/digest/DiskReporterImpl.java | 44 +++--- .../SofaTracerDigestReporterAsyncManager.java | 9 +- .../reporter/facade/AbstractReporter.java | 22 +-- .../tracer/core/reporter/facade/Reporter.java | 22 +-- .../AbstractSofaTracerStatisticReporter.java | 96 ++++++------ .../stat/SofaTracerStatisticReporter.java | 46 +++--- ...cerStatisticReporterCycleTimesManager.java | 15 +- .../SofaTracerStatisticReporterManager.java | 61 ++++---- .../core/reporter/stat/model/StatKey.java | 8 +- .../core/reporter/stat/model/StatMapKey.java | 2 +- .../core/reporter/stat/model/StatValues.java | 56 ++++--- .../reporter/type/TracerSystemLogEnum.java | 25 +-- .../common/tracer/core/samplers/Sampler.java | 5 + .../tracer/core/samplers/SamplingStatus.java | 4 +- .../SofaTracerPercentageBasedSampler.java | 6 +- .../tracer/core/span/CommonLogSpan.java | 27 ++-- .../common/tracer/core/span/LogData.java | 4 +- .../tracer/core/span/SofaTracerSpan.java | 145 ++++++++---------- .../SofaTracerSpanReferenceRelationship.java | 4 +- .../common/tracer/core/tags/SpanTags.java | 4 +- .../tracer/core/tracer/AbstractTracer.java | 6 +- .../tracer/core/utils/ByteArrayUtils.java | 124 ++------------- .../common/tracer/core/utils/CommonUtils.java | 20 ++- .../tracer/core/utils/ReflectionUtils.java | 3 - .../common/tracer/core/utils/StringUtils.java | 85 +++++----- .../common/tracer/core/utils/TracerUtils.java | 40 +++-- .../alipay/common/tracer/core/TestUtil.java | 3 - .../tracer/core/appender/LogCleanupTest.java | 64 ++++---- .../appender/TracerLogRootDaemonTest.java | 2 +- .../builder/JsonStringBuilderTest.java | 2 +- .../appender/builder/XStringBuilderTest.java | 10 +- .../file/TimedRollingFileAppenderTest.java | 7 +- .../core/appender/info/StaticInfoLogTest.java | 6 +- .../ConcurrentConsumerCorrectTest.java | 94 +++++------- .../manager/ConcurrentDiscardTest.java | 78 +++++----- .../appender/manager/ManagerTestUtil.java | 18 +-- .../core/appender/self/SelfLogTest.java | 2 +- .../core/async/SofaTracerCallableTest.java | 2 +- .../core/async/SofaTracerRunnableTest.java | 2 +- .../core/async/TracedExecutorServiceTest.java | 2 +- .../TracerScheduleExecutorServiceTest.java | 9 +- .../tracer/core/base/AbstractTestBase.java | 23 +-- .../tracer/core/benchmark/CountBenchmark.java | 4 +- .../SofaTracerConfigurationTest.java | 2 +- .../span/SofaTracerSpanContextTest.java | 2 +- ...SofaTracerThreadLocalTraceContextTest.java | 2 +- .../holder/SofaTraceContextHolderTest.java | 2 +- .../SpanReportListenerHolderTest.java | 2 +- .../tracer/core/mock/MockSofaTracerTest.java | 2 +- .../core/registry/BinaryFormaterTest.java | 23 ++- .../registry/HttpHeadersB3FormatterTest.java | 2 +- .../registry/HttpHeadersFormatterTest.java | 9 +- .../core/registry/TextMapB3FormatterTest.java | 2 +- .../core/registry/TextMapFormatterTest.java | 4 +- .../registry/TracerFormatRegistryTest.java | 4 +- ...tatisticReporterCycleTimesManagerTest.java | 2 +- .../common/CommonSpanEncoderTest.java | 19 ++- .../common/CommonTracerManagerTest.java | 6 +- ...TracerCompositeDigestReporterImplTest.java | 2 +- .../reporter/digest/DiskReporterImplTest.java | 5 +- .../SofaTracerStatisticReporterImplTest.java | 18 +-- .../reporter/stat/model/StatMapKeyTest.java | 12 +- .../tracer/core/span/SofaTracerSpanTest.java | 2 +- .../core/tracertest/SofaTracerTest.java | 22 +-- .../tracertest/type/TracerTestLogEnum.java | 16 +- .../tracer/core/utils/StringUtilsTest.java | 2 +- .../tracer/core/utils/TracerUtilsTest.java | 43 +++--- .../extensions/log/MDCSpanExtension.java | 2 +- .../log/constants/MDCKeyConstants.java | 4 +- .../SofaTracerDataSourceProperties.java | 2 +- .../CustomRestTemplateCustomizer.java | 2 +- .../RestTemplateAutoConfiguration.java | 2 +- ...ipkinSofaTracerSpanRemoteReporterTest.java | 19 +-- .../tracer/test/MDCMultiThreadTest.java | 2 +- .../alipay/common/tracer/test/MDCTest.java | 31 ++-- .../tracer/test/base/AbstractTestBase.java | 30 ++-- .../core/sofatracer/SofaTracerDemoTest.java | 6 +- .../SofaTracerStatisticsDemoTest.java | 6 +- .../sofatracer/type/TracerTestLogEnum.java | 12 +- .../com/alipay/common/tracer/LogTest.java | 4 +- .../com/alipay/common/tracer/LogTest.java | 2 +- .../com/alipay/commom/tracer/LogTest.java | 4 +- 154 files changed, 1236 insertions(+), 1466 deletions(-) diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/ExtendedStatement.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/ExtendedStatement.java index 0eb85a8d..b08bf252 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/ExtendedStatement.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/ExtendedStatement.java @@ -129,6 +129,7 @@ class StatementInterceptorChainImpl extends BaseStatementInterceptorChain { super(sql, sql, invocation); } + @Override protected void beforeInvoke(Invocation invocation) { invocation.getArgs()[0] = getProcessingSql(); } diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/SmartDataSource.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/SmartDataSource.java index 7e520e40..9d8f3bc3 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/SmartDataSource.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/SmartDataSource.java @@ -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; @@ -93,6 +92,7 @@ public List getTraceAnnotations() { /** * init method must be invoked first after construction */ + @Override public void init() { if (initialized.compareAndSet(false, true)) { if (StringUtils.isBlank(dbType)) { diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatJsonReporter.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatJsonReporter.java index 2b534969..3a8ce56c 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatJsonReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/tracer/DataSourceClientStatJsonReporter.java @@ -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); } diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java index 8c7cbf5e..c0518bfe 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/main/java/com/alipay/sofa/tracer/plugins/datasource/utils/DataSourceUtils.java @@ -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(":"); diff --git a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/DruidTest.java b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/DruidTest.java index 2ab79972..5f824a1a 100644 --- a/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/DruidTest.java +++ b/sofa-tracer-plugins/sofa-tracer-datasource-plugin/src/test/java/com/sofa/tracer/plugins/datasource/DruidTest.java @@ -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 { diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerFilter.java b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerFilter.java index a71f64a7..85d8216e 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerFilter.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerFilter.java @@ -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 TracerSpanMap = new ConcurrentHashMap(); + private static Map TracerSpanMap = new ConcurrentHashMap(); @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { @@ -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; @@ -206,7 +208,7 @@ 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 @@ -214,9 +216,9 @@ private Result doClientFilter(RpcContext rpcContext, Invoker invoker, Invocat } CompletableFuture future = (CompletableFuture) 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); } }); } @@ -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 { @@ -277,7 +278,6 @@ private Result doServerFilter(RpcContext rpcContext, Invoker invoker, Invocat private SofaTracerSpan serverReceived(Invocation invocation) { Map tags = new HashMap(); - //server tags 必须设置 tags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER); String serializeSpanContext = invocation.getAttachments() .get(CommonSpanTags.RPC_TRACE_NAME); @@ -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; } @@ -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 { diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/stat/DubboClientStatJsonReporter.java b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/stat/DubboClientStatJsonReporter.java index bbd439f0..5c0b928e 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/stat/DubboClientStatJsonReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/stat/DubboClientStatJsonReporter.java @@ -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); @@ -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; } @@ -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); diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/stat/DubboServerStatJsonReporter.java b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/stat/DubboServerStatJsonReporter.java index 12acdfba..4072fa21 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/stat/DubboServerStatJsonReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/stat/DubboServerStatJsonReporter.java @@ -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); @@ -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; } @@ -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); diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/wrapper/DataSizeCodecWrapper.java b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/wrapper/DataSizeCodecWrapper.java index de1c88d8..0b102423 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/wrapper/DataSizeCodecWrapper.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/main/java/com/alipay/sofa/tracer/plugins/dubbo/wrapper/DataSizeCodecWrapper.java @@ -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; @@ -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 { @@ -101,7 +100,7 @@ protected void encodeResultWithTracer(Channel channel, ChannelBuffer buffer, Obj } /** - * 反序列化操作 + * deserialization operation * @param channel * @param input * @return @@ -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; @@ -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; diff --git a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/test/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerTest.java b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/test/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerTest.java index 9811670c..bf596401 100644 --- a/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/test/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerTest.java +++ b/sofa-tracer-plugins/sofa-tracer-dubbo-plugin/src/test/java/com/alipay/sofa/tracer/plugins/dubbo/DubboSofaTracerTest.java @@ -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 service = new ServiceConfig(); + ServiceConfig 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 exportedUrls = service.getExportedUrls(); Assert.assertTrue(exportedUrls.size() == 1); @@ -80,8 +79,8 @@ public void testBefore() throws Exception { public void testTracer() throws Exception { RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress("N/A"); - // 服务调用者连接注册中心,设置属性 - ReferenceConfig reference = new ReferenceConfig(); // 此实例很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏 + //The service caller connects to the registry and sets the properties. + ReferenceConfig reference = new ReferenceConfig<>(); reference.setInterface(DubboService.class); reference.setRegistry(registryConfig); reference.setUrl(address); diff --git a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/HttpClientStatJsonReporter.java b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/HttpClientStatJsonReporter.java index 7e1afa9f..b767dade 100644 --- a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/HttpClientStatJsonReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/HttpClientStatJsonReporter.java @@ -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); } diff --git a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/AbstractHttpRequestInterceptor.java b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/AbstractHttpRequestInterceptor.java index 3078807f..15294d3c 100644 --- a/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/AbstractHttpRequestInterceptor.java +++ b/sofa-tracer-plugins/sofa-tracer-httpclient-plugin/src/main/java/com/alipay/sofa/tracer/plugins/httpclient/interceptor/AbstractHttpRequestInterceptor.java @@ -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) { @@ -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() diff --git a/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/main/java/com/alipay/sofa/tracer/plugins/okhttp/OkHttpStatJsonReporter.java b/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/main/java/com/alipay/sofa/tracer/plugins/okhttp/OkHttpStatJsonReporter.java index b0d06837..bad7bc65 100644 --- a/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/main/java/com/alipay/sofa/tracer/plugins/okhttp/OkHttpStatJsonReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/main/java/com/alipay/sofa/tracer/plugins/okhttp/OkHttpStatJsonReporter.java @@ -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); } diff --git a/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/main/java/com/alipay/sofa/tracer/plugins/okhttp/interceptor/SofaTracerOkHttpInterceptor.java b/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/main/java/com/alipay/sofa/tracer/plugins/okhttp/interceptor/SofaTracerOkHttpInterceptor.java index 37bca4c7..bef973d9 100644 --- a/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/main/java/com/alipay/sofa/tracer/plugins/okhttp/interceptor/SofaTracerOkHttpInterceptor.java +++ b/sofa-tracer-plugins/sofa-tracer-okhttp-plugin/src/main/java/com/alipay/sofa/tracer/plugins/okhttp/interceptor/SofaTracerOkHttpInterceptor.java @@ -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; diff --git a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/RestTemplateStatJsonReporter.java b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/RestTemplateStatJsonReporter.java index 1333e40b..05cfe512 100644 --- a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/RestTemplateStatJsonReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/RestTemplateStatJsonReporter.java @@ -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); } diff --git a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/SofaTracerRestTemplateBuilder.java b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/SofaTracerRestTemplateBuilder.java index 01525a2e..4dbbdd92 100644 --- a/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/SofaTracerRestTemplateBuilder.java +++ b/sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/src/main/java/com/sofa/alipay/tracer/plugins/rest/SofaTracerRestTemplateBuilder.java @@ -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) { diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcDigestJsonEncoder.java b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcDigestJsonEncoder.java index c16bb6c4..5b0d7438 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcDigestJsonEncoder.java +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcDigestJsonEncoder.java @@ -37,7 +37,6 @@ public class SpringMvcDigestJsonEncoder extends AbstractDigestSpanEncoder { @Override public String encode(SofaTracerSpan span) throws IOException { JsonStringBuilder jsonStringBuilder = new JsonStringBuilder(); - //日志打印时间 jsonStringBuilder.appendBegin("time", Timestamp.format(span.getEndTime())); appendSlot(jsonStringBuilder, span); return jsonStringBuilder.toString(); @@ -48,35 +47,33 @@ private void appendSlot(JsonStringBuilder jsonStringBuilder, SofaTracerSpan sofa SofaTracerSpanContext context = sofaTracerSpan.getSofaTracerSpanContext(); Map tagWithStr = sofaTracerSpan.getTagsWithStr(); Map tagWithNumber = sofaTracerSpan.getTagsWithNumber(); - //当前应用名 jsonStringBuilder .append(CommonSpanTags.LOCAL_APP, tagWithStr.get(CommonSpanTags.LOCAL_APP)); //TraceId jsonStringBuilder.append("traceId", context.getTraceId()); //RpcId jsonStringBuilder.append("spanId", context.getSpanId()); - //请求 URL + //URL jsonStringBuilder.append(CommonSpanTags.REQUEST_URL, tagWithStr.get(CommonSpanTags.REQUEST_URL)); - //请求方法 + //Request method jsonStringBuilder.append(CommonSpanTags.METHOD, tagWithStr.get(CommonSpanTags.METHOD)); - //Http 状态码 + //Http code jsonStringBuilder.append(CommonSpanTags.RESULT_CODE, tagWithStr.get(CommonSpanTags.RESULT_CODE)); Number requestSize = tagWithNumber.get(CommonSpanTags.REQ_SIZE); - //Request Body 大小 单位为byte + //Request Body Size (byte) jsonStringBuilder.append(CommonSpanTags.REQ_SIZE, (requestSize == null ? 0L : requestSize.longValue())); Number responseSize = tagWithNumber.get(CommonSpanTags.RESP_SIZE); - //Response Body 大小,单位为byte + //Response Body Size,(byte) jsonStringBuilder.append(CommonSpanTags.RESP_SIZE, (responseSize == null ? 0L : responseSize.longValue())); - //请求耗时(MS) + //Request time (MS) jsonStringBuilder.append("time.cost.milliseconds", (sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime())); jsonStringBuilder.append(CommonSpanTags.CURRENT_THREAD_NAME, tagWithStr.get(CommonSpanTags.CURRENT_THREAD_NAME)); - //穿透数据放在最后 jsonStringBuilder.appendEnd("baggage", baggageSerialized(context)); } } \ No newline at end of file diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcHeadersCarrier.java b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcHeadersCarrier.java index 63f8b053..997830cb 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcHeadersCarrier.java +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcHeadersCarrier.java @@ -22,6 +22,9 @@ import java.util.Iterator; import java.util.Map; +/** + * @author yangguanchao + */ public class SpringMvcHeadersCarrier implements TextMap { private HashMap headers; diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcJsonStatReporter.java b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcJsonStatReporter.java index 0a9c7112..b26aadf7 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcJsonStatReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcJsonStatReporter.java @@ -36,9 +36,6 @@ */ public class SpringMvcJsonStatReporter extends SpringMvcStatReporter { - /*** - * 输出拼接器 - */ private static JsonStringBuilder jsonBuffer = new JsonStringBuilder(); public SpringMvcJsonStatReporter(String statTracerName, String rollingPolicy, @@ -62,10 +59,9 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) { statKey.setResult(success ? "true" : "false"); //end statKey.setEnd(TracerUtils.getLoadTestMark(sofaTracerSpan)); - //value - //次数和耗时,最后一个耗时是单独打印的字段 + //duration long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime(); - long values[] = new long[] { 1, duration }; + long[] values = new long[] { 1, duration }; //reserve this.addStat(statKey, values); } @@ -73,7 +69,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) { @Override public void print(StatKey statKey, long[] values) { if (this.isClosePrint.get()) { - //关闭统计日志输出 + //Close the statistics log output return; } if (!(statKey instanceof StatMapKey)) { @@ -88,7 +84,7 @@ public void print(StatKey statKey, long[] values) { jsonBuffer.append("count", values[0]); jsonBuffer.append("total.cost.milliseconds", values[1]); jsonBuffer.append("success", statMapKey.getResult()); - //压测 + //pressure test mark jsonBuffer.appendEnd("load.test", statMapKey.getEnd()); if (appender instanceof LoadTestAwareAppender) { @@ -97,10 +93,10 @@ public void print(StatKey statKey, long[] values) { } else { appender.append(jsonBuffer.toString()); } - // 这里强制刷一次 + // Forced to flush appender.flush(); } catch (Throwable t) { - SelfLog.error("统计日志<" + statTracerName + ">输出异常", t); + SelfLog.error("Stat log<" + statTracerName + "> error!", t); } } diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcLogEnum.java b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcLogEnum.java index ad9b0706..2e4e0c3d 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcLogEnum.java +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcLogEnum.java @@ -24,10 +24,10 @@ */ public enum SpringMvcLogEnum { - // SOFA MVC 日志 SPRING_MVC_DIGEST("spring_mvc_digest_log_name", "spring-mvc-digest.log", - "spring_mvc_digest_rolling"), // - SPRING_MVC_STAT("spring_mvc_stat_log_name", "spring-mvc-stat.log", "spring_mvc_stat_rolling"); + "spring_mvc_digest_rolling"), SPRING_MVC_STAT("spring_mvc_stat_log_name", + "spring-mvc-stat.log", + "spring_mvc_stat_rolling"); private String logNameKey; private String defaultLogName; diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilter.java b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilter.java index 5271bf8d..96409c23 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilter.java +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilter.java @@ -79,7 +79,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo springMvcSpan.setTag(CommonSpanTags.REQ_SIZE, request.getContentLength()); //wrapper ResponseWrapper responseWrapper = new ResponseWrapper(response); - //filter begin filterChain.doFilter(servletRequest, responseWrapper); //filter end @@ -87,7 +86,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo responseSize = responseWrapper.getContentLength(); } catch (Throwable t) { httpStatus = 500; - // 异常抛出 throw new RuntimeException(t); } finally { if (springMvcSpan != null) { diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcStatReporter.java b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcStatReporter.java index 2ed649d7..94335014 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcStatReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/main/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcStatReporter.java @@ -52,10 +52,9 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) { statKey.setEnd(buildString(new String[] { TracerUtils.getLoadTestMark(sofaTracerSpan) })); //pressure mark statKey.setLoadTest(TracerUtils.isLoadTest(sofaTracerSpan)); - - //次数和耗时,最后一个耗时是单独打印的字段 + //duration long duration = sofaTracerSpan.getEndTime() - sofaTracerSpan.getStartTime(); - long values[] = new long[] { 1, duration }; + long[] values = new long[] { 1, duration }; this.addStat(statKey, values); } } \ No newline at end of file diff --git a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/test/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilterTest.java b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/test/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilterTest.java index c1f88c64..84f904ce 100644 --- a/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/test/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilterTest.java +++ b/sofa-tracer-plugins/sofa-tracer-springmvc-plugin/src/test/java/com/alipay/sofa/tracer/plugins/springmvc/SpringMvcSofaTracerFilterTest.java @@ -28,13 +28,13 @@ import java.util.List; /** - * @author: guolei.sgl (guolei.sgl@antfin.com) 19/1/30 下午2:19 + * @author: guolei.sgl (guolei.sgl@antfin.com) 19/1/30 PM2:19 * @since: **/ public class SpringMvcSofaTracerFilterTest extends AbstractTestBase { /** - * 测试当业务 Filter 链执行过程发生异常时,异常信息不会被打印到 tracer-self.log 中 + * Test that exception information is not printed to tracer-self.log when an exception occurs during the execution of the business Filter chain * @throws Exception */ @Test diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerSpanRemoteReporter.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerSpanRemoteReporter.java index 1ec46e84..c0a98a47 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerSpanRemoteReporter.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinSofaTracerSpanRemoteReporter.java @@ -70,10 +70,10 @@ public void close() { this.delegate.close(); } - /*** - * 功能:将 16 进制字符串转换为:十进制整数 - * @param hexString 16 进制字符串 - * @return 十进制整数 + /** + * To convert hexadecimal string to decimal integer + * @param hexString hexadecimal + * @return decimal */ public static long traceIdToId(String hexString) { Assert.hasText(hexString, "Can't convert empty hex string to long"); diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/ZipkinV2SpanAdapter.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/ZipkinV2SpanAdapter.java index 182ed6c0..53f61c5d 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/ZipkinV2SpanAdapter.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/main/java/com/alipay/sofa/tracer/plugins/zipkin/adapter/ZipkinV2SpanAdapter.java @@ -122,7 +122,7 @@ private Endpoint getZipkinEndpoint(SofaTracerSpan span) { ipAddress = InetAddress.getLocalHost(); this.ipAddressInt = ByteBuffer.wrap(ipAddress.getAddress()).getInt(); } catch (UnknownHostException e) { - //127.0.0.1 256 进制 + //127.0.0.1 256 this.ipAddressInt = 256 * 256 * 256 * 127 + 1; } } @@ -131,7 +131,7 @@ private Endpoint getZipkinEndpoint(SofaTracerSpan span) { } /** - * 将Baggage中的数据也放在tags中 + * Put the baggage data into the tags * @param zipkinSpan * @param span */ diff --git a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinRestTemplateSenderTest.java b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinRestTemplateSenderTest.java index 83cda74c..af41810a 100644 --- a/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinRestTemplateSenderTest.java +++ b/sofa-tracer-plugins/sofa-tracer-zipkin-plugin/src/test/java/com/alipay/sofa/tracer/plugins/zipkin/ZipkinRestTemplateSenderTest.java @@ -62,7 +62,7 @@ public void messageMaxBytes() { public void messageSizeInBytes() { byte[] tests = new byte[1]; tests[0] = 0; - List spans = new ArrayList(); + List spans = new ArrayList<>(); spans.add(tests); int i = zipkinRestTemplateSender.messageSizeInBytes(spans); Assert.assertTrue(i == 3); @@ -72,7 +72,7 @@ public void messageSizeInBytes() { public void sendSpans() throws InterruptedException { byte[] tests = new byte[1]; tests[0] = 0; - List encodedSpans = new ArrayList(); + List encodedSpans = new ArrayList<>(); encodedSpans.add(tests); Call voidCall = zipkinRestTemplateSender.sendSpans(encodedSpans); Thread.sleep(500); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java index 213f9c91..a44aa197 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java @@ -49,32 +49,32 @@ public class SofaTracer implements Tracer { /** - * 正常 TRACE 开始的 spanId + * normal root spanId's default value */ public static final String ROOT_SPAN_ID = "0"; - /*** - * 标示 tracer 的类型 + /** + * Mark the type of tracer */ private final String tracerType; - /*** - * 作为客户端运行时的 Reporter + /** + * Reporter as a client runtime */ private final Reporter clientReporter; - /*** - * 作为服务端运行时的 Reporter + /** + * Reporter as a server runtime */ private final Reporter serverReporter; - /*** - * 这个 tracerTags 主要用于缓存和 tracer 全局相关的一些信息 + /** + * Cache some information related to the tracer globally */ - private final Map tracerTags = new ConcurrentHashMap(); + private final Map tracerTags = new ConcurrentHashMap<>(); /** - * 支持 sampler 即根据 rate 采样(主要在入口起作用) + * Sampler instance */ private final Sampler sampler; @@ -123,19 +123,16 @@ public void reportSpan(SofaTracerSpan span) { } //invoke listener this.invokeReportListeners(span); - //客户端、服务端 if (span.isClient()) { - //摘要 if (this.clientReporter != null) { this.clientReporter.report(span); } } else if (span.isServer()) { - //摘要 if (this.serverReporter != null) { this.serverReporter.report(span); } } else { - //ignore 不统计 + //ignore ,do not statical SelfLog.warn("Span reported neither client nor server.Ignore!"); } } @@ -191,25 +188,25 @@ private void invokeReportListeners(SofaTracerSpan sofaTracerSpan) { } } - /*** - * SofaTracerSpanBuilder 用于在 Tracer 内部构建 Span + /** + * SofaTracerSpanBuilder is used to build Span inside Tracer */ public class SofaTracerSpanBuilder implements io.opentracing.Tracer.SpanBuilder { - private String operationName = StringUtils.EMPTY_STRING; + private String operationName; - /*** - * 默认初始化时间 + /** + * Default initialization time */ - private long startTime = -1; + private long startTime = -1; /** * In 99% situations there is only one parent (childOf), so we do not want to allocate * a collection of references. */ - private List references = Collections.emptyList(); + private List references = Collections.emptyList(); - private final Map tags = new HashMap(); + private final Map tags = new HashMap(); public SofaTracerSpanBuilder(String operationName) { this.operationName = operationName; @@ -246,8 +243,8 @@ public Tracer.SpanBuilder addReference(String referenceType, SpanContext referen (SofaTracerSpanContext) referencedContext, referenceType)); } else { if (references.size() == 1) { - //要保证有顺序 - references = new ArrayList(references); + //To ensure order + references = new ArrayList<>(references); } references.add(new SofaTracerSpanReferenceRelationship( (SofaTracerSpanContext) referencedContext, referenceType)); @@ -283,10 +280,10 @@ public Tracer.SpanBuilder withStartTimestamp(long microseconds) { public Span start() { SofaTracerSpanContext sofaTracerSpanContext = null; if (this.references != null && this.references.size() > 0) { - //存在父上下文 + //Parent context exist sofaTracerSpanContext = this.createChildContext(); } else { - //从新开始新的节点 + //Start with new root span context sofaTracerSpanContext = this.createRootSpanContext(); } @@ -311,7 +308,7 @@ private boolean calculateSampler(SofaTracerSpan sofaTracerSpan) { SamplingStatus samplingStatus = sampler.sample(sofaTracerSpan); if (samplingStatus.isSampled()) { isSampled = true; - //发生采样后,将相关属性记录 + //After the sampling occurs, the related attribute records this.tags.putAll(samplingStatus.getTags()); } } @@ -321,7 +318,7 @@ private boolean calculateSampler(SofaTracerSpan sofaTracerSpan) { } private SofaTracerSpanContext createRootSpanContext() { - //生成 traceId + //generate traceId String traceId = TraceIdGenerator.generate(); return new SofaTracerSpanContext(traceId, ROOT_SPAN_ID, StringUtils.EMPTY_STRING); } @@ -383,14 +380,8 @@ public static final class Builder { private final String tracerType; - /*** - * 作为客户端运行时的 Reporter - */ private Reporter clientReporter; - /*** - * 作为服务端运行时的 Reporter - */ private Reporter serverReporter; private Map tracerTags = new HashMap(); @@ -402,31 +393,16 @@ public Builder(String tracerType) { this.tracerType = tracerType; } - /*** - * 客户端日志功能 - * @param clientReporter 日志功能,落地到磁盘或者上报 zipkin - * @return Builder - */ public Builder withClientReporter(Reporter clientReporter) { this.clientReporter = clientReporter; return this; } - /*** - * 服务端日志功能 - * @param serverReporter 日志功能,落地到磁盘或者上报 zipkin - * @return Builder - */ public Builder withServerReporter(Reporter serverReporter) { this.serverReporter = serverReporter; return this; } - /*** - * 采样器入口 span 生效 - * @param sampler 采样器 - * @return Builder - */ public Builder withSampler(Sampler sampler) { this.sampler = sampler; return this; diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TraceAppender.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TraceAppender.java index ad82605d..9810b11a 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TraceAppender.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TraceAppender.java @@ -23,22 +23,23 @@ */ public interface TraceAppender { - /*** - * 刷新数据 + /** + * flush data * - * @throws IOException 操作异常 + * @throws IOException */ void flush() throws IOException; - /*** - * 添加要被输出的 log 文件 - * @param log 字符串 - * @throws IOException 操作异常 + /** + * Add the log file to be output + * + * @param log + * @throws IOException */ void append(String log) throws IOException; /** - * 清理日志 + * clean log */ void cleanup(); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java index d07bb598..80be8b77 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemon.java @@ -27,25 +27,29 @@ /** * TracerLogRootDaemon * - * 不从配置项目获取,直接从系统属性获取 + * Not obtained from the configuration project, obtained directly from the system properties * * @author yangguanchao * @since 2017/06/25 */ public class TracerLogRootDaemon { - /*** - * 是否添加 pid 到 log path + /** + * Whether to add pid to log path */ public static final String TRACER_APPEND_PID_TO_LOG_PATH_KEY = "tracer_append_pid_to_log_path"; - /*** - * 日志目录 + /** + * Log directory */ public static String LOG_FILE_DIR; /** - * 该编码由LANG或者-Dfile.encoding决定,因此如系统根据系统编码来决定日志编码, 请确保应用的启动脚本或者启动参数中不覆盖LANG或者-Dfile.encoding的参数。 一般来说国内的系统创建模板里,deploy/bin/templates/jbossctl.sh里有 - * LANG=zh_CN.GB18030,这样无论环境变量里LANG设置成何值,启动时都会被覆盖 + * The encoding is determined by LANG or -Dfile.encoding, + * so if the system determines the log encoding based on the system encoding, + * make sure that the application's startup script or startup parameters do not override the LANG or -Dfile.encoding parameters. + * Generally speaking, in the domestic system creation template, + * there is LANG=zh_CN.GB18030 in deploy/bin/templates/jbossctl.sh, + * so no matter what value LANG is set in the environment variable, it will be overwritten at startup. */ static public final Charset DEFAULT_CHARSET = Charset.defaultCharset(); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilder.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilder.java index 10c17685..bd4fbe1f 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilder.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilder.java @@ -21,8 +21,8 @@ /** * JsonStringBuilder *

- * 方便日志输出的字符串拼接工具 - * + * String splicing tool for convenient log output + *

* @author yangguanchao * @since 2018/05/14 */ diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/builder/XStringBuilder.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/builder/XStringBuilder.java index 4b149288..0c05c380 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/builder/XStringBuilder.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/builder/XStringBuilder.java @@ -23,16 +23,16 @@ /** * XStringBuilder *

- * 方便日志输出的字符串拼接工具 - * + * String splicing tool for convenient log output + *

* @author yangguanchao * @since 2017/06/25 */ public class XStringBuilder { - static public final int DEFAULT_BUFFER_SIZE = 256; - static public final char DEFAULT_SEPARATOR = ','; - static public final String DEFAULT_SEPARATOR_ESCAPE = "%2C"; + public static final int DEFAULT_BUFFER_SIZE = 256; + public static final char DEFAULT_SEPARATOR = ','; + public static final String DEFAULT_SEPARATOR_ESCAPE = "%2C"; public static final String AND_SEPARATOR = "&"; public static final String AND_SEPARATOR_ESCAPE = "%26"; public static final String EQUAL_SEPARATOR = "="; @@ -40,9 +40,9 @@ public class XStringBuilder { public static final String PERCENT = "%"; public static final String PERCENT_ESCAPE = "%25"; - static private char separator = DEFAULT_SEPARATOR; - static private String separatorStr = separator + ""; - static private String spearatorEscape = DEFAULT_SEPARATOR_ESCAPE; + private static char separator = DEFAULT_SEPARATOR; + private static String separatorStr = separator + ""; + private static String spearatorEscape = DEFAULT_SEPARATOR_ESCAPE; private StringBuilder sb; public XStringBuilder() { @@ -59,8 +59,8 @@ public XStringBuilder(int size, char separator) { } /** - * @param str 输入字符串 - * @return 当前实例 + * @param str Input string + * @return this */ public XStringBuilder append(String str) { sb.append(str == null ? StringUtils.EMPTY_STRING : str).append(separator); @@ -68,8 +68,8 @@ public XStringBuilder append(String str) { } /** - * @param str 输入字符串 - * @return 当前实例 + * @param str Input string + * @return this */ public XStringBuilder append(long str) { sb.append(str).append(separator); @@ -77,9 +77,9 @@ public XStringBuilder append(long str) { } /** - * @param str 输入字符串 - * @param separator 分隔符 - * @return 当前实例 + * @param str Input string + * @param separator + * @return this */ public XStringBuilder append(long str, String separator) { sb.append(str).append(separator); @@ -87,9 +87,9 @@ public XStringBuilder append(long str, String separator) { } /** - * @param str 输入字符串 - * @param separator 分隔符 - * @return 当前实例 + * @param str Input string + * @param separator + * @return this */ public XStringBuilder append(long str, char separator) { sb.append(str).append(separator); @@ -97,9 +97,9 @@ public XStringBuilder append(long str, char separator) { } /** - * @param str 输入字符串 - * @param separator 分隔符 - * @return 当前实例 + * @param str Input string + * @param separator + * @return this */ public XStringBuilder append(String str, String separator) { sb.append(str == null ? StringUtils.EMPTY_STRING : str).append(separator); @@ -107,8 +107,8 @@ public XStringBuilder append(String str, String separator) { } /** - * @param str 输入字符串 - * @return 当前实例 + * @param str Input string + * @return this */ public XStringBuilder append(int str) { sb.append(str).append(separator); @@ -116,8 +116,8 @@ public XStringBuilder append(int str) { } /** - * @param str 输入字符串 - * @return 当前实例 + * @param str Input string + * @return this */ public XStringBuilder append(char str) { sb.append(str).append(separator); @@ -125,8 +125,8 @@ public XStringBuilder append(char str) { } /** - * @param map 要添加的 map - * @return 当前实例 + * @param map map param + * @return this */ public XStringBuilder append(Map map) { this.appendEscape(StringUtils.mapToString(map)); @@ -134,8 +134,8 @@ public XStringBuilder append(Map map) { } /** - * @param str 输入的字符串 - * @return 当前实例 + * @param str Input string + * @return this */ public XStringBuilder appendEnd(int str) { sb.append(str).append(StringUtils.NEWLINE); @@ -143,8 +143,8 @@ public XStringBuilder appendEnd(int str) { } /** - * @param str 输入的字符串 - * @return 当前实例 + * @param str Input string + * @return this */ public XStringBuilder appendEnd(String str) { sb.append(str == null ? StringUtils.EMPTY_STRING : str).append(StringUtils.NEWLINE); @@ -152,8 +152,8 @@ public XStringBuilder appendEnd(String str) { } /** - * @param str 输入信息 - * @return 当前实例 + * @param str Input string + * @return this */ public XStringBuilder appendEnd(long str) { sb.append(str).append(StringUtils.NEWLINE); @@ -161,8 +161,8 @@ public XStringBuilder appendEnd(long str) { } /** - * @param c 输入字符 - * @return 当前实例 + * @param c Input char + * @return this */ public XStringBuilder appendEnd(char c) { sb.append(String.valueOf(c)).append(StringUtils.NEWLINE); @@ -170,8 +170,8 @@ public XStringBuilder appendEnd(char c) { } /** - * @param map 输入 map - * @return 当前实例 + * @param map map param + * @return this */ public XStringBuilder appendEnd(Map map) { this.appendEscapeEnd(StringUtils.mapToString(map)); @@ -179,8 +179,8 @@ public XStringBuilder appendEnd(Map map) { } /** - * @param str 输入字符串 - * @return 当前实例 + * @param str Input string + * @return this */ public XStringBuilder appendRaw(String str) { sb.append(str == null ? StringUtils.EMPTY_STRING : str); @@ -188,9 +188,9 @@ public XStringBuilder appendRaw(String str) { } /** - * 将字符串中分隔符变成对应转义字符 - * @param str 输入字符串 - * @return 当前实例 + * Change the separator in the string to the corresponding escape character + * @param str Input string + * @return this */ public XStringBuilder appendEscape(String str) { str = (str == null) ? StringUtils.EMPTY_STRING : str; @@ -199,9 +199,9 @@ public XStringBuilder appendEscape(String str) { } /** - * 将字符串中分隔符变成对应转义字符 - * @param str 输入字符串 - * @return 当前实例 + * Change the separator in the string to the corresponding escape character on raw + * @param str Input string + * @return this */ public XStringBuilder appendEscapeRaw(String str) { str = (str == null) ? StringUtils.EMPTY_STRING : str; @@ -210,9 +210,9 @@ public XStringBuilder appendEscapeRaw(String str) { } /** - * 将字符串中分隔符变成对应转义字符 - * @param str 输入字符串 - * @return 当前实例 + * Change the separator in the string to the corresponding escape character at the end + * @param str Input string + * @return this */ public XStringBuilder appendEscapeEnd(String str) { str = (str == null) ? StringUtils.EMPTY_STRING : str; @@ -221,7 +221,7 @@ public XStringBuilder appendEscapeEnd(String str) { } /** - * @return 当前实例 + * @return this */ public XStringBuilder reset() { sb.delete(0, sb.length()); @@ -229,7 +229,7 @@ public XStringBuilder reset() { } /** - * @return 当前实例 + * @return this */ @Override public String toString() { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/encoder/SpanEncoder.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/encoder/SpanEncoder.java index 2a00ac11..e23efebc 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/encoder/SpanEncoder.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/encoder/SpanEncoder.java @@ -23,19 +23,19 @@ /** * SpanEncoder *

- * Tracer 日志格式编码,为针对异步队列调用做优化,不允许多线程并发调用 - * + * Tracer Span log encoder, optimized for asynchronous queue calls, does not allow multi-threaded concurrent calls + *

* @author yangguanchao * @since 2017/06/25 */ public interface SpanEncoder { - /*** - * 对 span 按照自定义的规则分隔字段,并准备输出到文件中 + /** + * Separate fields according to custom rules and prepare to output to file * - * @param span 要被格式化输出的上下文 - * @throws IOException 文件输出异常 - * @return 返回格式化输出的字符串 + * @param span current span + * @throws IOException + * @return formatted output string */ String encode(T span) throws IOException; } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/AbstractRollingFileAppender.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/AbstractRollingFileAppender.java index 2addacfb..361fed3b 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/AbstractRollingFileAppender.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/AbstractRollingFileAppender.java @@ -33,17 +33,17 @@ public abstract class AbstractRollingFileAppender implements TraceAppender { /** - * 日志刷新间隔,buffer 时间超过间隔,则把缓存的日志数据刷新出去 + * The log refresh interval, when the buffer time exceeds the interval, the cached log data is refreshed. */ private static final long LOG_FLUSH_INTERVAL = TimeUnit.SECONDS.toMillis(1); /** - * 默认输出缓冲大小 + * Default output buffer size 8KB */ - public static final int DEFAULT_BUFFER_SIZE = 8 * 1024; // 8KB + public static final int DEFAULT_BUFFER_SIZE = 8 * 1024; private static final long IOEXCEPTION_PRINT_INTERVAL = 60 * 1000; /** - * 日志缓存大小 + * Log cache buffer size */ private final int bufferSize; @@ -96,6 +96,7 @@ protected void setFile(boolean append) { } } + @Override public void append(String log) throws IOException { if (bos != null) { waitUntilRollFinish(); @@ -107,29 +108,30 @@ public void append(String log) throws IOException { isRolling.set(false); } } else { - // 超过指定刷新时间没刷新,就刷新一次 + // Refreshed after the specified refresh time has not been refreshed long now; if ((now = System.currentTimeMillis()) >= nextFlushTime) { flush(); nextFlushTime = now + LOG_FLUSH_INTERVAL; } } - // 无论有没有做 RollOver,都需要将输入往 bos 中写入 + // Whether you have RollOver or not, you need to write the input to bos byte[] bytes = log.getBytes(TracerLogRootDaemon.DEFAULT_CHARSET); write(bytes); } } /** - * 是否现在马上进行滚动 - * - * @return true: 是 + * Whether to scroll right now + * @return true */ protected abstract boolean shouldRollOverNow(); /** - * 进行 RollOver - * WARNING:RollOver 的时候日志不要用 SelfLog 打印,因为这个时候可能 SelfLog 自己在 RollOver。 + * Ready to RollOver + * + * WARNING:Do not use SelfLog when logging RollOver, + * because this time it is possible that SelfLog is in RollOver itself. */ protected abstract void rollOver(); @@ -146,8 +148,9 @@ private void write(byte[] bytes) { } /** - * 超过指定刷新时间没刷新,就刷新一次 + * Refreshed after the specified refresh time has not been refreshed */ + @Override public void flush() { if (bos != null) { try { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/CompositeTraceAppender.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/CompositeTraceAppender.java index 0ac016ba..6368cb1f 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/CompositeTraceAppender.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/CompositeTraceAppender.java @@ -33,23 +33,26 @@ public class CompositeTraceAppender implements TraceAppender { private Map traceAppenders = new ConcurrentHashMap(); /** - * @param logName 日志名 - * @return 输出实例 + * getAppender by logName + * @param logName logName + * @return traceAppender */ public TraceAppender getAppender(String logName) { return traceAppenders.get(logName); } /** - * @param logName 日志名 - * @param traceAppender 输出实例 + * putAppender + * @param logName logName + * @param traceAppender traceAppender */ public void putAppender(String logName, TraceAppender traceAppender) { traceAppenders.put(logName, traceAppender); } /** - * @throws IOException 异常 + * Traverse traceAppenders, callback flush method in turn + * @throws IOException */ @Override public void flush() throws IOException { @@ -59,8 +62,8 @@ public void flush() throws IOException { } /** - * @param log 内容 - * @throws IOException 异常 + * @param log + * @throws IOException */ @Override public void append(String log) throws IOException { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/LoadTestAwareAppender.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/LoadTestAwareAppender.java index 609d57bd..146e3e75 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/LoadTestAwareAppender.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/LoadTestAwareAppender.java @@ -29,9 +29,9 @@ */ public final class LoadTestAwareAppender implements TraceAppender { - // 非压测数据的 TraceAppender + /** TraceAppender for non-pressure */ private TraceAppender nonLoadTestTraceAppender; - // 压测数据的 TraceAppender + /** TraceAppender for pressure*/ private TraceAppender loadTestTraceAppender; private LoadTestAwareAppender(TraceAppender nonLoadTestTraceAppender, diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppender.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppender.java index b8a87c12..869a5476 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppender.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppender.java @@ -24,22 +24,26 @@ import com.alipay.common.tracer.core.utils.TracerUtils; import java.io.File; -import java.io.FilenameFilter; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; /** - * 基于时间的 RollingFileAppender + * RollingFileAppender based on Time * * @author khotyn 4/8/14 2:56 PM */ public class TimedRollingFileAppender extends AbstractRollingFileAppender { - // The code assumes that the following constants are in a increasing sequence. + /** + * The code assumes that the following constants are in a increasing sequence. + */ static final int TOP_OF_TROUBLE = -1; - static final int TOP_OF_SECONDS = 0; // 添加秒级的滚动主要是为了测试方便 + /** + * Adding seconds of scrolling is mainly for testing convenience + */ + static final int TOP_OF_SECONDS = 0; static final int TOP_OF_MINUTE = 1; static final int TOP_OF_HOUR = 2; static final int HALF_DAY = 3; @@ -54,47 +58,39 @@ public class TimedRollingFileAppender extends AbstractRollingFileAppender { private static final String DEFAULT_ROLLING_PATTERN = DAILY_ROLLING_PATTERN; /** - * 下次日志 RollOver 的时候,日志文件会被重命名成这个文件。 + * The next time you log RollOver, the log file will be renamed to this file. */ private String scheduledFilename; /** - * 预计下次 RollOver 发生的时间 + * Expect the time of the next RollOver */ private long nextCheck = System.currentTimeMillis() - 1; /** - * 备份的文件的后缀模式 + * Suffix mode of the backed up file */ private String datePattern; /** - * 日期格式化,主要用于格式化文件名用 + * Date formatting, mainly used to format file names */ private SimpleDateFormat sdf; private Date now = new Date(); /** - * 此 Calender 主要用于计算下一次 RollOver 发生的时间 + * This Calender is mainly used to calculate the time when the next RollOver occurs. */ private RollingCalendar rc = new RollingCalendar(); /** - * 日志的保留时间 + * Log retention time */ private LogReserveConfig logReserveConfig = new LogReserveConfig( SofaTracerConfiguration.DEFAULT_LOG_RESERVE_DAY, 0); - /** - * @param file 文件名 - * @param append 是否累加 - */ public TimedRollingFileAppender(String file, boolean append) { this(file, DEFAULT_BUFFER_SIZE, append, DEFAULT_ROLLING_PATTERN); } - /** - * @param file 文件 - * @param datePattern 日期格式 - */ public TimedRollingFileAppender(String file, String datePattern) { this(file, DEFAULT_BUFFER_SIZE, true, datePattern); } @@ -104,20 +100,15 @@ public TimedRollingFileAppender(String file, String datePattern, String logReser this.logReserveConfig = TracerUtils.parseLogReserveConfig(logReserveConfigString); } - /** - * @param file 文件 - * @param bufferSize 缓冲区大小 - * @param append 是否追加,默认是 - */ public TimedRollingFileAppender(String file, int bufferSize, boolean append) { this(file, bufferSize, append, DEFAULT_ROLLING_PATTERN); } /** - * @param file 文件 - * @param bufferSize 缓冲区大小 - * @param append 是否追加,默认是 - * @param datePatternParam 日期格式 + * @param file fileName + * @param bufferSize bufferSize + * @param append default is true + * @param datePatternParam date format */ public TimedRollingFileAppender(String file, int bufferSize, boolean append, String datePatternParam) { @@ -134,10 +125,10 @@ public TimedRollingFileAppender(String file, int bufferSize, boolean append, } /** - * 判断是否应该现在进行 RollOver - * - * @return true 现在进行 RollOver + * Determine if RollOver should be done now + * @return true:Now RollOver */ + @Override public boolean shouldRollOverNow() { long n = System.currentTimeMillis(); if (n >= nextCheck) { @@ -150,8 +141,9 @@ public boolean shouldRollOverNow() { } /** - * 清理日志 + * clean log */ + @Override public void cleanup() { try { File parentDirectory = logFile.getParentFile(); @@ -166,12 +158,8 @@ public void cleanup() { return; } - File[] logFiles = parentDirectory.listFiles(new FilenameFilter() { - - public boolean accept(File dir, String name) { - return StringUtils.isNotBlank(name) && name.startsWith(baseName); - } - }); + File[] logFiles = parentDirectory.listFiles((dir,name)-> + StringUtils.isNotBlank(name) && name.startsWith(baseName)); if (logFiles == null || logFiles.length == 0) { return; @@ -248,13 +236,11 @@ public boolean accept(File dir, String name) { } } - /** - * - */ + @Override public void rollOver() { - /* Compute filename, but only if datePattern is specified */ + // Compute filename, but only if datePattern is specified if (datePattern == null) { - SelfLog.error("没有设置文件滚动的后缀名模式"); + SelfLog.error("No Settings for file rolling suffix's model"); return; } @@ -269,7 +255,7 @@ public void rollOver() { try { bos.close(); } catch (IOException e) { - SelfLog.error("关闭输出流失败", e); + SelfLog.error("Failed to closing the output stream", e); } File target = new File(scheduledFilename); @@ -279,10 +265,9 @@ public void rollOver() { boolean result = logFile.renameTo(target); if (result) { - System.out.println(fileName + " -> " + scheduledFilename); + SelfLog.info(fileName + " -> " + scheduledFilename); } else { - System.err.println("Failed to rename [" + fileName + "] to [" + scheduledFilename - + "]."); + SelfLog.error("Failed to rename [" + fileName + "] to [" + scheduledFilename + "]."); } this.setFile(false); @@ -305,7 +290,8 @@ int computeCheckPeriod() { if (datePattern != null) { for (int i = TOP_OF_SECONDS; i <= TOP_OF_MONTH; i++) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern); - simpleDateFormat.setTimeZone(gmtTimeZone); // do all date formatting in GMT + // do all date formatting in GMT + simpleDateFormat.setTimeZone(gmtTimeZone); String r0 = simpleDateFormat.format(epoch); rollingCalendar.setType(i); Date next = new Date(rollingCalendar.getNextCheckMillis(epoch)); @@ -315,7 +301,8 @@ int computeCheckPeriod() { } } } - return TOP_OF_TROUBLE; // Deliberately head for trouble... + // Deliberately head for trouble... + return TOP_OF_TROUBLE; } } @@ -342,16 +329,16 @@ void setType(int type) { } /** - * @param now 日期 - * @return 下一个整数日期 + * @param now + * @return Next Date */ public long getNextCheckMillis(Date now) { return getNextCheckDate(now).getTime(); } /** - * @param now 当前 - * @return 下一个周期日周期 + * @param now + * @return Next cycle day */ public Date getNextCheckDate(Date now) { this.setTime(now); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonAppenderManager.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonAppenderManager.java index 37e51c63..f337fde8 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonAppenderManager.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonAppenderManager.java @@ -33,9 +33,9 @@ import java.util.concurrent.atomic.AtomicLong; /** - * SelfLog专用 + * For SelfLog * @author luoguimu123 - * @version $Id: AsyncCommonAppenderManager.java, v 0.1 2017年11月21日 下午6:15 luoguimu123 Exp $ + * @version $Id: AsyncCommonAppenderManager.java, v 0.1 November 21, 2017 6:15 PM luoguimu123 Exp $ */ public class AsyncCommonAppenderManager { @@ -47,7 +47,7 @@ public class AsyncCommonAppenderManager { private List consumers; - // SelfLog 专用,不用开启三个 Consumer + /** Dedicated for SelfLog, no need to open three Consumers */ private static final int DEFAULT_CONSUMER_NUMBER = 1; private boolean allowDiscard; @@ -160,15 +160,13 @@ private class Consumer implements EventHandler { @Override public void onEvent(StringEvent event, long sequence, boolean endOfBatch) throws Exception { - String string = event.getString(); - if (string != null) { try { appender.append(string); appender.flush(); } catch (Exception e) { - //todo 全局保留一个同步的log,用于在一些关键点同步打印日志 + //todo Globally keep a synchronized log for synchronizing print logs at some key points if (string != null) { SynchronizingSelfLog.error("fail to async write log", e); } else { @@ -184,7 +182,6 @@ public void onEvent(StringEvent event, long sequence, boolean endOfBatch) throws } class PaddedAtomicLong extends AtomicLong { - public volatile long p1, p2, p3, p4, p5, p6 = 7L; public PaddedAtomicLong(long initialValue) { @@ -194,5 +191,4 @@ public PaddedAtomicLong(long initialValue) { public PaddedAtomicLong() { } } - } \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonDigestAppenderManager.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonDigestAppenderManager.java index 460208f8..7aaaa468 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonDigestAppenderManager.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/AsyncCommonDigestAppenderManager.java @@ -44,7 +44,7 @@ /** * * @author liangen - * @version $Id: AsyncCommonDigestAppenderManager.java, v 0.1 2017年10月23日 上午9:47 liangen Exp $ + * @version $Id: AsyncCommonDigestAppenderManager.java, v 0.1 October 23, 2017 9:47 AM liangen Exp $ */ public class AsyncCommonDigestAppenderManager { private final Map appenders = new ConcurrentHashMap(); @@ -233,7 +233,6 @@ public void addLogType(String logType) { } class PaddedAtomicLong extends AtomicLong { - public volatile long p1, p2, p3, p4, p5, p6 = 7L; public PaddedAtomicLong(long initialValue) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ConsumerExceptionHandler.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ConsumerExceptionHandler.java index cb631ea1..2b554ea1 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ConsumerExceptionHandler.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ConsumerExceptionHandler.java @@ -23,7 +23,7 @@ /** * * @author liangen - * @version $Id: ConsumerExceptionHandler.java, v 0.1 2017年10月23日 上午10:13 liangen Exp $ + * @version $Id: ConsumerExceptionHandler.java, v 0.1 October 23, 2017 10:13 AM liangen Exp $ */ public class ConsumerExceptionHandler implements ExceptionHandler { @Override diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ConsumerThreadFactory.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ConsumerThreadFactory.java index 8249fad9..110052c4 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ConsumerThreadFactory.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/ConsumerThreadFactory.java @@ -21,7 +21,7 @@ /** * * @author liangen - * @version $Id: ConsumerThreadFactory.java, v 0.1 2017年10月23日 上午10:09 liangen Exp $ + * @version $Id: ConsumerThreadFactory.java, v 0.1 October 23, 2017 10:09 AM liangen Exp $ */ public class ConsumerThreadFactory implements ThreadFactory { private String workName; diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/SofaTracerSpanEventFactory.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/SofaTracerSpanEventFactory.java index 6250b13c..85b5db9a 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/SofaTracerSpanEventFactory.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/SofaTracerSpanEventFactory.java @@ -21,7 +21,7 @@ /** * * @author liangen - * @version $Id: SofaTracerSpanEventFactory.java, v 0.1 2017年10月23日 上午10:07 liangen Exp $ + * @version $Id: SofaTracerSpanEventFactory.java, v 0.1 October 23, 2017 10:07 AM liangen Exp $ */ public class SofaTracerSpanEventFactory implements EventFactory { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringConsumerExceptionHandler.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringConsumerExceptionHandler.java index 192764db..2a31caf6 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringConsumerExceptionHandler.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringConsumerExceptionHandler.java @@ -22,12 +22,12 @@ /** * * @author luoguimu123 - * @version $Id: StringConsumerExceptionHandler.java, v 0.1 2017年11月21日 下午7:06 luoguimu123 Exp $ + * @version $Id: StringConsumerExceptionHandler.java, v 0.1 November 21, 2017 7:06 PM luoguimu123 Exp $ */ public class StringConsumerExceptionHandler implements ExceptionHandler { @Override public void handleEventException(Throwable ex, long sequence, StringEvent event) { - //循环调用 + //Loop call if (event != null) { SynchronizingSelfLog.error( "AsyncConsumer occurs exception during handle StringEvent, The string is[" diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEvent.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEvent.java index d47365b0..f5fb8b0f 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEvent.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEvent.java @@ -19,7 +19,7 @@ /** * * @author luoguimu123 - * @version $Id: StringEvent.java, v 0.1 2017年11月21日 下午7:01 luoguimu123 Exp $ + * @version $Id: StringEvent.java, v 0.1 November 21, 2017 7:01 PM luoguimu123 Exp $ */ public class StringEvent { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEventFactory.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEventFactory.java index 3f8dab85..67026f56 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEventFactory.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/manager/StringEventFactory.java @@ -21,7 +21,7 @@ /** * * @author luoguimu123 - * @version $Id: StringEventFactory.java, v 0.1 2017年11月21日 下午7:00 luoguimu123 Exp $ + * @version $Id: StringEventFactory.java, v 0.1 November 21, 2017 7:00 PM luoguimu123 Exp $ */ public class StringEventFactory implements EventFactory { @Override diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SelfLog.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SelfLog.java index dc4d5a1c..592facc8 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SelfLog.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SelfLog.java @@ -24,8 +24,7 @@ import java.io.StringWriter; /** - * tracer自己的日志,仅供内部试用 - * + * Tracer's own log, for internal use only * @author yangyanzhao */ public class SelfLog { @@ -34,8 +33,8 @@ public class SelfLog { static private final String WARN_PREFIX = "[WARN] "; static private final String INFO_PREFIX = "[INFO] "; - /*** - * 日志文件名称 + /** + * Log file name */ static protected final String SELF_LOG_FILE = "tracer-self.log"; @@ -47,8 +46,8 @@ public class SelfLog { } /** - * @param log 日志内容 - * @param e 异常 + * @param log + * @param e */ public static void error(String log, Throwable e) { try { @@ -66,10 +65,10 @@ public static void error(String log, Throwable e) { } /** - * 打印错误日志,附加当前线程的 TraceId + * Print error log with current thread's TraceId * - * @param log 错误信息 - * @param e 异常 + * @param log + * @param e */ public static void errorWithTraceId(String log, Throwable e) { try { @@ -92,9 +91,9 @@ public static void error(String log) { } /** - * 打印错误日志,附加当前线程的 TraceId + * Print error log with current thread's TraceId * - * @param log 错误消息 + * @param log * @param traceId traceId */ public static void errorWithTraceId(String log, String traceId) { @@ -102,9 +101,9 @@ public static void errorWithTraceId(String log, String traceId) { } /** - * 打印错误日志,附加当前线程的 TraceId + * Print error log with current thread's TraceId * - * @param log 错误消息 + * @param log */ public static void errorWithTraceId(String log) { doLog(log, ERROR_PREFIX + "[" + TracerUtils.getTraceId() + "]"); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SynchronizingSelfLog.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SynchronizingSelfLog.java index 662b2d9b..9b249b34 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SynchronizingSelfLog.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SynchronizingSelfLog.java @@ -26,9 +26,12 @@ import java.io.StringWriter; /** - * 同步打印的SelfLog,仅在中间件内部使用,解决SelfLog异步化后,在一些Mananger初始化时打印日志时使用 + * + * Self-synchronized SelfLog, used only in the middleware, + * after Solving SelfLog asynchronous, it is used when printing logs in some Manager initialization + * * @author luoguimu123 - * @version $Id: SynchronizingSelfLog.java, v 0.1 2017年11月21日 下午7:45 luoguimu123 Exp $ + * @version $Id: SynchronizingSelfLog.java, v 0.1 November 21, 2017 7:45 PM luoguimu123 Exp $ */ public class SynchronizingSelfLog { @@ -36,8 +39,8 @@ public class SynchronizingSelfLog { static private final String WARN_PREFIX = "[WARN] "; static private final String INFO_PREFIX = "[INFO] "; - /*** - * 日志文件名称 + /** + * Log file name */ static protected final String SELF_LOG_FILE = "sync.log"; @@ -60,8 +63,8 @@ public class SynchronizingSelfLog { } /** - * @param log 日志 - * @param e 异常 + * @param log + * @param e */ public static void error(String log, Throwable e) { try { @@ -80,10 +83,10 @@ public static void error(String log, Throwable e) { } /** - * 打印错误日志,附加当前线程的 TraceId + * Print error log with current thread's TraceId * - * @param log 错误信息 - * @param e 异常 + * @param log + * @param e */ public static void errorWithTraceId(String log, Throwable e) { try { @@ -107,9 +110,9 @@ public static void error(String log) { } /** - * 打印错误日志,附加当前线程的 TraceId + * Print error log with current thread's TraceId * - * @param log 错误消息 + * @param log * @param traceId traceId */ public static void errorWithTraceId(String log, String traceId) { @@ -117,9 +120,9 @@ public static void errorWithTraceId(String log, String traceId) { } /** - * 打印错误日志,附加当前线程的 TraceId + * Print error log with current thread's TraceId * - * @param log 错误消息 + * @param log */ public static void errorWithTraceId(String log) { doLog(log, ERROR_PREFIX + "[" + TracerUtils.getTraceId() + "]"); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/TracerDaemon.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/TracerDaemon.java index a8032eca..a9bc2777 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/TracerDaemon.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/TracerDaemon.java @@ -24,9 +24,9 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * Tracer 的 Daemon 线程,主要是做清理日志的事情 + * Tracer's Daemon thread, mainly to do the cleanup log * - * @author khotyn 15/2/16 下午4:32 + * @author khotyn 15/2/16 PM 4:32 */ public class TracerDaemon implements Runnable { @@ -36,15 +36,16 @@ public class TracerDaemon implements Runnable { private static long scanInterval = ONE_HOUR; /** - * 注册被监听的 Appender + * Register the Appender being monitored * - * @param traceAppender 输出实现 + * @param traceAppender */ public static void watch(TraceAppender traceAppender) { watchedAppenders.add(traceAppender); } @SuppressWarnings("InfiniteLoopStatement") + @Override public void run() { while (true) { try { @@ -60,9 +61,9 @@ public void run() { } /** - * 为了测试方便,调整 Daemon 线程的扫描周期 + * Adjust the scanning cycle of the Daemon thread for testing convenience * - * @param scanInterval 扫描周期,单位为秒 + * @param scanInterval Scan period in seconds */ public static void setScanInterval(long scanInterval) { TracerDaemon.scanInterval = scanInterval; diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerCallable.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerCallable.java index 05fd97d0..e04a8fde 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerCallable.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerCallable.java @@ -26,8 +26,9 @@ /** * Callable that passes Span between threads. The Span name is * taken either from the passed value or from the interface. + * * @author luoguimu123 - * @version $Id: Callable.java, v 0.1 2017年06月19日 下午5:52 luoguimu123 Exp $ + * @version $Id: Callable.java, v 0.1 June 19, 2017 5:52 PM luoguimu123 Exp $ */ public class SofaTracerCallable implements Callable { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerRunnable.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerRunnable.java index 6a75fdfb..6dbb71a7 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerRunnable.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/SofaTracerRunnable.java @@ -25,8 +25,9 @@ /** * Runnable that passes Span between threads. The Span name is * taken either from the passed value or from the interface. + * * @author luoguimu123 - * @version $Id: Runnable.java, v 0.1 2017年06月19日 下午5:54 luoguimu123 Exp $ + * @version $Id: Runnable.java, v 0.1 June 19, 2017 5:54 PM luoguimu123 Exp $ */ public class SofaTracerRunnable implements Runnable { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorService.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorService.java index 9afbb4f3..655f7259 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorService.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorService.java @@ -25,9 +25,10 @@ import java.util.concurrent.TimeUnit; /** - * 扩展的定时可有trace信息的定时线程池 + * Extended timing thread pool for SOFATracer + * * @author luoguimu123 - * @version $Id: TracerScheduleExecutorService.java, v 0.1 2017年06月22日 上午11:43 luoguimu123 Exp $ + * @version $Id: TracerScheduleExecutorService.java, v 0.1 June 22, 2017 11:43 AM luoguimu123 Exp $ */ public class TracerScheduleExecutorService extends TracedExecutorService implements ScheduledExecutorService { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerConfiguration.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerConfiguration.java index ef3b6ba2..9e958886 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerConfiguration.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerConfiguration.java @@ -31,77 +31,78 @@ /** * * @author luoguimu123 - * @version $Id: SofaTracerConfiguration.java, v 0.1 2017年06月22日 下午3:12 luoguimu123 Exp $ + * @version $Id: SofaTracerConfiguration.java, v 0.1 June 22, 2017 3:12 PM luoguimu123 Exp $ */ public class SofaTracerConfiguration { /** - * 是否开启中间件的 Digest 日志,关闭这个开关将会关闭所有的中间件的 Digest 日志 + * Whether to open the Digest log of the middleware, closing this switch will close the Digest log of all middleware. */ public static final String DISABLE_MIDDLEWARE_DIGEST_LOG_KEY = "disable_middleware_digest_log"; /** - * key=是否开启特定的中间件 Digest 日志开关,value=map[日志类型为key:value(开关)] + * com.alipay.sofa.tracer.disableConfiguration[logType]=true */ public final static String DISABLE_DIGEST_LOG_KEY = "disable_digest_log"; /** - * Tracer 的全局的 Rolling 的配置的 Key + * Tracer's Global Rolling configured Key */ public final static String TRACER_GLOBAL_ROLLING_KEY = "tracer_global_rolling_policy"; /** - * Tracer 的全局的日志的保留天数配置的 Key + * Tracer's global log retention days configured Key */ public final static String TRACER_GLOBAL_LOG_RESERVE_DAY = "tracer_global_log_reserve_day"; - /*** - * 默认日志的保留天数 + /** + * Default log retention days */ public static final int DEFAULT_LOG_RESERVE_DAY = 7; /** - * 阈值,业务透传字段的限制长度 + * Threshold, the length of the service transparent field */ public final static int PEN_ATTRS_LENGTH_TRESHOLD = 1024; /** - * Tracer 的穿透数据的最大值的配置的 Key + * The configuration of the maximum value of the tracer's penetration data */ public static final String TRACER_PENETRATE_ATTRIBUTE_MAX_LENGTH = "tracer_penetrate_attribute_max_length"; /** - * Tracer 系统穿透数据的最大值的配置的 Key + * The configuration key of the maximum value of the Tracer system penetration data */ public static final String TRACER_SYSTEM_PENETRATE_ATTRIBUTE_MAX_LENGTH = "tracer_system_penetrate_attribute_max_length"; /** - * 统计日志的打印的间隔,加入这个选项主要是为了可测试性的考虑,系统属性关键字 + * The interval for printing the stat log. + * This option is mainly for testability considerations. System attribute keywords. */ public static final String STAT_LOG_INTERVAL = "stat_log_interval"; - /*****************异步队列配置项 start***************/ + /***************** Asynchronous queue configuration item start ***************/ /** - * 是否允许丢失日志 + * Whether to allow lost logs */ public static final String TRACER_ASYNC_APPENDER_ALLOW_DISCARD = "tracer_async_appender_allow_discard"; /** - * 是否日志输出丢失日志的数量 + * Whether the log output loses the number of logs */ public static final String TRACER_ASYNC_APPENDER_IS_OUT_DISCARD_NUMBER = "tracer_async_appender_is_out_discard_number"; /** - * 是否日志输出丢失日志的TraceId和RpcId + * Whether the log output loses the trace of the TraceId and RpcId */ public static final String TRACER_ASYNC_APPENDER_IS_OUT_DISCARD_ID = "tracer_async_appender_is_out_discard_id"; /** - * 丢失日志的数量达到该阈值进行一次日志输出 + * The number of lost logs reaches this threshold for a log output */ public static final String TRACER_ASYNC_APPENDER_DISCARD_OUT_THRESHOLD = "tracer_async_appender_discard_out_threshold"; - /*****************异步队列配置项 end***************/ + /***************** Asynchronous queue configuration item end ***************/ /** - * 应用名称 + * app name */ public static final String TRACER_APPNAME_KEY = "spring.application.name"; @@ -111,13 +112,11 @@ public class SofaTracerConfiguration { private static SofaTracerExternalConfiguration sofaTracerExternalConfiguration = null; - /***************** 采样配置项 end ***************/ - - /** 采样策略名称key */ + /** The key of Sampling policy name */ public static final String SAMPLER_STRATEGY_NAME_KEY = "tracer_sampler_strategy_name_key"; - /** 自定义采样规则类名 */ + /** Custom sampling rule class name */ public static final String SAMPLER_STRATEGY_CUSTOM_RULE_CLASS_NAME = "tracer_sampler_strategy_custom_rule_class_name"; - /** 采样率key */ + /** The key of Sampling rate */ public static final String SAMPLER_STRATEGY_PERCENTAGE_KEY = "tracer_sampler_strategy_percentage_key"; static { @@ -132,41 +131,43 @@ public class SofaTracerConfiguration { } catch (Exception e) { SelfLog.info("sofa.tracer.properties文件不存在"); } - //静态统计信息 + //Static statistics StaticInfoLog.logStaticInfo(); } /** - * 设置配置项 + * Setting configuration item for String type value * - * @param key 配置项 key - * @param value 配置项的值 + * @param key configuration item key + * @param value configuration item value */ public static void setProperty(String key, String value) { properties.put(key, value); } /** - * @param key 关键字 - * @param value 值 + * Setting configuration item for Integer type value + * @param key configuration item key + * @param value configuration item value */ public static void setProperty(String key, Integer value) { properties.put(key, value); } /** - * @param key 关键字 - * @param value 值 + * Setting configuration item for Map type value + * @param key configuration item key + * @param value configuration item value */ public static void setProperty(String key, Map value) { properties.put(key, value); } /** - * 获取配置项 + * get property by key * - * @param key 配置项的 key - * @return 属性值 + * @param key configuration item key + * @return */ public static String getProperty(String key) { return getProperty(key, StringUtils.EMPTY_STRING); @@ -186,9 +187,10 @@ public static Integer getInteger(String key) { } /** - * @param key 关键字 - * @param defaultValue 默认值 - * @return 整数 + * get property with default value + * @param key key + * @param defaultValue default value + * @return Integer */ public static Integer getIntegerDefaultIfNull(String key, Integer defaultValue) { Integer value = getInteger(key); @@ -196,7 +198,8 @@ public static Integer getIntegerDefaultIfNull(String key, Integer defaultValue) } /** - * @param key 关键字 + * get property + * @param key key * @return map */ public static Map getMapEmptyIfNull(String key) { @@ -213,11 +216,11 @@ public static Map getMapEmptyIfNull(String key) { } /** - * 获取配置项 + * get property * - * @param key 配置项的 key - * @param defaultValue 如果获取出得配置项是 null,则返回 defaultValue - * @return 配置值或者默认值 + * @param key key + * @param defaultValue defaultValue + * @return defaultValue if value is not null */ public static String getProperty(String key, String defaultValue) { if (properties.containsKey(key)) { @@ -229,7 +232,8 @@ public static String getProperty(String key, String defaultValue) { if (fileProperties.containsKey(key)) { return (String) fileProperties.get(key); } - //最后判断外部注入的配置中是否存在该key对应的配置值 + // Finally, it is determined whether the configuration value corresponding to + // the key exists in the externally injected configuration. if (sofaTracerExternalConfiguration != null && sofaTracerExternalConfiguration.contains(key)) { return sofaTracerExternalConfiguration.getValue(key); @@ -238,10 +242,10 @@ public static String getProperty(String key, String defaultValue) { } /** - * 获取某一个日志的 Rolling 策略 + * Get a Rolling policy for a log * - * @param rollingKey 滚动策略名称 - * @return 某一个日志的 Rolling 策略,默认的策略是 + * @param rollingKey rollingKey + * @return The Rolling policy of a log, the default policy is * {@link TimedRollingFileAppender#DAILY_ROLLING_PATTERN} */ public static String getRollingPolicy(String rollingKey) { @@ -256,10 +260,10 @@ public static String getRollingPolicy(String rollingKey) { : rollingPolicy; } - /*** - * 获取日志保留天数 - * @param logReserveKey 日志保留天数关键字,跟进此获取具体的保留值 - * @return 此关键字对应的日志保留天数 + /** + * Get log retention days + * @param logReserveKey The key of Log retention days + * @return */ public static String getLogReserveConfig(String logReserveKey) { if (StringUtils.isBlank(logReserveKey)) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerExternalConfiguration.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerExternalConfiguration.java index 33ff49a1..54d8cb88 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerExternalConfiguration.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/configuration/SofaTracerExternalConfiguration.java @@ -17,14 +17,24 @@ package com.alipay.common.tracer.core.configuration; /** - * 外部配置类的接口,该接口由外部代码实现 + * The interface of the external configuration class, which is implemented by external code * @author luoguimu123 - * @version $Id: SofaTracerExternalConfiguration.java, v 0.1 2017年10月11日 下午12:03 luoguimu123 Exp $ + * @version $Id: SofaTracerExternalConfiguration.java, v 0.1 October 11, 2017 12:03 PM luoguimu123 Exp $ */ public interface SofaTracerExternalConfiguration { + /** + * get value by input key + * @param key + * @return + */ String getValue(String key); + /** + * Whether the specified key exists + * @param key + * @return + */ boolean contains(String key); } \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/constants/SofaTracerConstant.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/constants/SofaTracerConstant.java index 7625fa6f..0c66680a 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/constants/SofaTracerConstant.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/constants/SofaTracerConstant.java @@ -47,46 +47,42 @@ public class SofaTracerConstant { //******************* span encoder constant start ***************** /** - * 耗时单位 + * Time-consuming unit */ public static final String MS = "ms"; - /*** - * 字节单位 + /** + * Byte unit */ public static final String BYTE = "B"; /** - * Tracer 上下文嵌套的最大深度 + * Maximum depth of the Tracer context nesting */ public static final int MAX_LAYER = 100; //******************* span encoder constant end ***************** //******************* exception constant start ***************** - - /*** - * 业务异常 + /** + * Business exception */ public static final String BIZ_ERROR = "biz_error"; //******************* exception constant end ***************** - /*** - * ============= baggage key start ============== - */ + //******************* baggage key start ***************** /** - * 必须保持一致,baggage key 压测标识 + * Must be consistent, baggage key for pressure measurement mark */ public static final String LOAD_TEST_TAG = "mark"; - - /*** - * 压测标识必须为 T 即 baggage 中 mark=T 才可以打印到 shdow 文件 + /** + * The pressure measurement mark must be T, ie mark=T in baggage, to print to the shadow file. */ public static final String LOAD_TEST_VALUE = "T"; - /*** - * 非压测情况下的返回值 {@link AbstractSofaTracerStatisticReporter} + /** + * Return value in case of non-pressure measurement {@link AbstractSofaTracerStatisticReporter} */ public static final String NON_LOAD_TEST_VALUE = "F"; } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java index 14922267..ad510c44 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java @@ -22,7 +22,6 @@ import com.alipay.common.tracer.core.utils.StringUtils; import com.alipay.common.tracer.core.utils.TracerUtils; import io.opentracing.SpanContext; - import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -36,10 +35,10 @@ */ public class SofaTracerSpanContext implements SpanContext { - //spanId 分隔符 + //spanId separator public static final String RPC_ID_SEPARATOR = "."; - //======================== 以下为序列化数据的 key ======================== + //======================== The following is the key for serializing data ======================== private static final String TRACE_ID_KET = "tcid"; @@ -49,41 +48,42 @@ public class SofaTracerSpanContext implements SpanContext { private static final String SAMPLE_KET = "sample"; - /*** - * 序列化系统透传属性 key 的关键字前缀(需要序列化添加,反序列化去除 key 的前缀) + /** + * The serialization system transparently passes the prefix of the attribute key */ private static final String SYS_BAGGAGE_PREFIX_KEY = "_sys_"; - //span 关键属性参数 private String traceId = StringUtils.EMPTY_STRING; private String spanId = StringUtils.EMPTY_STRING; private String parentId = StringUtils.EMPTY_STRING; - /*** - * 默认不会采样 + /** + * Default will not be sampled */ private boolean isSampled = false; - /*** - * 系统透传数据,主要是指系统维度的透传数据,注意业务透传不能使用此字段 + /** + * The system transparently transmits data, + * mainly refers to the transparent transmission data of the system dimension. + * Note that this field cannot be used for transparent transmission of business. */ private final Map sysBaggage = new ConcurrentHashMap(); - /*** - * 透传数据,主要是指业务的透传数据 + /** + * Transparent transmission of data, mainly refers to the transparent transmission data of the business */ private final Map bizBaggage = new ConcurrentHashMap(); /** - * 子上下文的计数器 + * sub-context counter */ private AtomicInteger childContextIndex = new AtomicInteger(0); - /*** - * clone 一个当前模型 - * @return clone 对象 + /** + * clone a SofaTracerSpanContext instance + * @return */ public SofaTracerSpanContext cloneInstance() { SofaTracerSpanContext spanContext = new SofaTracerSpanContext(this.traceId, this.spanId, @@ -95,17 +95,17 @@ public SofaTracerSpanContext cloneInstance() { } public SofaTracerSpanContext() { - //默认不会采样 + //Default will not be sampled this(StringUtils.EMPTY_STRING, StringUtils.EMPTY_STRING, null, false); } public SofaTracerSpanContext(String traceId, String spanId) { - //默认不会采样 + //Default will not be sampled this(traceId, spanId, null, false); } public SofaTracerSpanContext(String traceId, String spanId, String parentId) { - //默认不会采样 + //Default will not be sampled this(traceId, spanId, parentId, false); } @@ -130,9 +130,9 @@ public SofaTracerSpanContext addSysBaggage(Map sysBaggage) { return this; } - /*** - * 系统和业务 baggage 均返回 - * @return 迭代器 + /** + * return both system and business baggage + * @return Iterable */ @Override public Iterable> baggageItems() { @@ -146,21 +146,20 @@ public Iterable> baggageItems() { return allBaggage.entrySet(); } - /**** - * 关键信息统一生成字符串 + /** + * return key information string for SofaTracerSpanContext * @return */ - private String contextAsString() {// NOPMD + private String contextAsString() { return String.format("%s:%s:%s:%s", traceId, spanId, parentId, isSampled); } /** - * 将 Tracer 中的穿透属性序列化成一个 String + * Serialize the Penetration property in Tracer into a String *

- * 此方法一般是 Tracer 内部或者直接集成 Tracer 的中间件使用 + * This method is generally used internally by Tracer or directly integrated with Tracer. *

- * - * @return 序列化以后的穿透属性 + * @return */ public String getBizSerializedBaggage() { return StringUtils.mapToString(bizBaggage); @@ -171,12 +170,12 @@ public String getSysSerializedBaggage() { } /** - * 将一个穿透属性序列化后的 String,反序列化回来成为一个 Map 接口 + * deserialize string to map + * *

- * 此方法一般是 Tracer 内部或者直接集成 Tracer 的中间件使用 + * This method is generally used internally by Tracer or directly integrated with Tracer. *

- * - * @param bizBaggageAttrs 序列化后的穿透属性 String + * @param bizBaggageAttrs serialized penetration properties */ public void deserializeBizBaggage(String bizBaggageAttrs) { StringUtils.stringToMap(bizBaggageAttrs, this.bizBaggage); @@ -201,10 +200,10 @@ public void deserializeSysBaggage(String sysBaggageAttrs) { } } - /*** - * 将 SpanContext 序列化为一个字符串,与 {@link SofaTracerSpanContext#deserializeFromString} 互逆 + /** + * Serialize the SpanContext to a string that is reciprocal to {@link SofaTracerSpanContext#deserializeFromString} * - * @return 序列化后的字符串, 格式:tcid:0,spid:1 + * @return Serialized string, format: tcid:0,spid:1 */ public String serializeSpanContext() { StringBuilder serializedValue = new StringBuilder(); @@ -228,20 +227,21 @@ public String serializeSpanContext() { return serializedValue.toString(); } - /*** - * 反序列化并还原一个 SofaTracerSpanContext,与 {@link SofaTracerSpanContext#serializeSpanContext()} 互逆 - * @param deserializedValue 反序列化的字符串,格式:tcid:0,spid:1 + /** + * + * Deserialize and restore a SofaTracerSpanContext, reciprocal with {@link SofaTracerSpanContext#serializeSpanContext()} + * @param deserializedValue deserialize string, format: tcid:0,spid:1 * @return SofaTracerSpanContext */ public static SofaTracerSpanContext deserializeFromString(String deserializedValue) { if (StringUtils.isBlank(deserializedValue)) { return SofaTracerSpanContext.rootStart(); } - //默认值 + //default value for SofaTracerSpanContext String traceId = TraceIdGenerator.generate(); String spanId = SofaTracer.ROOT_SPAN_ID; String parentId = StringUtils.EMPTY_STRING; - //默认false + //sampled default is false boolean sampled = false; //sys bizBaggage Map sysBaggage = new HashMap(); @@ -275,11 +275,11 @@ public static SofaTracerSpanContext deserializeFromString(String deserializedVal } int sysIndex = key.indexOf(SYS_BAGGAGE_PREFIX_KEY); if (sysIndex == 0) { - //必须前缀作为开始 + //must have a prefix String sysKey = key.substring(SYS_BAGGAGE_PREFIX_KEY.length()); sysBaggage.put(sysKey, value); } else { - //剩余全部为业务 bizBaggage + //bizBaggage baggage.put(key, value); } } @@ -294,21 +294,20 @@ public static SofaTracerSpanContext deserializeFromString(String deserializedVal return sofaTracerSpanContext; } - /**** - * 作为根节点而开始 + /** + * As root start ,it will be return a new sofaTracerSpanContext * - * 注意:1.留下这个接口,不对接具体的 tracer 实现,主要为了在序列化或者反序列化发生异常时,做补救 - * 2.不可以随意调用此方法,正确的入口应该是 {@link SofaTracer.SofaTracerSpanBuilder#createRootSpanContext()} - * @return 根节点 + * Note:1.Leave this interface, do not dock the specific tracer implementation, mainly to remedy when an exception occurs in serialization or deserialization + * 2.This method cannot be called at will, the correct entry should be {@link SofaTracer.SofaTracerSpanBuilder#createRootSpanContext()} + * @return root node */ public static SofaTracerSpanContext rootStart() { return rootStart(false); } public static SofaTracerSpanContext rootStart(boolean isSampled) { - //生成 traceId + //create traceId String traceId = TraceIdGenerator.generate(); - //默认不采样 return new SofaTracerSpanContext(traceId, SofaTracer.ROOT_SPAN_ID, StringUtils.EMPTY_STRING, isSampled); } @@ -318,16 +317,16 @@ private String genParentSpanId(String spanId) { : spanId.substring(0, spanId.lastIndexOf(RPC_ID_SEPARATOR)); } - /*** - * 允许设置 tracdId + /** + * Allow to set traceId * @param traceId traceId */ public void setTraceId(String traceId) { this.traceId = traceId; } - /**** - * 允许设置 spanId + /** + * Allow to set spanId * @param spanId spanId */ public void setSpanId(String spanId) { @@ -392,18 +391,18 @@ public AtomicInteger getChildContextIndex() { } /** - * 获取下一个子上下文的 ID + * Get the ID of the next sub context * - * @return 下一个 spanId + * @return next spanId */ public String nextChildContextId() { return this.spanId + RPC_ID_SEPARATOR + childContextIndex.incrementAndGet(); } /** - * 获取上一个子上下文的 rpcId + * Get the spanId of the previous sub context * - * @return 上一个子上下文的 rpcId + * @return prev spanId */ public String lastChildContextId() { return this.spanId + RPC_ID_SEPARATOR + childContextIndex.get(); @@ -427,9 +426,6 @@ public boolean equals(Object o) { return false; } if (StringUtils.isBlank(parentId)) { - //一个为空 - //另一个也为空 - //另一个不为空 return StringUtils.isBlank(that.parentId); } return parentId.equals(that.parentId); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/context/trace/SofaTraceContext.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/context/trace/SofaTraceContext.java index 0f53dfbc..8ffc78f6 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/context/trace/SofaTraceContext.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/context/trace/SofaTraceContext.java @@ -49,14 +49,14 @@ public interface SofaTraceContext { */ SofaTracerSpan pop(); - /*** - * Retrieves the current span size stored in current thread local + /** + * Retrieves the current span size stored in current thread local * * @return the span size of current thread local */ int getThreadLocalSpanSize(); - /*** + /** * Clear current thread local span */ void clear(); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/EmptyTracerStateStringException.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/EmptyTracerStateStringException.java index 0df37fb2..429922c4 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/EmptyTracerStateStringException.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/EmptyTracerStateStringException.java @@ -19,7 +19,7 @@ /** * * @author luoguimu123 - * @version $Id: EmptyTracerStateStringException.java, v 0.1 2017年06月22日 上午10:55 luoguimu123 Exp $ + * @version $Id: EmptyTracerStateStringException.java, v 0.1 June 22, 2017 10:55 AM luoguimu123 Exp $ */ public class EmptyTracerStateStringException extends RuntimeException { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/SamplingStrategyErrorException.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/SamplingStrategyErrorException.java index 4eab30a1..549464d4 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/SamplingStrategyErrorException.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/SamplingStrategyErrorException.java @@ -17,9 +17,9 @@ package com.alipay.common.tracer.core.exception; /** - * 采样部分代码出错时候采用的异常 + * Exception when sampling part of the code error * @author luoguimu123 - * @version $Id: SamplingStrategyErrorException.java, v 0.1 2017年06月22日 上午10:56 luoguimu123 Exp $ + * @version $Id: SamplingStrategyErrorException.java, v 0.1 June 22, 2017 10:56 AM luoguimu123 Exp $ */ public class SamplingStrategyErrorException extends RuntimeException { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/SofaTracerRuntimeException.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/SofaTracerRuntimeException.java index 0890fa40..ca507ee2 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/SofaTracerRuntimeException.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/SofaTracerRuntimeException.java @@ -32,6 +32,7 @@ public SofaTracerRuntimeException(String desc, Throwable t) { super(desc, t); } + @Override public String toString() { return super.getMessage(); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/UnsupportedFormatException.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/UnsupportedFormatException.java index 570cb3d2..e0d5305a 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/UnsupportedFormatException.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/exception/UnsupportedFormatException.java @@ -19,10 +19,10 @@ import io.opentracing.propagation.Format; /** - * format不支持时抛出的异常 + * format does not support exception thrown * * @author luoguimu123 - * @version $Id: UnsupportedFormatException.java, v 0.1 2017年06月22日 上午10:57 luoguimu123 Exp $ + * @version $Id: UnsupportedFormatException.java, v 0.1 June 22, 2017 10:57 AM luoguimu123 Exp $ */ public class UnsupportedFormatException extends RuntimeException { public UnsupportedFormatException(Format format) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/extensions/SpanExtension.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/extensions/SpanExtension.java index 684716ae..17f07f10 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/extensions/SpanExtension.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/extensions/SpanExtension.java @@ -21,16 +21,31 @@ /** * * @author luoguimu123 - * @version $Id: TracerExtension.java, v 0.1 2017年06月23日 上午11:48 luoguimu123 Exp $ + * @version $Id: TracerExtension.java, v 0.1 June 23, 2017 11:48 AM luoguimu123 Exp $ */ public interface SpanExtension { - + /** + * Called at the beginning of span + * @param currentSpan + */ void logStartedSpan(Span currentSpan); + /** + * Called at the end of span + * @param currentSpan + */ void logStoppedSpan(Span currentSpan); + /** + * Called at the end of span in Runnable + * @param currentSpan + */ void logStoppedSpanInRunnable(Span currentSpan); + /** + * return support name + * @return + */ String supportName(); } \ No newline at end of file diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/extensions/SpanExtensionFactory.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/extensions/SpanExtensionFactory.java index 44040332..2803b47a 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/extensions/SpanExtensionFactory.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/extensions/SpanExtensionFactory.java @@ -25,7 +25,7 @@ /** * * @author luoguimu123 - * @version $Id: SpanExtensionFactory.java, v 0.1 2017年06月23日 上午11:50 luoguimu123 Exp $ + * @version $Id: SpanExtensionFactory.java, v 0.1 June 23, 2017 11:50 AM luoguimu123 Exp $ */ public class SpanExtensionFactory { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolder.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolder.java index 2c497d2e..edb814f5 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolder.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolder.java @@ -27,12 +27,12 @@ */ public class SofaTraceContextHolder { - /*** + /** * singleton SofaTraceContext */ private static final SofaTraceContext SOFA_TRACE_CONTEXT = new SofaTracerThreadLocalTraceContext(); - /*** + /** * Get threadlocal alipay trace context * @return SofaTraceContext */ diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/listener/SpanReportListener.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/listener/SpanReportListener.java index 81b3d0e0..fb526430 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/listener/SpanReportListener.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/listener/SpanReportListener.java @@ -19,12 +19,17 @@ import com.alipay.common.tracer.core.span.SofaTracerSpan; /** - * SpanReportListener + * SpanReportListener:Reporter extension interface * * @author yangguanchao * @since 2018/05/07 */ public interface SpanReportListener { + /** + * Reporter extension callback method + * It can be printed to the log, or it can be reported to some remote server + * @param sofaTracerSpan + */ void onSpanReport(SofaTracerSpan sofaTracerSpan); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/middleware/parent/AbstractDigestSpanEncoder.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/middleware/parent/AbstractDigestSpanEncoder.java index 7d62c317..f8547481 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/middleware/parent/AbstractDigestSpanEncoder.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/middleware/parent/AbstractDigestSpanEncoder.java @@ -23,22 +23,25 @@ /** * * @author luoguimu123 - * @version $Id: AbstractDigestSpanEncoder.java, v 0.1 2017年08月28日 上午10:23 luoguimu123 Exp $ + * @version $Id: AbstractDigestSpanEncoder.java, v 0.1 August 28, 2017 10:23 AM luoguimu123 Exp $ */ public abstract class AbstractDigestSpanEncoder implements SpanEncoder { - /*** - * 系统透传数据 - * @param spanContext span 上下文 + /** + * System transparent transmission of data + * @param spanContext span context * @return String */ protected String baggageSystemSerialized(SofaTracerSpanContext spanContext) { - //目前只有一个 baggage return spanContext.getSysSerializedBaggage(); } + /** + * Business transparent transmission of data + * @param spanContext span context + * @return + */ protected String baggageSerialized(SofaTracerSpanContext spanContext) { - //目前只有一个 baggage return spanContext.getBizSerializedBaggage(); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/mock/MockSofaTracer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/mock/MockSofaTracer.java index 9b054e24..a3a4ff76 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/mock/MockSofaTracer.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/mock/MockSofaTracer.java @@ -26,11 +26,11 @@ */ public class MockSofaTracer { - private static final String MOCK_TRACER = "MOCK_TRACER"; + private static final String MOCK_TRACER = "MOCK_TRACER"; - private static SofaTracer MOCK_SOFA_TRACER = null; + private volatile static SofaTracer MOCK_SOFA_TRACER = null; - /*** + /** * Get the mocked OpenTracing Implementation * @return mock tracer */ diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextB3Formatter.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextB3Formatter.java index 0b9ee514..904ebd34 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextB3Formatter.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextB3Formatter.java @@ -66,7 +66,7 @@ public SofaTracerSpanContext extract(TextMap carrier) { String parentId = null; boolean sampled = false; boolean isGetSampled = false; - //sys bizBaggage + //sysBaggage Map sysBaggage = new ConcurrentHashMap(); //bizBaggage Map bizBaggage = new ConcurrentHashMap(); @@ -161,14 +161,14 @@ public void inject(SofaTracerSpanContext spanContext, TextMap carrier) { } } - /*** + /** * encode string * @param value string will be encoded * @return encoded value */ protected abstract String encodedValue(String value); - /*** + /** * decode string * @param value string will be decoded * @return decoded value diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextFormatter.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextFormatter.java index aafac43f..350c4eca 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextFormatter.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/AbstractTextFormatter.java @@ -33,7 +33,7 @@ public abstract class AbstractTextFormatter implements RegistryExtractorInjector @Override public SofaTracerSpanContext extract(TextMap carrier) { if (carrier == null) { - //根节点开始 + //Root node starts return SofaTracerSpanContext.rootStart(); } SofaTracerSpanContext sofaTracerSpanContext = null; @@ -49,7 +49,7 @@ public SofaTracerSpanContext extract(TextMap carrier) { } } if (sofaTracerSpanContext == null) { - //根节点开始 + //Root node starts return SofaTracerSpanContext.rootStart(); } return sofaTracerSpanContext; @@ -63,17 +63,17 @@ public void inject(SofaTracerSpanContext spanContext, TextMap carrier) { carrier.put(FORMATER_KEY_HEAD, this.encodedValue(spanContext.serializeSpanContext())); } - /*** - * 对指定的值进行编码 - * @param value 字符串 - * @return 编码后的 value + /** + * Encode the specified value + * @param value + * @return encoded value */ protected abstract String encodedValue(String value); - /*** - * 对指定的值进行解码 - * @param value 字符串 - * @return 编码后的字符串 + /** + * Decode the specified value + * @param value + * @return decoded value */ protected abstract String decodedValue(String value); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/BinaryFormater.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/BinaryFormater.java index 476499f1..72eb4a52 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/BinaryFormater.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/BinaryFormater.java @@ -27,16 +27,18 @@ /** * BinaryFormater *

- * 注意:只支持堆内存不支持堆外内存 - * + * Note: only supports the heap memory does not support outside the heap memory + *

* @author yangguanchao * @since 2017/06/23 */ public class BinaryFormater implements RegistryExtractorInjector { - /*** - * 作为跨进程传输字段的关键字key或者头部标识信息,其 value 就是 {@link SofaTracerSpanContext} 的序列化表现:sofa tracer head - * 转换为字节码,这组字节码会作为 byteArray 中的 spanContext 起始标示 + /** + * As the keyword key or header identification information of the cross-process transmission field, + * its value is the serialization representation of {@link SofaTracerSpanContext}: sofa tracer head + * + * Converted to bytecode, this set of bytecodes will be used as the start of the spanContext in the byteArray */ private static final byte[] FORMATER_KEY_HEAD_BYTES = FORMATER_KEY_HEAD .getBytes(SofaTracerConstant.DEFAULT_UTF8_CHARSET); @@ -49,7 +51,6 @@ public Format getFormatType() { @Override public SofaTracerSpanContext extract(ByteBuffer carrier) { if (carrier == null || carrier.array().length < FORMATER_KEY_HEAD_BYTES.length) { - //从新开始 return SofaTracerSpanContext.rootStart(); } byte[] carrierDatas = carrier.array(); @@ -57,13 +58,12 @@ public SofaTracerSpanContext extract(ByteBuffer carrier) { byte[] formaterKeyHeadBytes = FORMATER_KEY_HEAD_BYTES; int index = ByteArrayUtils.indexOf(carrierDatas, formaterKeyHeadBytes); if (index < 0) { - //从新开始 return SofaTracerSpanContext.rootStart(); } try { - //(UTF-8)放在头部从 0 开始 + //(UTF-8)Put the head from 0 carrier.position(index + formaterKeyHeadBytes.length); - //value 字节数组 + //value byte arrays byte[] contextDataBytes = new byte[carrier.getInt()]; carrier.get(contextDataBytes); String spanContextInfos = new String(contextDataBytes, @@ -74,7 +74,6 @@ public SofaTracerSpanContext extract(ByteBuffer carrier) { .error( "com.alipay.common.tracer.core.registry.BinaryFormater.extract Error.Recover by root start", e); - //从新开始 return SofaTracerSpanContext.rootStart(); } } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/RegistryExtractorInjector.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/RegistryExtractorInjector.java index 3c9cc09d..ab4194b0 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/RegistryExtractorInjector.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/registry/RegistryExtractorInjector.java @@ -21,29 +21,30 @@ public interface RegistryExtractorInjector { - /*** - * 作为跨进程传输字段的关键字key或者头部标识信息,其 value 就是 {@link SofaTracerSpanContext} 的序列化表现:sofa tracer head + /** + * As the keyword key or header identification information of the cross-process transmission field, + * its value is the serialization representation of {@link SofaTracerSpanContext}: sofa tracer head */ String FORMATER_KEY_HEAD = "sftc_head"; - /*** - * 获取支持的格式类型 - * @return 格式类型 {@link Format} + /** + * Get supported format types + * @return Format type {@link Format} */ Format getFormatType(); /** - * 从负载中提取出 Span 上下文 + * Extract the Span context from the payload * - * @param carrier 负载 - * @return Span 上下文 + * @param carrier payload + * @return SpanContext */ SofaTracerSpanContext extract(T carrier); - /*** - * 向负载中注入 Span 上下文 - * @param spanContext 要注入或者序列化的 span 上下文 - * @param carrier 负载 + /** + * Inject a Span context into the payload + * @param spanContext The span context to be injected or serialized + * @param carrier payload */ void inject(SofaTracerSpanContext spanContext, T carrier); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoder.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoder.java index 91fad443..68f54077 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoder.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoder.java @@ -29,9 +29,10 @@ /** * CommonSpanEncoder *

- * 客户端错误和服务端错误均打印在同一个文件中 + * Client errors and server errors are printed in the same file + *

* - * 注意是无状态实例:多个日志打印共用的一个实例 + * Note that there is a stateless instance: an instance of multiple log prints shared * * @author yangguanchao * @since 2017/06/27 @@ -45,9 +46,9 @@ public String encode(CommonLogSpan commonLogSpan) throws IOException { } SofaTracerSpanContext spanContext = commonLogSpan.getSofaTracerSpanContext(); XStringBuilder xsb = new XStringBuilder(); - //报告开始的时间作为打印的时间,不存在完成时间 + //The time when the report started as the time of printing, there is no completion time xsb.append(Timestamp.format(commonLogSpan.getStartTime())) - //保证构造common也携带过来 + //Ensure that the construct common is also carried .append(commonLogSpan.getTagsWithStr().get(SpanTags.CURR_APP_TAG.getKey())) .append(spanContext.getTraceId()).append(spanContext.getSpanId()); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManager.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManager.java index 628d1d91..031d5a71 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManager.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManager.java @@ -35,8 +35,7 @@ public class CommonTracerManager { /** - * - * 异步日志打印,所有的中间件公用一个来打印通用日志 + * Asynchronous log print, all middleware common to print general logs */ private static volatile AsyncCommonDigestAppenderManager commonReporterAsyncManager = new AsyncCommonDigestAppenderManager( 1024); @@ -64,11 +63,11 @@ public class CommonTracerManager { commonReporterAsyncManager.start("CommonProfileErrorAppender"); } - /*** - * 注册一个通用日志 - * @param logFileName 日志文件名字,同时也是作为日志文件的类型标识 - * @param rollingPolicy 滚动策略 - * @param logReserveDay 保留天数 + /** + * Register a general log + * @param logFileName logFileName + * @param rollingPolicy rollingPolicy + * @param logReserveDay logReserveDay */ public static void register(String logFileName, String rollingPolicy, String logReserveDay) { if (StringUtils.isBlank(logFileName)) { @@ -83,12 +82,12 @@ public static void register(String logFileName, String rollingPolicy, String log commonReporterAsyncManager.addAppender(logFileName, traceAppender, commonSpanEncoder); } - /*** - * 废弃 - * @param logType 类型 - * @param logFileName 文件名称 - * @param rollingPolicy 滚动策略 - * @param logReserveDay 保留天数 + /** + * Deprecated registration method + * @param logType logType + * @param logFileName logFileName + * @param rollingPolicy rollingPolicy + * @param logReserveDay logReserveDay */ @Deprecated public static void register(char logType, String logFileName, String rollingPolicy, @@ -103,10 +102,10 @@ public static void register(char logType, String logFileName, String rollingPoli commonReporterAsyncManager.addAppender(logTypeStr, traceAppender, commonSpanEncoder); } - /*** - * 判断指定日志类型的输出是否符合要求 - * @param logType 日志类型 - * @return true 已经存在 + /** + * Determine if the output of the specified log type meets the requirements + * @param logType logType + * @return true:exist */ public static boolean isAppenderExist(String logType) { if (StringUtils.isBlank(logType)) { @@ -115,9 +114,9 @@ public static boolean isAppenderExist(String logType) { return commonReporterAsyncManager.isAppenderAndEncoderExist(logType); } - /*** - * 注意:这个 {@link CommonLogSpan} 的 logType 一定要设置,否则无法打印 - * @param commonLogSpan 要被打印的 Span + /** + * Note: The logType of this {@link CommonLogSpan} must be set, otherwise it will not print. + * @param commonLogSpan The span will be printed */ public static void reportCommonSpan(CommonLogSpan commonLogSpan) { if (commonLogSpan == null) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/AbstractDiskReporter.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/AbstractDiskReporter.java index 980c6981..c0f1585e 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/AbstractDiskReporter.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/AbstractDiskReporter.java @@ -28,59 +28,59 @@ /** * AbstractDiskReporter * - * 持久化抽象类,摘要持久化和统计持久化 + * Abstract classes for persisting log information, including digest log persistence and stat log persistence * @author yangguanchao * @since 2017/07/14 */ public abstract class AbstractDiskReporter extends AbstractReporter { - /*** - * 获取 Reporter 实例类型 - * @return 类型 + /** + * Get Reporter instance type + * @return */ @Override public String getReporterType() { - //默认用摘要日志的类型作为 span 的类型 + //By default, the type of the digest log is used as the type of span return this.getDigestReporterType(); } - /*** - * 输出 span - * @param span 要被输出的 span + /** + * output span + * @param span */ @Override public void doReport(SofaTracerSpan span) { - //设置日志类型,方便打印,否则无法正确打印 + //Set the log type for easy printing, otherwise it will not print correctly. span.setLogType(this.getDigestReporterType()); if (!isDisableDigestLog(span)) { - //打印摘要日志 + //print digest log this.digestReport(span); } - //统计日志默认是不关闭的 + //print stat log this.statisticReport(span); } - /*** - * 获取摘要 Reporter 实例类型 - * @return 类型 + /** + * Get digest reporter instance type + * @return */ public abstract String getDigestReporterType(); - /*** - * 获取统计 Reporter 实例类型 - * @return 类型 + /** + * Get stat reporter instance type + * @return */ public abstract String getStatReporterType(); - /*** - * 打印摘要日志 - * @param span 被打印 span + /** + * print digest log + * @param span span */ public abstract void digestReport(SofaTracerSpan span); - /*** - * 打印统计日志 - * @param span 被统计 span + /** + * print stat log + * @param span span */ public abstract void statisticReport(SofaTracerSpan span); @@ -103,13 +103,13 @@ protected boolean isDisableDigestLog(SofaTracerSpan span) { Map disableConfiguration = SofaTracerConfiguration .getMapEmptyIfNull(SofaTracerConfiguration.DISABLE_DIGEST_LOG_KEY); - //摘要日志类型 + //digest log type String logType = StringUtils.EMPTY_STRING + span.getLogType(); if (StringUtils.isBlank(logType)) { - //摘要日志类型为空,就不打印了 + //if the digest log type is empty, it will not be printed. return true; } - // rpc-2-jvm特殊处理, 适配rpc2jvm中关闭digest而只打印stat的情况 + // Rpc-2-jvm special handling, adapting rpc2jvm to close digest and only print stat if (SofaTracerConstant.RPC_2_JVM_DIGEST_LOG_NAME.equals(logType)) { if (Boolean.FALSE.toString().equalsIgnoreCase( SofaTracerConfiguration.getProperty("enable_rpc_2_jvm_digest_log"))) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImpl.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImpl.java index f2368638..f9d9d03e 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImpl.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImpl.java @@ -31,16 +31,16 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * DiskReporterImpl - * 内部定制化实现 + * Internal customization : DiskReporterImpl * * @author yangguanchao * @since 2017/07/14 */ public class DiskReporterImpl extends AbstractDiskReporter { - /*** - * 标识初始状态: lazy 初始化磁盘文件,用到在初始化,注意并发初始化逻辑 + /** + * Identify the initial state: lazy initializes the disk file, + * used in initialization, pay attention to concurrent initialization logic */ private final AtomicBoolean isDigestFileInited = new AtomicBoolean(false); @@ -54,8 +54,9 @@ public class DiskReporterImpl extends AbstractDiskReporter { private String logNameKey; - /*** - * 统计实现,需要用户实现一个如何统计的方法,默认提供了累加的操作 + /** + * Statistical implementation, the user needs to implement a method of how to count, + * the cumulative operation is provided by default. */ private SofaTracerStatisticReporter statReporter; @@ -78,25 +79,22 @@ public DiskReporterImpl(String digestLogType, String digestRollingPolicy, statReporter, null); } - /*** - * - * @param digestLogType 日志类型 - * @param digestRollingPolicy 滚动策略 - * @param digestLogReserveConfig 保留天数配置 - * @param contextEncoder 日志输出编码 - * @param statReporter 用户需要提供统计实现 - * @param logNameKey 日志文件配置关键字 + /** + * @param digestLogType digestLogType:log type + * @param digestRollingPolicy digestRollingPolicy:digest rolling policy + * @param digestLogReserveConfig digestLogReserveConfig:Reserved days configuration + * @param contextEncoder contextEncoder:Log Encoder + * @param statReporter statReporter:User-supplied statistical log reporter implementation + * @param logNameKey logNameKey:Log file configuration keyword */ public DiskReporterImpl(String digestLogType, String digestRollingPolicy, String digestLogReserveConfig, SpanEncoder contextEncoder, SofaTracerStatisticReporter statReporter, String logNameKey) { AssertUtils.hasText(digestLogType, "digestLogType can't be empty"); - this.digestLogType = digestLogType; this.digestRollingPolicy = digestRollingPolicy; this.digestLogReserveConfig = digestLogReserveConfig; this.contextEncoder = contextEncoder; - //注册统计实现 this.statReporter = statReporter; this.logNameKey = logNameKey; } @@ -117,7 +115,7 @@ public String getDigestReporterType() { @Override public String getStatReporterType() { if (statReporter != null) { - //日志文件名字 + //get log file name return statReporter.getStatTracerName(); } return StringUtils.EMPTY_STRING; @@ -125,14 +123,14 @@ public String getStatReporterType() { @Override public void digestReport(SofaTracerSpan span) { - //lazy 初始化 + //lazy initialization if (!this.isDigestFileInited.get()) { this.initDigestFile(); } AsyncCommonDigestAppenderManager asyncDigestManager = SofaTracerDigestReporterAsyncManager .getSofaTracerDigestReporterAsyncManager(); if (asyncDigestManager.isAppenderAndEncoderExist(this.digestLogType)) { - //同时存在 appender 和 encoder 才打印 + //Print only when appender and encoder are present asyncDigestManager.append(span); } else { SelfLog.warn(span.toString() + " have no logType set, so ignore data persistence."); @@ -170,8 +168,8 @@ public String getLogNameKey() { return logNameKey; } - /*** - * 磁盘文件初始化创建完成 + /** + * Disk file initialization is completed */ private synchronized void initDigestFile() { if (this.isDigestFileInited.get()) { @@ -192,14 +190,14 @@ private synchronized void initDigestFile() { TraceAppender digestTraceAppender = LoadTestAwareAppender .createLoadTestAwareTimedRollingFileAppender(this.digestLogType, this.digestRollingPolicy, this.digestLogReserveConfig); - //注册 digest + //registry digest AsyncCommonDigestAppenderManager asyncDigestManager = SofaTracerDigestReporterAsyncManager .getSofaTracerDigestReporterAsyncManager(); if (!asyncDigestManager.isAppenderAndEncoderExist(this.digestLogType)) { asyncDigestManager.addAppender(this.digestLogType, digestTraceAppender, this.contextEncoder); } - //已经存在或者首次创建 + //Already exists or created for the first time this.isDigestFileInited.set(true); } } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/manager/SofaTracerDigestReporterAsyncManager.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/manager/SofaTracerDigestReporterAsyncManager.java index ae30a2bd..57c180b7 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/manager/SofaTracerDigestReporterAsyncManager.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/manager/SofaTracerDigestReporterAsyncManager.java @@ -27,14 +27,13 @@ public final class SofaTracerDigestReporterAsyncManager { /** - * 异步日志打印,所有的中间件 摘要日志公用一个 SofaTracerDigestReporterAsyncManager AsyncAppender 来打印日志 + * Asynchronous log print, all middleware digest logs share a SofaTracerDigestReporterAsyncManager AsyncAppender to print logs */ private static volatile AsyncCommonDigestAppenderManager asyncCommonDigestAppenderManager; - /*** - * - * 异步摘要日志打印,所有的中间件公用一个 AsyncAppender 来打印日志 - * @return 全局唯一的日志打印器 + /** + * get singleton instance + * @return asyncCommonDigestAppenderManager */ public static AsyncCommonDigestAppenderManager getSofaTracerDigestReporterAsyncManager() { if (asyncCommonDigestAppenderManager == null) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/facade/AbstractReporter.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/facade/AbstractReporter.java index 7b71be22..a7f136d5 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/facade/AbstractReporter.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/facade/AbstractReporter.java @@ -23,37 +23,37 @@ /** * AbstractDiskReporter * - * 持久化抽象类,摘要持久化和统计持久化 + * Abstract class definition for the Reporter * @author yangguanchao * @since 2017/07/14 */ public abstract class AbstractReporter implements Reporter { - /*** - * 是否关闭摘要日志打印,默认不关闭,关闭意味着关闭摘要也关闭统计 + /** + * Whether to turn off digest log print, the default is not closed; + * closing means closing the digest and stat log */ private AtomicBoolean isClosePrint = new AtomicBoolean(false); - /*** - * 输出 span - * @param span 要被输出的 span + /** + * report span + * @param span */ @Override public void report(SofaTracerSpan span) { if (span == null) { return; } - //关闭所有日志打印:关闭摘要和统计 + //close print if (isClosePrint.get()) { return; } this.doReport(span); } - /*** - * 抽象方法具体输出方式落磁盘还会远程上报需要子类实现 - * - * @param span 要被输出的 span + /** + * Subclass needs to implement the report method + * @param span */ public abstract void doReport(SofaTracerSpan span); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/facade/Reporter.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/facade/Reporter.java index 2c178786..156c1e06 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/facade/Reporter.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/facade/Reporter.java @@ -26,30 +26,30 @@ */ public interface Reporter { - /*** - * 上报到远程服务器的持久化类型 + /** + * Persistence type reported to the remote server */ String REMOTE_REPORTER = "REMOTE_REPORTER"; /** - * 组合类型 + * Combined reporting type */ String COMPOSITE_REPORTER = "COMPOSITE_REPORTER"; - /*** - * 获取 Reporter 实例类型 - * @return 类型 + /** + * get reporter type + * @return */ String getReporterType(); - /*** - * 输出 span - * @param span 要被输出的 span + /** + * report span + * @param span */ void report(SofaTracerSpan span); - /*** - *关闭输出 span 的能力 + /** + * turn off output ability */ void close(); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/AbstractSofaTracerStatisticReporter.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/AbstractSofaTracerStatisticReporter.java index 7fbd8453..38317476 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/AbstractSofaTracerStatisticReporter.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/AbstractSofaTracerStatisticReporter.java @@ -45,70 +45,59 @@ public abstract class AbstractSofaTracerStatisticReporter implements SofaTracerStatisticReporter { /** - * 默认的周期为0(从0开始),即输出间隔时间是一个周期时间(一个周期多长时间是可以设置的,默认是60s), + * The default period is 0 (starting at 0), that is, + * the output interval is a cycle time (how long a cycle can be set, the default is 60s), * {@link com.alipay.common.tracer.core.reporter.stat.manager.SofaTracerStatisticReporterManager#DEFAULT_CYCLE_SECONDS} */ public static final int DEFAULT_CYCLE = 0; /** - * 用来控制初始化槽时的并发 + * Used to control the concurrency when initializing the slot */ private static final ReentrantLock initLock = new ReentrantLock(false); - /*** - * 输出拼接器 - */ private static XStringBuilder buffer = new XStringBuilder(); - /*** - * 是否关闭统计日志打印,默认不关闭 + /** + * Whether to turn off stat log print, the default is not closed */ protected AtomicBoolean isClosePrint = new AtomicBoolean(false); - /*** - * 输出器 - */ protected TraceAppender appender = null; /** - * 统计日志的名称 + * The name of the stat log */ protected String statTracerName; - /*** - * 周期时间,一次统计数据的周期时间,单位:秒 - */ - private long periodTime; - /** - * 滚动策略 + * period time(Unit:second) */ + private long periodTime; private String rollingPolicy; - - /** - * 日志保留天数 - */ private String logReserveConfig; - /** - * 输出周期间隔,单位:次数 + * Output cycle interval */ private int printCycle = 0; + /** - * 当前已被计数的周期数,单位:次数 + * The number of cycles currently counted */ private long countCycle = 0; + /** - * "统计数据"滚动数组 + * "Statistics" scrolling array */ private Map[] statDatasPair = new ConcurrentHashMap[2]; + /** - * "统计数据"滚动数组的当前下标 + * The current subscript of the "statistics" scrolling array */ private int currentIndex = 0; /** - * 统计数据 + * Statistical data */ protected Map statDatas; @@ -124,7 +113,6 @@ public AbstractSofaTracerStatisticReporter(String statTracerName, long periodTim AssertUtils.hasText(statTracerName, "Statistics tracer name cat't be empty."); this.statTracerName = statTracerName; - //周期时间:单位秒 this.periodTime = this.globalConfiguredCycleTime(periodTime); this.printCycle = outputCycle; this.rollingPolicy = rollingPolicy; @@ -133,14 +121,14 @@ public AbstractSofaTracerStatisticReporter(String statTracerName, long periodTim this.statDatasPair[i] = new ConcurrentHashMap(100); } this.statDatas = statDatasPair[currentIndex]; - //注册定时任务并启动 + //Register a scheduled task and start SofaTracerStatisticReporterCycleTimesManager.registerStatReporter(this); } - /**** - * 获取统计日志的输出时间间隔 - * @param defaultCycle 默认间隔 60s - * @return 统计日志的时间间隔 + /** + * Get the output interval of the stat log + * @param defaultCycle default interval is 60s + * @return */ private long globalConfiguredCycleTime(long defaultCycle) { long cycleTime = defaultCycle; @@ -186,30 +174,31 @@ public void reportStat(SofaTracerSpan sofaTracerSpan) { this.doReportStat(sofaTracerSpan); } - /*** - * 执行统计操作,并调用 {@link AbstractSofaTracerStatisticReporter#addStat} - * @param sofaTracerSpan 要被统计的 span + /** + * report stat log,and call {@link AbstractSofaTracerStatisticReporter#addStat} + * @param sofaTracerSpan */ public abstract void doReportStat(SofaTracerSpan sofaTracerSpan); /** - * 默认只提供累加的统计方法 + * By default, only the accumulated stat methods are provided. * - * 向槽中更新数据 前面是唯一的key,后面是数值列 统计计算会对不同key的数值列进行加和 + * Update the data to the slot. The front is the unique key, followed by the numeric column. + * The statistical calculation adds the numeric columns of different keys. * - * @param keys 被统计 key 的唯一标示 - * @param values 被统计的值 + * @param keys Unique identifier of the key being counted + * @param values Statistical value */ protected void addStat(StatKey keys, long... values) { StatValues oldValues = statDatas.get(keys); if (oldValues == null) { - // 初始化过程,需要加锁和二次判空 + // need to lock and double judgment initLock.lock(); try { oldValues = statDatas.get(keys); - // 新增一个key,先判断是否超出最大key上限 + // check whether the maximum key limit is exceeded if (null == oldValues) { - // 本次是第一次创建该槽,创建完毕设置第一次的统计值,即可返回 + // Create a slot with specified value oldValues = new StatValues(values); statDatas.put(keys, oldValues); return; @@ -218,14 +207,14 @@ protected void addStat(StatKey keys, long... values) { initLock.unlock(); } } - // 已有其他线程创建过槽,合并新数据 + // Other threads have created slots and merge new data if (oldValues != null) { oldValues.update(values); } } /** - * 切换当前下标并返回切换前的统计数据 + * Switch the current subscript and return the stat before switching */ @Override public Map shiftCurrentIndex() { @@ -236,18 +225,19 @@ public Map shiftCurrentIndex() { } /** - * 返回当前被统计的数据 + * Return the currently statistical data * - * @return 当前被统计的数据 + * @return */ public Map getStatData() { return new HashMap(statDatas); } /** - * 获取另一组非当前正在统计的数据,总共:两组数据进行统计和打印 + * Get another set of data that is not currently being counted, + * Total: two sets of data for statistics and printing * - * @return 非当前正在统计的数据 + * @return */ public Map getOtherStatData() { return new HashMap(statDatasPair[1 - currentIndex]); @@ -261,7 +251,7 @@ public boolean shouldPrintNow() { @Override public void print(StatKey statKey, long[] values) { if (this.isClosePrint.get()) { - //关闭统计日志输出 + //Close the statistics log output return; } buffer.reset(); @@ -279,10 +269,10 @@ public void print(StatKey statKey, long[] values) { } else { appender.append(buffer.toString()); } - // 这里强制刷一次 + // Forced to flush appender.flush(); } catch (Throwable t) { - SelfLog.error("统计日志<" + statTracerName + ">输出异常", t); + SelfLog.error("Stat log <" + statTracerName + "> output error!", t); } } @@ -314,6 +304,6 @@ protected String buildString(String[] keys) { protected boolean isHttpOrMvcSuccess(String resultCode) { return resultCode.charAt(0) == '1' || resultCode.charAt(0) == '2' - || resultCode.trim().equals("302") || resultCode.trim().equals("301"); + || "302".equals(resultCode.trim()) || ("301".equals(resultCode.trim())); } } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporter.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporter.java index 1d0c3fee..94636f75 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporter.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporter.java @@ -25,54 +25,54 @@ /** * SofaTracerStatisticReporter *

- * 参考: {com.alipay.common.tracer.tracer.StatTracer} - * + * Reference: {com.alipay.common.tracer.tracer.StatTracer} + *

* @author yangguanchao * @since 2017/06/26 */ public interface SofaTracerStatisticReporter { - /*** - * 获取周期时间,即多长时间调度一次 - * @return 一次统计数据的周期时间 + /** + * get the period time + * @return */ long getPeriodTime(); - /*** - * 获取统计类型额唯一标示 - * @return 统计名称(全局唯一标识) + /** + * Get the unique identifier of the statistic type + * @return */ String getStatTracerName(); - /*** - * 向槽中更新数据 前面是唯一的key,后面是数值列 统计计算会对不同key的数值列进行加和 - * - * @param sofaTracerSpan span 上下文 + /** + * Update data to the slot + * @param sofaTracerSpan */ void reportStat(SofaTracerSpan sofaTracerSpan); - /*** - * 切换当前下标并返回切换前的统计数据 - * @return 当前时间段内的统计数据 + /** + * Switch the current subscript and return the stat before switching + * @return */ Map shiftCurrentIndex(); /** - * 当该方法被调用,说明已经过去了一个周期,要判断是否已经过去了足够的周期,是否需要flush + * When the method is called, it indicates that a cycle has passed, + * to determine whether enough cycles have passed, and whether flush is needed. * - * @return true 统计数据可以打印,框架会调用 {@link SofaTracerStatisticReporter#print} + * @return true:stat log can be printed and the framework will call {@link SofaTracerStatisticReporter#print} */ boolean shouldPrintNow(); - /*** - * 打印,即可以打印到本地磁盘,也可以上报到远程服务器 - * @param statKey 统计关键字 - * @param values 要打印的值 + /** + * Print, you can print to a local disk, or you can report to a remote server + * @param statKey + * @param values */ void print(StatKey statKey, long[] values); - /*** - * 关闭打印能力 + /** + * close print */ void close(); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterCycleTimesManager.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterCycleTimesManager.java index 1f9f5175..895c95fd 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterCycleTimesManager.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterCycleTimesManager.java @@ -35,10 +35,9 @@ public static Map getCycleTimesManager return cycleTimesManager; } - /*** - * 周期:秒 - * 需要统一掉 - * @param statisticReporter 周期统计时间 + /** + * period: second + * @param statisticReporter statisticReporter */ public static void registerStatReporter(SofaTracerStatisticReporter statisticReporter) { SofaTracerStatisticReporterManager sofaTracerStatisticReporterManager = SofaTracerStatisticReporterCycleTimesManager @@ -48,10 +47,10 @@ public static void registerStatReporter(SofaTracerStatisticReporter statisticRep } } - /*** - * 定时任务以此为入口:获取指定周期时间的定时任务 - * @param cycleTime 周期时间单位:秒 - * @return SofaTracerStatisticReporterManager 固定周期的任务管理器 + /** + * The timed task uses this as the entry: Get the scheduled task with the specified cycle time + * @param cycleTime period: second + * @return SofaTracerStatisticReporterManager Fixed-cycle task manager */ public static SofaTracerStatisticReporterManager getSofaTracerStatisticReporterManager(Long cycleTime) { if (cycleTime == null) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterManager.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterManager.java index bfde6bdd..aec7bd52 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterManager.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/manager/SofaTracerStatisticReporterManager.java @@ -29,31 +29,35 @@ /** * SofaTracerStatisticReporterManager *

- * 固定时间周期的 Reporter,一个时钟周期对应一个实例,初始化之后就会启动周期 - * + * Reporter with a fixed time period, one clock cycle corresponds to one instance, and the cycle is started after initialization + *

* @author yangguanchao * @since 2017/06/26 */ public class SofaTracerStatisticReporterManager { /** - * 阈值,如果统计日志的数据(map格式)key个数超过该值,则清空map,非 final 为了可测性 + * Threshold, if the number of keys in the stat log (map format) exceeds this value, the map is cleared, non-final for testability */ public static int CLEAR_STAT_KEY_THRESHOLD = 5000; /** - * 默认输出周期 60 秒 + * The default output period is 60 seconds. */ - static public final long DEFAULT_CYCLE_SECONDS = 60; + public static final long DEFAULT_CYCLE_SECONDS = 60; + /** + * Thread count + */ static final AtomicInteger THREAD_NUMBER = new AtomicInteger(0); - /*** - * 每一个固定周期调度都会有这样的一个实例 + + /** + * Every fixed-cycle schedule will have such an instance. */ private Map statReporters = new ConcurrentHashMap(); - /*** - * 周期时间,默认 {@link SofaTracerStatisticReporterManager#DEFAULT_CYCLE_SECONDS}=60 s + /** + * Period time, default {@link SofaTracerStatisticReporterManager#DEFAULT_CYCLE_SECONDS}=60 s */ private long cycleTime; @@ -66,7 +70,7 @@ public class SofaTracerStatisticReporterManager { SofaTracerStatisticReporterManager(final long cycleTime) { this.cycleTime = cycleTime; this.executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { - + @Override public Thread newThread(Runnable r) { final Thread thread = new Thread(r, "Tracer-TimedAppender-" + THREAD_NUMBER.incrementAndGet() + "-" @@ -82,10 +86,10 @@ private void start() { executor.scheduleAtFixedRate(new StatReporterPrinter(), 0, cycleTime, TimeUnit.SECONDS); } - /*** - * 根据名称获取统计 Reporter 实例 - * @param statTracerName 统计日志 tracer 名称 - * @return 统计实现 + /** + * Get a stat Reporter instance by statTracerName + * @param statTracerName Stat log tracer name + * @return */ public SofaTracerStatisticReporter getStatTracer(String statTracerName) { if (StringUtils.isBlank(statTracerName)) { @@ -94,9 +98,9 @@ public SofaTracerStatisticReporter getStatTracer(String statTracerName) { return statReporters.get(statTracerName); } - /*** - * 保存统计 Reporter 实例 - * @param statisticReporter 要保存的统计 Reporter 实例 + /** + * Save Stat Reporter instance + * @param statisticReporter statisticReporter */ public synchronized void addStatReporter(SofaTracerStatisticReporter statisticReporter) { if (statisticReporter == null) { @@ -114,29 +118,32 @@ public Map getStatReporters() { } class StatReporterPrinter implements Runnable { - + @Override public void run() { SofaTracerStatisticReporter st = null; try { - // 此任务默认 60 秒执行一次 + // once/60s for (SofaTracerStatisticReporter statTracer : statReporters.values()) { if (statTracer.shouldPrintNow()) { st = statTracer; - // 切换下标并获取过去一段时间的statDatas + // Switch subscripts and get statDatas for a while Map statDatas = statTracer.shiftCurrentIndex(); for (Map.Entry e : statDatas.entrySet()) { StatKey statKeys = e.getKey(); StatValues values = e.getValue(); - // 打印日志 - long tobePrint[] = values.getCurrentValue(); - // 当计数大于0的时候才打印 + // print log + long[] tobePrint = values.getCurrentValue(); + // print when the count is greater than 0 if (tobePrint[0] > 0) { statTracer.print(statKeys, tobePrint); } - // 更新槽中值,清除掉已打印内容 - values.clear(tobePrint);// 这里必须保证传入的参数是print过程中使用的数组的值 + // Update the slot value to clear the printed content + // Here you must ensure that the input params is the value of the array used in the print process. + values.clear(tobePrint); } - // 如果该统计日志的key的数量大于阈值,表示key可能有带可变参数,因此清空掉防止占用太多内存 + // If the number of keys in the statistics log is greater than the threshold, + // it indicates that the key may have variable parameters, + // so clearing it prevents taking up too much memory. if (statDatas.size() > CLEAR_STAT_KEY_THRESHOLD) { statDatas.clear(); } @@ -144,7 +151,7 @@ public void run() { } } catch (Throwable t) { if (st != null) { - SelfLog.error("统计日志<" + st.getStatTracerName() + ">flush失败", t); + SelfLog.error("Stat log <" + st.getStatTracerName() + "> flush failure.", t); } } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatKey.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatKey.java index 328b89c9..f8ef15ca 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatKey.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatKey.java @@ -25,22 +25,22 @@ public class StatKey { /** - * 统计信息的 Key + * Key for statistics */ private String key; /** - * 统计哪一类信息,Y 成功,N 失败 + * Y success,N failure */ private String result; /** - * 是否是压测的统计信息 + * Whether it is pressure measurement stat */ private boolean loadTest; /** - * 打印出来的结尾 + * Printed end */ private String end; diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatMapKey.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatMapKey.java index d2c28746..7109a650 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatMapKey.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatMapKey.java @@ -28,7 +28,7 @@ public class StatMapKey extends StatKey { /** - * 统计信息的 Key + * Key for statistic */ private Map keyMap = new HashMap(); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatValues.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatValues.java index c5374251..6e84ac9e 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatValues.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/stat/model/StatValues.java @@ -19,19 +19,30 @@ import java.util.concurrent.atomic.AtomicReference; /** - * 不断被更新的统计数据 + * Constantly updated statistics + * *

- * 注意这里用的是CAS机制 - * 该机制用失败重试的方式代替了锁 - * 它允许多线程同时对一个原子进行修改,但是当写入新值却发现新值已被修改时,需要重新执行赋值过程,直至成功 - * 需要注意的是赋值过程是会可能被不断重复执行的,那赋值算法中唯一允许变化的就是该原子内部的属性值,其他的因数不能发生变化 - * 这样能在大部分没有并发冲突的情况下提高性能 - * 所有对AtomicReference中的值的更改,必需是写入一个全新的数组,不能直接更改原来已有数组中的值(这样才能保证是对原子进行修改) + * Note that the CAS mechanism is used here. + * This mechanism replaces the lock with a failed retry + * + * It allows multiple threads to modify an atom at the same time, + * but when a new value is written and it is found that the new value has been modified, + * the assignment process needs to be re-executed until it succeeds. + * + * + * It should be noted that the assignment process may be repeatedly executed. + * The only change allowed in the assignment algorithm is the value of the attribute inside the atom. + * Other factors cannot be changed.This can improve performance in the absence of most concurrent conflicts. + * + * All changes to the value in the AtomicReference must be written to a completely new array, + * and the values ​​in the existing array cannot be directly changed (so that the atom is modified) + *

+ * * @author zhanghan */ public class StatValues { /** - * 真实的value + * the real value */ private final AtomicReference values = new AtomicReference(); @@ -40,9 +51,9 @@ public StatValues(long[] values) { } /** - * 写入新值 - * (所有操作需满足CAS机制) - * @param update 要更新的新值 + * write new value + * (All operations need to meet the CAS mechanism) + * @param update new value need to update */ public void update(long[] update) { long[] current; @@ -57,10 +68,14 @@ public void update(long[] update) { } /** - * 打印完毕后对槽清空 - * 由于在打印期间值可能已经被更新,所以传入需要被clear的数值数组,减去已被打印的值 - * (所有操作需满足CAS机制) - * @param toBeClear long 数组 + * Empty the slot after print + * + * The value may have been updated during printing + * So pass in the array of values ​​that need to be cleared, minus the value that has been printed. + * + * (All operations need to meet the CAS mechanism) + * + * @param toBeClear toBeClear */ public void clear(long[] toBeClear) { long[] current; @@ -74,11 +89,12 @@ public void clear(long[] toBeClear) { } /** - * 返回当前值 - * 这里可以直接get并返回,返回的值肯定不会改变 - * 因为任何对values这个原子的改变都是直接覆盖数组的引用地址 - * 而不会更新数组中的值 - * @return long 数组 + * Return current value + * + * Here you can get and return directly, the returned value will definitely not change + * Because any change to the atoms of values ​​is directly over the reference address of the array. + * and does not update the values ​​in the array. + * @return */ public long[] getCurrentValue() { return values.get(); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/type/TracerSystemLogEnum.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/type/TracerSystemLogEnum.java index 807af023..4443a8b2 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/type/TracerSystemLogEnum.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/type/TracerSystemLogEnum.java @@ -24,34 +24,21 @@ */ public enum TracerSystemLogEnum { - /*** - * 性能日志 - */ + /** Profile log */ RPC_PROFILE("rpc_profile_log_name", "rpc-profile.log", "rpc_profile_rolling"), + /** Business success log */ + BIZ_SUCCESS("biz_success_log_name", "biz_success.log", "biz_success_rolling"), + /** Business fail log */ + BIZ_FAIL("biz_fail_log_name", "biz_fail.log", "biz_fail_rolling"), - // 其他日志 - BIZ_SUCCESS("biz_success_log_name", "biz_success.log", "biz_success_rolling"), // 业务成功日志 - BIZ_FAIL("biz_fail_log_name", "biz_fail.log", "biz_fail_rolling"), // 业务异常日志 - - /*** - * 中间件错误日志 - */ + /** Middleware error log */ MIDDLEWARE_ERROR("middleware_error_log_name", "middleware_error.log", "middleware_error_rolling"); - /*** - * 获取保留天数 getLogReverseDay 关键字 - */ private String logReverseKey; - /*** - * 默认生成的日志名字 .log 结尾同时作为一个类型 - */ private String defaultLogName; - /*** - * 日志的滚动策略 - */ private String rollingKey; TracerSystemLogEnum(String logReverseKey, String defaultLogName, String rollingKey) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/Sampler.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/Sampler.java index 3f126daa..a3fc125b 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/Sampler.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/Sampler.java @@ -19,12 +19,17 @@ import com.alipay.common.tracer.core.span.SofaTracerSpan; public interface Sampler { + /** * @param sofaTracerSpan The operation name set on the span * @return whether or not the new trace should be sampled */ SamplingStatus sample(SofaTracerSpan sofaTracerSpan); + /** + * get sampler type + * @return + */ String getType(); /** diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SamplingStatus.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SamplingStatus.java index 1807f3f6..27ff9985 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SamplingStatus.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SamplingStatus.java @@ -23,8 +23,8 @@ public class SamplingStatus { private boolean isSampled = false; - /*** - * 允许在 RootSpan 处放置 tags + /** + * Allow tags to be placed at RootSpan */ private Map tags = new HashMap(); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SofaTracerPercentageBasedSampler.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SofaTracerPercentageBasedSampler.java index ec964279..8724d521 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SofaTracerPercentageBasedSampler.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/samplers/SofaTracerPercentageBasedSampler.java @@ -77,9 +77,9 @@ public void close() { * Reservoir sampling algorithm borrowed from Stack Overflow. *

* http://stackoverflow.com/questions/12817946/generate-a-random-bitset-with-n-1s - * @param size 大小 - * @param cardinality 基数 - * @param rnd 随机种子 + * @param size + * @param cardinality + * @param rnd * @return BitSet */ public static BitSet randomBitSet(int size, int cardinality, Random rnd) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/span/CommonLogSpan.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/CommonLogSpan.java index 4ca114f5..6ccb8b80 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/span/CommonLogSpan.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/CommonLogSpan.java @@ -29,9 +29,10 @@ /** * CommonLogSpan * - * 主要为了记录具体的顺序数据 + * Mainly for recording specific sequential data * - * 之所以要新创建一个对象,主要是为了区分 CommonLogSpan 和日常摘要等的打印 + * + * The reason to create a new object is to distinguish between the printing of CommonLogSpan and daily digest. * * com.alipay.common.tracer.core.span.LogData#EVENT_COMMON_TYPE_VALUE * @@ -42,14 +43,15 @@ public class CommonLogSpan extends SofaTracerSpan { private static final int MAX_SLOT_SIZE = 32; - /** 通用的槽位,需要打印的日志数据全部都放到这里面 */ + /** + * The common slot, all the log data that needs to be printed are placed in it. + */ private List slots = new ArrayList(); private AtomicInteger slotCounter = new AtomicInteger(0); public CommonLogSpan(SofaTracer sofaTracer, long startTime, String operationName, SofaTracerSpanContext sofaTracerSpanContext, Map tags) { - //SofaTracer 可以 mock 在 此中,因为打印是通过显示 report this(sofaTracer, startTime, null, operationName, sofaTracerSpanContext, tags); } @@ -57,13 +59,12 @@ public CommonLogSpan(SofaTracer sofaTracer, long startTime, List spanReferences, String operationName, SofaTracerSpanContext sofaTracerSpanContext, Map tags) { - //SofaTracer 可以 mock 在 此中,因为打印是通过显示 report super(sofaTracer, startTime, spanReferences, operationName, sofaTracerSpanContext, tags); } /** - * 往 Slots 中增加一项需要打印的内容 - * @param slot 槽位 + * Add an item to Slots that needs to be printed + * @param slot */ public void addSlot(String slot) { if (slot == null) { @@ -73,21 +74,21 @@ public void addSlot(String slot) { if (slotCounter.incrementAndGet() <= MAX_SLOT_SIZE) { slots.add(slot); } else { - SelfLog.warn("槽位数量(" + MAX_SLOT_SIZE + ")已满"); + SelfLog.warn("Slots count(" + MAX_SLOT_SIZE + ")Fully"); } } /** - * 获取所有需要打印的内容 - * @return 栏位列表 + * Get all the content you need to print + * @return */ public List getSlots() { return slots; } - /*** - * 添加 slot 列表 - * @param stringArrayList slot 列表 + /** + * Add slot list + * @param stringArrayList */ public void addSlots(List stringArrayList) { if (stringArrayList == null || stringArrayList.isEmpty()) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/span/LogData.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/LogData.java index 69456c62..fe2f845e 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/span/LogData.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/LogData.java @@ -20,8 +20,8 @@ public final class LogData { - /*** - * 事件类型关键字 @Nullable cs/cr/ss/sr ,去掉单独字段,使用统一 map 操作 + /** + * Event type keyword @Nullable cs/cr/ss/sr */ public static final String EVENT_TYPE_KEY = "event"; diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java index 532f5727..01cfa7e6 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java @@ -46,15 +46,12 @@ public class SofaTracerSpan implements Span { private final SofaTracer sofaTracer; - /*** - * tags String,Integer,boolean - */ private final List spanReferences; - + /** tags for String */ private final Map tagsWithStr = new LinkedHashMap(); - + /** tags for Boolean */ private final Map tagsWithBool = new LinkedHashMap(); - + /** tags for Number */ private final Map tagsWithNumber = new LinkedHashMap(); private final List logs = new LinkedList(); @@ -63,24 +60,18 @@ public class SofaTracerSpan implements Span { private final SofaTracerSpanContext sofaTracerSpanContext; - /*** - * 启动时间 - */ private long startTime; - - /*** - * span endTime - */ private long endTime = -1; - /*** - * - * report时才有意义:摘要日志类型,日志能够正确打印的关键信息:当前 span 的日志类型,如:客户端为 rpc-client-digest.log,服务端为 rpc-server-digest.log + /** + * Only meaningful when reporting + * Digest log type,The logs correctly printed key information. + * For example, the client is rpc-client-digest.log and the server is rpc-server-digest.log */ private String logType = StringUtils.EMPTY_STRING; - /*** - * 父亲 span,当作为客户端结束并弹出线程上下文时,需要将父亲 span 再放入 + /** + * parent span. Describe the child-of relationship */ private SofaTracerSpan parentSofaTracerSpan = null; @@ -104,37 +95,36 @@ public SofaTracerSpan cloneInstance() { return cloneSpan; } - /*** - * 作为服务端:还原回 {@link SofaTracerSpanContext} 之后,就可以直接构造 Server Span(traceId,spanId 不变) + /** + * As a server-Side(Kind.type is server): After reverting back to {@link SofaTracerSpanContext}, + * you can directly construct Server Span (traceId, spanId unchanged) * - * @param sofaTracer sofaTracer 当前具体中间件 tracer - * @param startTime 开始时间 - * @param operationName 操作名称 - * @param sofaTracerSpanContext 当前上下文信息 - * @param tags 标签 + * @param sofaTracer sofaTracer + * @param startTime startTime + * @param operationName operationName + * @param sofaTracerSpanContext sofaTracerSpanContext + * @param tags tags */ public SofaTracerSpan(SofaTracer sofaTracer, long startTime, String operationName, SofaTracerSpanContext sofaTracerSpanContext, Map tags) { - //作为服务端还原回 sofaTracerSpanContext,traceId:spanId 不变,所以 spanReferences 为空 this(sofaTracer, startTime, null, operationName, sofaTracerSpanContext != null ? sofaTracerSpanContext : SofaTracerSpanContext .rootStart(), tags); } - /*** - * 注意: - * - * 1.作为服务端:还原回 {@link SofaTracerSpanContext} 之后,就可以直接构造 Server Span(traceId,spanId 不变) + /** + * Note: * + * 1.As a server-side: After reverting back to {@link SofaTracerSpanContext}, you can directly construct Server Span (traceId, spanId unchanged) * - * 2.作为客户端:需要通过 {@link SofaTracer.SofaTracerSpanBuilder#start() 构建} + * 2.As a client: need to be built by {@link SofaTracer.SofaTracerSpanBuilder#start()} * - * @param sofaTracer 当前 tracer - * @param startTime 开始时间 - * @param spanReferences 引用关系 - * @param operationName 操作名称 - * @param sofaTracerSpanContext 当前上下文 - * @param tags 标签 + * @param sofaTracer sofaTracer + * @param startTime startTime + * @param spanReferences spanReferences + * @param operationName operationName + * @param sofaTracerSpanContext sofaTracerSpanContext + * @param tags tags */ public SofaTracerSpan(SofaTracer sofaTracer, long startTime, List spanReferences, @@ -148,7 +138,6 @@ public SofaTracerSpan(SofaTracer sofaTracer, long startTime, spanReferences) : null; this.operationName = operationName; this.sofaTracerSpanContext = sofaTracerSpanContext; - //tags this.setTags(tags); SpanExtensionFactory.logStartedSpan(this); @@ -167,7 +156,7 @@ public void finish() { @Override public void finish(long endTime) { this.setEndTime(endTime); - //关键记录:report span + //Key record:report span this.sofaTracer.reportSpan(this); SpanExtensionFactory.logStoppedSpan(this); } @@ -183,7 +172,7 @@ public Span setTag(String key, String value) { return this; } this.tagsWithStr.put(key, value); - //注意:server 还是 client 在 OpenTracing 标准中是用 tags 标识的,所以在这里进行判断 + //to set log type by span kind type if (isServer()) { Reporter serverReporter = this.sofaTracer.getServerReporter(); if (serverReporter != null) { @@ -215,18 +204,15 @@ public Span setTag(String key, Number number) { @Override public Span log(String eventValue) { - //使用默认的 event key,关键记录 span 事件:cs/cr/ss/sr + //log with current time return log(System.currentTimeMillis(), eventValue); } @Override public Span log(long currentTime, String eventValue) { - //关键记录 span 事件 AssertUtils.isTrue(currentTime >= startTime, "Current time must greater than start time"); - //记录下相关事件 Map fields = new HashMap(); fields.put(LogData.EVENT_TYPE_KEY, eventValue); - //save return this.log(currentTime, fields); } @@ -265,11 +251,12 @@ public Span log(long currentTime, String eventName, /* @Nullable */Object payloa return this.log(currentTime, fields); } - /*** - * 默认设置和读取的都是业务 baggage - * @param key 关键字 - * @param value 值 - * @return 当前 span + /** + * + * The default settings are business baggage + * @param key + * @param value + * @return */ @Override public Span setBaggageItem(String key, String value) { @@ -277,10 +264,10 @@ public Span setBaggageItem(String key, String value) { return this; } - /*** - * 默认设置和读取的都是业务 baggage - * @param key 关键字 - * @return 当前 span + /** + * The default read are business baggage + * @param key + * @return */ @Override public String getBaggageItem(String key) { @@ -293,32 +280,32 @@ public Span setOperationName(String operationName) { return this; } - //=======================扩展的 API 接口开始 + //======================= Extended API interface starts - /*** + /** * - * @param errorType errorType error 描述:timeout_error/biz_error... - * @param context context 记录的上下文信息 - * @param e e 异常信息 - * @param errorSourceApp errorSources 故障源 trade|rpc - * @param errorSources errorSources 故障源数组 + * @param errorType errorType error description:timeout_error/biz_error... + * @param context context + * @param e e + * @param errorSourceApp errorSourceApp trade|rpc + * @param errorSources errorSources */ public void reportError(String errorType, Map context, Throwable e, String errorSourceApp, String... errorSources) { Tags.ERROR.set(this, true); - //关键:用于记录所有的持久化数据 + //all tags set Map tags = new HashMap(); tags.putAll(this.getTagsWithStr()); tags.putAll(this.getTagsWithBool()); tags.putAll(this.getTagsWithNumber()); tags.put(SpanTags.CURR_APP_TAG.getKey(), errorSourceApp); - //构造新的 + //Construct new CommonLogSpan CommonLogSpan commonLogSpan = new CommonLogSpan(this.sofaTracer, System.currentTimeMillis(), this.getOperationName(), this.getSofaTracerSpanContext(), tags); commonLogSpan.addSlot(Thread.currentThread().getName()); commonLogSpan.addSlot(errorType); - // 业务定制的输出中可能会有分隔符,现在将分割符替换成相应的转义字符 + // There may be a separator in the output of the business customization, now replace the separator with the corresponding escape character commonLogSpan.addSlot(StringUtils.arrayToString(errorSources, ARRAY_SEPARATOR, "", "")); commonLogSpan.addSlot(StringUtils.mapToString(context)); commonLogSpan.addSlot(this.getSofaTracerSpanContext() == null ? StringUtils.EMPTY_STRING @@ -329,29 +316,25 @@ public void reportError(String errorType, Map context, Throwable } else { StringWriter sw = new StringWriter(256); e.printStackTrace(new PrintWriter(sw)); - // 同上 String exception = sw.getBuffer().toString(); commonLogSpan.addSlot(exception); } - //report error 使用客户端服务端tags进行区分 CommonTracerManager.reportError(commonLogSpan); } /** - * 打印 Common Profile 日志 + * Print Common Profile Log * - * @param profileApp profile 应用 - * @param protocolType 协议类型 - * @param profileMessage 日志内容 + * @param profileApp profileApp + * @param protocolType protocolType + * @param profileMessage profileMessage */ public void profile(String profileApp, String protocolType, String profileMessage) { - //关键:用于记录所有的持久化数据 Map tags = new HashMap(); tags.putAll(this.getTagsWithStr()); tags.putAll(this.getTagsWithBool()); tags.putAll(this.getTagsWithNumber()); tags.put(SpanTags.CURR_APP_TAG.getKey(), profileApp); - //构造新的,关键:用于记录所有的持久化数据 CommonLogSpan commonLogSpan = new CommonLogSpan(this.sofaTracer, System.currentTimeMillis(), this.getOperationName(), this.getSofaTracerSpanContext(), tags); @@ -363,26 +346,27 @@ public void profile(String profileApp, String protocolType, String profileMessag } /** - * 返回自身作为下一个上下文的 parent + * Return itself as the parent of the next context *

- * 采用 countMatches 来对 . 进行计数, 以获取更高的性能, 见com.alipay.common.tracer.benchmark.CountBenchmark 的性能测试数据 - * 防止 SofaTracerSpan 嵌套过深导致内存泄漏。这个时候重新创建一个上下文,使上面的上下文都能够释放。 - * - * @return 重新构造的 span + * Use countMatches to count . for higher performance, see performance test data for com.alipay.common.tracer.benchmark.CountBenchmark + + * Preventing SofaTracerSpan from nesting too deeply causes a memory leak. + * This time recreates a context so that the above context can be released. + *

+ * @return */ public SofaTracerSpan getThisAsParentWhenExceedLayer() { final SofaTracerSpan parent; String rpcId = this.sofaTracerSpanContext.getSpanId(); if (StringUtils.countMatches(rpcId, '.') + 1 > SofaTracerConstant.MAX_LAYER) { SofaTracerSpanContext parentSpanContext = SofaTracerSpanContext.rootStart(); - // 虽然重新创建一个 Span, 但是穿透数据没有必要丢掉;但是丢弃 tags + // discard tags Map baggage = new HashMap(); baggage.putAll(this.sofaTracerSpanContext.getBizBaggage()); parentSpanContext.addBizBaggage(baggage); - //重新构造 parent = new SofaTracerSpan(this.sofaTracer, System.currentTimeMillis(), this.operationName, parentSpanContext, null); - // 在日志中进行记录, 防止发生了这个情况却无法快速知晓 + // Record in the log to prevent this from happening but not to know quickly SelfLog.errorWithTraceId("OpenTracing Span layer exceed max layer limit " + SofaTracerConstant.MAX_LAYER, this.sofaTracerSpanContext.getTraceId()); @@ -393,7 +377,7 @@ public SofaTracerSpan getThisAsParentWhenExceedLayer() { return parent; } - //=======================扩展的 API 接口结束 + //======================= Extended API interface end public List getSpanReferences() { if (spanReferences == null) { @@ -491,7 +475,6 @@ private void setTags(Map tags) { continue; } if (value instanceof String) { - //初始化时候,tags也可以作为 client 和 server 的判断依据 this.setTag(key, (String) value); } else if (value instanceof Boolean) { this.setTag(key, (Boolean) value); diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpanReferenceRelationship.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpanReferenceRelationship.java index e999d9fc..733c6d90 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpanReferenceRelationship.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpanReferenceRelationship.java @@ -24,7 +24,7 @@ * SofaTracerSpanReferenceRelationship *

* {@link io.opentracing.References} - * + *

* @author yangguanchao * @since 2017/06/17 */ @@ -32,7 +32,7 @@ public class SofaTracerSpanReferenceRelationship { private SofaTracerSpanContext sofaTracerSpanContext; - /*** + /** * {@link io.opentracing.References} */ private String referenceType; diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/tags/SpanTags.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/tags/SpanTags.java index 4e57dce4..14fd5a9c 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/tags/SpanTags.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/tags/SpanTags.java @@ -26,8 +26,8 @@ */ public class SpanTags { - /*** - * 当前应用名称 + /** + * current span tags */ public static final StringTag CURR_APP_TAG = new StringTag("curr.app"); } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/tracer/AbstractTracer.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/tracer/AbstractTracer.java index 74307df2..73f6afe3 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/tracer/AbstractTracer.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/tracer/AbstractTracer.java @@ -50,7 +50,6 @@ public AbstractTracer(String tracerType) { public AbstractTracer(String tracerType, boolean clientTracer, boolean serverTracer) { SofaTracer.Builder builder = new SofaTracer.Builder(tracerType); - //构造 client 的日志打印实例 if (clientTracer) { Reporter clientReporter = this.generateReporter(this.generateClientStatReporter(), this.getClientDigestReporterLogName(), this.getClientDigestReporterRollingKey(), @@ -59,7 +58,6 @@ public AbstractTracer(String tracerType, boolean clientTracer, boolean serverTra builder.withClientReporter(clientReporter); } } - //构造 server 的日志打印实例 if (serverTracer) { Reporter serverReporter = this.generateReporter(this.generateServerStatReporter(), this.getServerDigestReporterLogName(), this.getServerDigestReporterRollingKey(), @@ -75,10 +73,8 @@ public AbstractTracer(String tracerType, boolean clientTracer, boolean serverTra protected Reporter generateReporter(AbstractSofaTracerStatisticReporter statReporter, String logName, String logRollingKey, String logNameKey, SpanEncoder spanEncoder) { - //构造摘要实例 String digestRollingPolicy = SofaTracerConfiguration.getRollingPolicy(logRollingKey); String digestLogReserveConfig = SofaTracerConfiguration.getLogReserveConfig(logNameKey); - //构造实例 DiskReporterImpl reporter = new DiskReporterImpl(logName, digestRollingPolicy, digestLogReserveConfig, spanEncoder, statReporter, logNameKey); return reporter; @@ -197,7 +193,7 @@ public SofaTracerSpan serverReceive() { /** * server receive request - * @param sofaTracerSpanContext 要恢复的上下文 + * @param sofaTracerSpanContext The context to restore * @return SofaTracerSpan */ public SofaTracerSpan serverReceive(SofaTracerSpanContext sofaTracerSpanContext) { diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/ByteArrayUtils.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/ByteArrayUtils.java index ae970ac9..5783a644 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/ByteArrayUtils.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/ByteArrayUtils.java @@ -25,51 +25,37 @@ public class ByteArrayUtils { /** - * 查找指定数组的起始索引 + * Find the starting index of the specified array * - * @param org of type byte[] 原数组 - * @param search of type byte[] 要查找的数组 - * @return int 返回索引 + * @param org of type byte[] origin byte array + * @param search of type byte[] target array + * @return */ - public static int indexOf(byte[] org, byte[] search) { - return indexOf(org, search, 0); - } /** - * 查找指定数组的起始索引 + * Find the starting index of the specified array * - * @param org of type byte[] 原数组 - * @param search of type byte[] 要查找的数组 - * @param startIndex 起始索引 - * @return int 返回索引 + * @param org of type byte[] origin byte array + * @param search of type byte[] target array + * @param startIndex startIndex + * @return */ - public static int indexOf(byte[] org, byte[] search, int startIndex) { - KMPMatcher kmpMatcher = new KMPMatcher(); - kmpMatcher.computeFailure4Byte(search); - return kmpMatcher.indexOf(org, startIndex); } /** - * KMP算法类 - *

- *

- *

+ * KMP * Created on 2017-08-04 */ - static class KMPMatcher { - private int[] failure; - private int matchPoint; - private byte[] bytePattern; /** @@ -79,113 +65,69 @@ static class KMPMatcher { * @param startIndex of type int * @return int */ - public int indexOf(byte[] text, int startIndex) { - int j = 0; - if (text.length == 0 || startIndex > text.length) { return -1; } - for (int i = startIndex; i < text.length; i++) { - while (j > 0 && bytePattern[j] != text[i]) { - j = failure[j - 1]; - } - if (bytePattern[j] == text[i]) { - j++; - } - if (j == bytePattern.length) { - matchPoint = i - bytePattern.length + 1; - return matchPoint; - } - } - return -1; } /** - * 找到末尾后重头开始找 + * After finding the end, start looking for it again. * * @param text of type byte[] * @param startIndex of type int * @return int */ - public int lastIndexOf(byte[] text, int startIndex) { - matchPoint = -1; - int j = 0; - if (text.length == 0 || startIndex > text.length) { return -1; } - int end = text.length; - for (int i = startIndex; i < end; i++) { - while (j > 0 && bytePattern[j] != text[i]) { - j = failure[j - 1]; - } - if (bytePattern[j] == text[i]) { - j++; - } - if (j == bytePattern.length) { - matchPoint = i - bytePattern.length + 1; - if ((text.length - i) > bytePattern.length) { - j = 0; - continue; - } - return matchPoint; - } - - //如果从中间某个位置找,找到末尾没找到后,再重头开始找 - + //If you find it from a position in the middle, if you don’t find it at the end, then start looking for it again. if (startIndex != 0 && i + 1 == end) { - end = startIndex; - i = -1; - startIndex = 0; - } - } - return matchPoint; - } /** - * 找到末尾后不会重头开始找 + * + * It won’t start looking for it after find the end. * * @param text of type byte[] * @param startIndex of type int @@ -193,86 +135,48 @@ public int lastIndexOf(byte[] text, int startIndex) { */ public int lastIndexOfWithNoLoop(byte[] text, int startIndex) { - matchPoint = -1; - int j = 0; - if (text.length == 0 || startIndex > text.length) { return -1; } - for (int i = startIndex; i < text.length; i++) { - while (j > 0 && bytePattern[j] != text[i]) { - j = failure[j - 1]; - } - if (bytePattern[j] == text[i]) { - j++; - } - if (j == bytePattern.length) { - matchPoint = i - bytePattern.length + 1; - if ((text.length - i) > bytePattern.length) { - j = 0; - continue; - } - return matchPoint; - } - } - return matchPoint; - } /** * Method computeFailure4Byte … - * * @param patternStr of type byte[] */ - public void computeFailure4Byte(byte[] patternStr) { - bytePattern = patternStr; - int j = 0; - int len = bytePattern.length; - failure = new int[len]; - for (int i = 1; i < len; i++) { - while (j > 0 && bytePattern[j] != bytePattern[i]) { - j = failure[j - 1]; - } - if (bytePattern[j] == bytePattern[i]) { - j++; - } - failure[i] = j; - } - } - } } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/CommonUtils.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/CommonUtils.java index bd3a3351..a0111c9a 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/CommonUtils.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/CommonUtils.java @@ -27,24 +27,23 @@ public class CommonUtils { private static int LONG_BYTES = Long.SIZE / 8; private static int LONG_HEX_STRING_BYTES = LONG_BYTES * 2; - /*** - * 取数值 - * @param num 数字 - * @param defaultInt 默认值 - * @param 类型 Number - * @return Number + /** + * Take the value + * @param num + * @param defaultInt + * @param Number + * @return T */ public static T parseNum(T num, T defaultInt) { return num == null ? defaultInt : num; } - /*** + /** * Convert a hex string to a array containing two unsigned long elements * @param hexString hex string * @return long array: [0] -- High 64 bit, [1] -- low 64 bit */ public static long[] hexToDualLong(String hexString) { - //Assert.hasText(hexString, "Can't convert empty hex string to long"); int length = hexString.length(); if (length < 1) { throw new IllegalArgumentException("Malformed id(length must be more than zero): " @@ -76,13 +75,12 @@ public static long[] hexToDualLong(String hexString) { return result; } - /*** + /** * Convert a hex string to a unsigned long * @param hexString hex string * @return long */ public static long hexToLong(String hexString) { - //Assert.hasText(hexString, "Can't convert empty hex string to long"); int length = hexString.length(); if (length < 1) { throw new IllegalArgumentException("Malformed id(length must be more than zero): " @@ -106,7 +104,7 @@ public static long hexToLong(String hexString) { return result; } - /*** + /** * Judge if a string is hex string * @param str string * @return boolean diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/ReflectionUtils.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/ReflectionUtils.java index 49b7c3ea..8eea9a40 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/ReflectionUtils.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/ReflectionUtils.java @@ -17,10 +17,7 @@ package com.alipay.common.tracer.core.utils; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; /** * @author qilong.zql diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/StringUtils.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/StringUtils.java index 38f57b84..4b8facce 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/StringUtils.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/StringUtils.java @@ -57,11 +57,6 @@ public class StringUtils { private static final String CURRENT_PATH = "."; - /*** - * 字符串是否为空 - * @param str 字符串 - * @return true : 字符串为空 - */ public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { @@ -75,23 +70,16 @@ public static boolean isBlank(String str) { return true; } - /** - * 字符串是否不为空 - * - * @param str 字符串 - * @return true : 非空 - */ public static boolean isNotBlank(String str) { return !isBlank(str); } /** - *

- * 将map转成string并在每一个 key 添加指定的前缀, 如 {"k1":"v1"} - *

- * @param map map 要映射的集合 - * @param prefix prefix 前缀 - * @return 字符串携带指定前缀 prefix_k1=v1 + * Convert the map to a string and add the specified prefix to each key, such as {"k1":"v1"} + * + * @param map origin data + * @param prefix prefix + * @return */ public static String mapToStringWithPrefix(Map map, String prefix) { StringBuilder sb = new StringBuilder(XStringBuilder.DEFAULT_BUFFER_SIZE); @@ -113,11 +101,10 @@ public static String mapToStringWithPrefix(Map map, String prefi } /** - *

- * 将map转成string, 如{"k1":"v1"} - *

- * @param map 要映射的集合 - * @return 字符串 k1=v1 + * Convert the map to a string, such as {"k1":"v1"} + * + * @param map origin data + * @return */ public static String mapToString(Map map) { StringBuilder sb = new StringBuilder(XStringBuilder.DEFAULT_BUFFER_SIZE); @@ -136,16 +123,14 @@ public static String mapToString(Map map) { } /** - * 由string转成map, 函数 mapToString 的逆过程 - * @param str 字符串 - * @param map 映射的集合 + * Convert from string to map, the inverse of the function mapToString + * @param str origin data + * @param map default result */ public static void stringToMap(String str, Map map) { - if (isBlank(str)) { return; } - String key = null; String value = null; int mark = -1; @@ -188,15 +173,15 @@ public static String unescapeComma(String str) { } /** - * @param items 列表 - * @param separator 分隔符 - * @param prefix 前缀 - * @param postfix 后缀 - * @return 字符串 + * Array to string + * @param items origin data + * @param separator separator + * @param prefix prefix + * @param postfix postfix + * @return */ public static String arrayToString(Object[] items, char separator, String prefix, String postfix) { String emptyArrayString = (EMPTY_STRING + prefix) + postfix; - // handle null, zero and one elements before building a buffer if (items == null) { return emptyArrayString; @@ -231,24 +216,34 @@ public static String arrayToString(Object[] items, char separator, String prefix return buf.toString(); } - //替换str中的"&","=" 和 "%" + /** + * Replace "&"、"=" and "%" + * @param str origin data + */ public static String escapePercentEqualAnd(String str) { - // 必须先对 % 做转义 + //You must first escape the % return escape( escape(escape(str, PERCENT, PERCENT_ESCAPE), AND_SEPARATOR, AND_SEPARATOR_ESCAPE), EQUAL_SEPARATOR, EQUAL_SEPARATOR_ESCAPE); } - //将 str 中被转义的 & , = 和 % 转义回来 + /** + * escapePercentEqualAnd's Reverse Operation + * @param str + * @return + */ public static String unescapeEqualAndPercent(String str) { - // 必须最后才对 % 做转义 + // You must first escape the % return escape( escape(escape(str, EQUAL_SEPARATOR_ESCAPE, EQUAL_SEPARATOR), AND_SEPARATOR_ESCAPE, AND_SEPARATOR), PERCENT_ESCAPE, PERCENT); } /** - * 将str中的oldStr替换为newStr + * Replace oldStr in str with newStr + * @param str target origin data + * @param oldStr oldStr + * @param newStr newStr */ private static String escape(String str, String oldStr, String newStr) { if (str == null) { @@ -468,25 +463,23 @@ public static String replace(String inString, String oldPattern, String newPatte return sb.toString(); } - /*** - * 对指定的字符串中出现的字符进行计数 - * @param str 要被统计的字符串 - * @param c 出现的字符 - * @return 个数 + /** + * Counts the characters that appear in the specified string + * + * @param str target str + * @param c target char c + * @return */ public static int countMatches(String str, char c) { if (str == null || str.length() == 0) { return 0; } - int count = 0; - for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == c) { count++; } } - return count; } diff --git a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/TracerUtils.java b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/TracerUtils.java index 8e4021b1..2de717cd 100644 --- a/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/TracerUtils.java +++ b/tracer-core/src/main/java/com/alipay/common/tracer/core/utils/TracerUtils.java @@ -30,7 +30,7 @@ import java.util.TimeZone; /** - * Tracer 的工具类,此工具类是一个内部工具类,非 Tracer 相关 JAR 包请不要依赖。 + * Tracer's tool class, this tool class is an internal tool class, please do not rely on non-Tracer related JAR packages. * * @author khotyn 4/4/14 1:39 PM */ @@ -71,10 +71,10 @@ public static String getTraceId() { } /** - * @param sofaTracerSpan 要检验的 span - * @param key 关键字 + * @param sofaTracerSpan sofaTracerSpan + * @param key key * @param value value - * @return true 满足长度要求 + * @return */ public static boolean checkBaggageLength(SofaTracerSpan sofaTracerSpan, String key, String value) { int length = sofaTracerSpan.getSofaTracerSpanContext().getBizSerializedBaggage().length(); @@ -90,9 +90,9 @@ public static boolean checkBaggageLength(SofaTracerSpan sofaTracerSpan, String k } /** - * 系统穿透数据长度可以通过不同的-D来设置 + * System penetration data length can be set by different -D parameters * - * @return 整数值 + * @return */ public static int getSysBaggageMaxLength() { if (TRACER_SYSTEM_PENETRATE_ATTRIBUTE_MAX_LENGTH < 0) { @@ -131,11 +131,12 @@ public static int getBaggageMaxLength() { } /** - * 此方法在 JDK9 下可以有更加好的方式,但是目前的几个 JDK 版本下,只能通过这个方式来搞。 - * 在 Mac 环境下,JDK6,JDK7,JDK8 都可以跑过。 - * 在 Linux 环境下,JDK6,JDK7,JDK8 尝试过,可以运行通过。 + * This method can be a better way under JDK9, but in the current JDK version, it can only be implemented in this way. * - * @return 进程 ID + * In Mac OS , JDK6,JDK7,JDK8 ,it's OK + * In Linux OS,JDK6,JDK7,JDK8 ,it's OK + * + * @return Process ID */ public static String getPID() { //check pid is cached @@ -202,7 +203,7 @@ public static String getLoadTestMark(SofaTracerSpan span) { if (TracerUtils.isLoadTest(span)) { return SofaTracerConstant.LOAD_TEST_VALUE; } else { - //非压测 + //non-pressure test return SofaTracerConstant.NON_LOAD_TEST_VALUE; } } @@ -231,13 +232,10 @@ public static String removeJSessionIdFromUrl(String url) { if (url == null) { return null; } - int index = url.indexOf(";jsessionid="); - if (index < 0) { return url; } - return url.substring(0, index); } @@ -250,11 +248,11 @@ public static String getDefaultTimeZone() { } /** - * 从 Map 中获取一个 value,如果获取出来是 null,则返回一个空字符串 + * Get a value from the Map, or return an empty string if it is null * - * @param map 要映射的 map - * @param key 关键字 - * @return 字符串 + * @param map map + * @param key key + * @return */ public static String getEmptyStringIfNull(Map map, String key) { String value = map.get(key); @@ -262,10 +260,10 @@ public static String getEmptyStringIfNull(Map map, String key) { } /** - * 将一个 Host 地址转换成一个 16 进制数字 + * Convert a Host address to a hexadecimal number * - * @param host 主机地址 - * @return 将一个 Host 地址转换成一个 16 进制数字 + * @param host host address + * @return hexadecimal number */ public static String hostToHexString(String host) { //NOPMD return Integer.toHexString(host.hashCode()); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/TestUtil.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/TestUtil.java index 9c246dfc..b744e667 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/TestUtil.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/TestUtil.java @@ -32,17 +32,14 @@ public static boolean compareSlotMap(String a, String b) { StringUtils.stringToMap(a, aMap); Map bMap = new HashMap(); StringUtils.stringToMap(b, bMap); - if (aMap.size() != bMap.size()) { return false; } - for (String aKey : aMap.keySet()) { if (!aMap.get(aKey).equals(bMap.get(aKey))) { return false; } } - return true; } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/LogCleanupTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/LogCleanupTest.java index 26eda294..631f621a 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/LogCleanupTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/LogCleanupTest.java @@ -27,9 +27,9 @@ import java.util.Calendar; /** - * 测试日志的清理功能 + * Test log cleanup function * - * @author khotyn 15/2/16 下午3:50 + * @author khotyn 15/2/16 PM 3:50 */ public class LogCleanupTest extends AbstractTestBase { @@ -42,41 +42,37 @@ public class LogCleanupTest extends AbstractTestBase { private File fiveDayAgoFile = null; @Test - public void 测试清理日志_按天滚动() throws IOException { + public void test_cleanup_log_scroll_by_day() throws IOException { generateLogFilesToBeCleanup(new SimpleDateFormat( TimedRollingFileAppender.DAILY_ROLLING_PATTERN)); TraceAppender appender = new TimedRollingFileAppender(CLEAN_UP_TEST_LOG, TimedRollingFileAppender.DAILY_ROLLING_PATTERN, "3"); appender.cleanup(); - Assert.assertTrue("今天的日志应该还是存在", todayFile.exists()); - Assert.assertTrue("昨天的日志应该还是存在", yesterdayFile.exists()); - Assert.assertTrue("两天前的日志应该还是存在", twoDayAgoFile.exists()); - Assert.assertTrue("三天前的日志应该还是存在", threeDayAgoFile.exists()); - Assert.assertTrue("四天前的日志应该不存在", !fourDayAgoFile.exists()); - Assert.assertTrue("五天前的日志应该不存在", !fiveDayAgoFile.exists()); + Assert.assertTrue("Today's log should still exist", todayFile.exists()); + Assert.assertTrue("Yesterday's log should still exist", yesterdayFile.exists()); + Assert.assertTrue("The log two days ago should still exist", twoDayAgoFile.exists()); + Assert.assertTrue("The log three days ago should still exist", threeDayAgoFile.exists()); + Assert.assertTrue("The log four days ago should not exist", !fourDayAgoFile.exists()); + Assert.assertTrue("The log five days ago should not exist", !fiveDayAgoFile.exists()); } @Test - public void 测试清理日志_按小时滚() throws IOException { + public void test_cleanup_log_scroll_by_hour() throws IOException { generateLogFilesToBeCleanup(new SimpleDateFormat( TimedRollingFileAppender.HOURLY_ROLLING_PATTERN)); TraceAppender appender = new TimedRollingFileAppender(CLEAN_UP_TEST_LOG, TimedRollingFileAppender.HOURLY_ROLLING_PATTERN, "2"); appender.cleanup(); - Assert.assertTrue("今天的日志应该还是存在", todayFile.exists()); - Assert.assertTrue("昨天的日志应该还是存在", yesterdayFile.exists()); - Assert.assertTrue("两天前的日志应该还是存在", twoDayAgoFile.exists()); - Assert.assertTrue("三天前的日志应该还是存在", !threeDayAgoFile.exists()); - Assert.assertTrue("四天前的日志应该不存在", !fourDayAgoFile.exists()); - Assert.assertTrue("五天前的日志应该不存在", !fiveDayAgoFile.exists()); + Assert.assertTrue("Today's log should still exist", todayFile.exists()); + Assert.assertTrue("Yesterday's log should still exist", yesterdayFile.exists()); + Assert.assertTrue("The log two days ago should still exist", twoDayAgoFile.exists()); + Assert.assertTrue("The log three days ago should not exist", !threeDayAgoFile.exists()); + Assert.assertTrue("The log four days ago should not exist", !fourDayAgoFile.exists()); + Assert.assertTrue("The log five days ago should not exist", !fiveDayAgoFile.exists()); } - /*** - * 测试按小时清理日志_按小时滚动_两小时 - * @throws IOException exception - */ @Test public void rolling_by_two_hour() throws IOException { generateLogFilesToBeCleanupHourly(new SimpleDateFormat( @@ -85,18 +81,14 @@ public void rolling_by_two_hour() throws IOException { TimedRollingFileAppender.HOURLY_ROLLING_PATTERN, "0D2H"); appender.cleanup(); - Assert.assertTrue("这个小时前的日志应该还是存在", todayFile.exists()); - Assert.assertTrue("一个小时前的日志应该还是存在", yesterdayFile.exists()); - Assert.assertTrue("两个小时前的日志应该还是存在", twoDayAgoFile.exists()); - Assert.assertTrue("三个小时前的日志应该不存在", !threeDayAgoFile.exists()); - Assert.assertTrue("四个小时前的日志应该不存在", !fourDayAgoFile.exists()); - Assert.assertTrue("五个小时前的日志应该不存在", !fiveDayAgoFile.exists()); + Assert.assertTrue("The log before this hour should still exist", todayFile.exists()); + Assert.assertTrue("The log An hour ago should still exist", yesterdayFile.exists()); + Assert.assertTrue("The log two hours ago should still exist", twoDayAgoFile.exists()); + Assert.assertTrue("The log three hours ago should not exist", !threeDayAgoFile.exists()); + Assert.assertTrue("The log four hours ago should not exist", !fourDayAgoFile.exists()); + Assert.assertTrue("The log five hours ago should not exist", !fiveDayAgoFile.exists()); } - /*** - * 测试按小时清理日志_按小时滚动_三小时 - * @throws IOException - */ @Test public void rolling_by_three_hour() throws IOException { generateLogFilesToBeCleanupHourly(new SimpleDateFormat( @@ -105,12 +97,12 @@ public void rolling_by_three_hour() throws IOException { TimedRollingFileAppender.HOURLY_ROLLING_PATTERN, "0D3H"); appender.cleanup(); - Assert.assertTrue("这个小时前的日志应该还是存在", todayFile.exists()); - Assert.assertTrue("一个小时前的日志应该还是存在", yesterdayFile.exists()); - Assert.assertTrue("两个小时前的日志应该还是存在", twoDayAgoFile.exists()); - Assert.assertTrue("三个小时前的日志应该还是存在", threeDayAgoFile.exists()); - Assert.assertTrue("四个小时前的日志应该不存在", !fourDayAgoFile.exists()); - Assert.assertTrue("五个小时前的日志应该不存在", !fiveDayAgoFile.exists()); + Assert.assertTrue("The log before this hour should still exist", todayFile.exists()); + Assert.assertTrue("The log An hour ago should still exist", yesterdayFile.exists()); + Assert.assertTrue("The log two hours ago should still exist", twoDayAgoFile.exists()); + Assert.assertTrue("The log three hours ago should still exist", threeDayAgoFile.exists()); + Assert.assertTrue("The log four hours ago should not exist", !fourDayAgoFile.exists()); + Assert.assertTrue("The log five hours ago should not exist", !fiveDayAgoFile.exists()); } private void generateLogFilesToBeCleanupHourly(SimpleDateFormat sdf) throws IOException { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonTest.java index 2e3038da..28c293e9 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/TracerLogRootDaemonTest.java @@ -29,7 +29,7 @@ * * @author * @version 1.0 - * @since
七月 24, 2017
+ * @since
July 24, 2017
*/ public class TracerLogRootDaemonTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilderTest.java index 0a8e3afa..ef04f3f6 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/JsonStringBuilderTest.java @@ -30,7 +30,7 @@ * * @author * @version 1.0 - * @since
五月 14, 2018
+ * @since
May 14, 2018
*/ public class JsonStringBuilderTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/XStringBuilderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/XStringBuilderTest.java index baab4062..c3f97113 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/XStringBuilderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/builder/XStringBuilderTest.java @@ -30,12 +30,12 @@ * * @author * @version 1.0 - * @since
七月 12, 2017
+ * @since
July 12, 2017
*/ public class XStringBuilderTest { - /*** - * 测试_appendEndMap_逗号被转义 + /** + * Test appendEndMap comma is escaped */ @Test public void appendEndMapTransferredMeaning() { @@ -49,8 +49,8 @@ public void appendEndMapTransferredMeaning() { @Test public void testXStringBuilderAppender() { XStringBuilder xStringBuilder = new XStringBuilder(128); - xStringBuilder.append(1l, ","); - xStringBuilder.append(1l, ','); + xStringBuilder.append(1L, ","); + xStringBuilder.append(1L, ','); xStringBuilder.append("test1", ","); Map map = new HashMap(); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppenderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppenderTest.java index f2d3ae01..ef3c9705 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppenderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/file/TimedRollingFileAppenderTest.java @@ -58,12 +58,13 @@ public void test() throws IOException, InterruptedException { Resource[] resources = resolver.getResources("file:" + TracerLogRootDaemon.LOG_FILE_DIR + File.separator + ROLLING_TEST_FILE_NAME + "*"); - Assert.assertTrue("文件的数量不正确,以 " + ROLLING_TEST_FILE_NAME + " 为开头的文件数量应该是 2 个", - resources.length == 2); + Assert.assertTrue("The number of files is incorrect. The number of files starting with " + + ROLLING_TEST_FILE_NAME + " should be 2", resources.length == 2); for (Resource resource : resources) { String c = FileUtils.readFileToString(resource.getFile()); - Assert.assertEquals("文件 " + resource.getFilename() + " 中的内容不正确", content, c); + Assert.assertEquals("File content in " + resource.getFilename() + " is incorrect", + content, c); } } } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/info/StaticInfoLogTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/info/StaticInfoLogTest.java index cf9d2d3d..404d3624 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/info/StaticInfoLogTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/info/StaticInfoLogTest.java @@ -37,7 +37,7 @@ * * @author * @version 1.0 - * @since
七月 2, 2017
+ * @since
July 2, 2017
*/ public class StaticInfoLogTest extends AbstractTestBase { @@ -45,7 +45,7 @@ public class StaticInfoLogTest extends AbstractTestBase { public void testLogStaticInfo() throws IOException, InterruptedException, NoSuchFieldException, IllegalAccessException { - //记录 + //record reflect(); StaticInfoLog.logStaticInfo(); @@ -57,7 +57,7 @@ public void testLogStaticInfo() throws IOException, InterruptedException, NoSuch params.add(TracerUtils.getCurrentZone()); params.add(TracerUtils.getDefaultTimeZone()); List contents = FileUtils.readLines(customFileLog("static-info.log")); - Assert.assertFalse("静态信息日志没有内容", contents.isEmpty()); + Assert.assertFalse("Static information log has no content", contents.isEmpty()); assertTrue(checkResult(params, contents.get(0))); } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentConsumerCorrectTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentConsumerCorrectTest.java index 6aada06a..b76519c5 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentConsumerCorrectTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentConsumerCorrectTest.java @@ -37,7 +37,7 @@ /** * * @author liangen - * @version $Id: ConcurrentConsumerCorrectTest.java, v 0.1 2017年10月23日 下午3:01 liangen Exp $ + * @version $Id: ConcurrentConsumerCorrectTest.java, v 0.1 October 23, 2017 3:01 PM liangen Exp $ */ public class ConcurrentConsumerCorrectTest { @@ -61,7 +61,7 @@ public void clean() throws Exception { @Test public void testConcurrentConsumerCorrect() throws InterruptedException, IOException { - /**不允许丢失日志,避免日志丢失影响结果校验的正确性*/ + /** Logs are not allowed to be lost, and log loss is avoided to affect the correctness of the result check. */ SofaTracerConfiguration.setProperty( SofaTracerConfiguration.TRACER_ASYNC_APPENDER_ALLOW_DISCARD, "false"); @@ -90,65 +90,55 @@ public void testConcurrentConsumerCorrect() throws InterruptedException, IOExcep final CountDownLatch countDownLatch = new CountDownLatch(30); for (int i = 0; i < 20; i++) { - new Thread(new Runnable() { - @Override - public void run() { - - SofaTracerSpan span1 = ManagerTestUtil.createSofaTracerSpan(1); - for (int j = 0; j < 30; j++) { - asyncCommonDigestAppenderManager.append(span1); - } - - SofaTracerSpan span2 = ManagerTestUtil.createSofaTracerSpan(2); - for (int j = 0; j < 40; j++) { - asyncCommonDigestAppenderManager.append(span2); - } - - SofaTracerSpan span3 = ManagerTestUtil.createSofaTracerSpan(3); - for (int j = 0; j < 50; j++) { - asyncCommonDigestAppenderManager.append(span3); - } - - SofaTracerSpan span4 = ManagerTestUtil.createSofaTracerSpan(4); - for (int j = 0; j < 60; j++) { - asyncCommonDigestAppenderManager.append(span4); - } - - SofaTracerSpan span5 = ManagerTestUtil.createSofaTracerSpan(5); - for (int j = 0; j < 70; j++) { - asyncCommonDigestAppenderManager.append(span5); - } - - countDownLatch.countDown(); + new Thread(()->{ + SofaTracerSpan span1 = ManagerTestUtil.createSofaTracerSpan(1); + for (int j = 0; j < 30; j++) { + asyncCommonDigestAppenderManager.append(span1); } + + SofaTracerSpan span2 = ManagerTestUtil.createSofaTracerSpan(2); + for (int j = 0; j < 40; j++) { + asyncCommonDigestAppenderManager.append(span2); + } + + SofaTracerSpan span3 = ManagerTestUtil.createSofaTracerSpan(3); + for (int j = 0; j < 50; j++) { + asyncCommonDigestAppenderManager.append(span3); + } + + SofaTracerSpan span4 = ManagerTestUtil.createSofaTracerSpan(4); + for (int j = 0; j < 60; j++) { + asyncCommonDigestAppenderManager.append(span4); + } + + SofaTracerSpan span5 = ManagerTestUtil.createSofaTracerSpan(5); + for (int j = 0; j < 70; j++) { + asyncCommonDigestAppenderManager.append(span5); + } + + countDownLatch.countDown(); }).start(); } for (int i = 0; i < 10; i++) { - new Thread(new Runnable() { - @Override - public void run() { - - SofaTracerSpan span1 = ManagerTestUtil.createSofaTracerSpan(1); - SofaTracerSpan span2 = ManagerTestUtil.createSofaTracerSpan(2); - SofaTracerSpan span3 = ManagerTestUtil.createSofaTracerSpan(3); - SofaTracerSpan span4 = ManagerTestUtil.createSofaTracerSpan(4); - SofaTracerSpan span5 = ManagerTestUtil.createSofaTracerSpan(5); - - for (int j = 0; j < 40; j++) { - asyncCommonDigestAppenderManager.append(span1); - asyncCommonDigestAppenderManager.append(span2); - asyncCommonDigestAppenderManager.append(span3); - asyncCommonDigestAppenderManager.append(span4); - asyncCommonDigestAppenderManager.append(span5); - } - - countDownLatch.countDown(); + new Thread(()->{ + SofaTracerSpan span1 = ManagerTestUtil.createSofaTracerSpan(1); + SofaTracerSpan span2 = ManagerTestUtil.createSofaTracerSpan(2); + SofaTracerSpan span3 = ManagerTestUtil.createSofaTracerSpan(3); + SofaTracerSpan span4 = ManagerTestUtil.createSofaTracerSpan(4); + SofaTracerSpan span5 = ManagerTestUtil.createSofaTracerSpan(5); + for (int j = 0; j < 40; j++) { + asyncCommonDigestAppenderManager.append(span1); + asyncCommonDigestAppenderManager.append(span2); + asyncCommonDigestAppenderManager.append(span3); + asyncCommonDigestAppenderManager.append(span4); + asyncCommonDigestAppenderManager.append(span5); } + countDownLatch.countDown(); }).start(); } - /**校验*/ + /** check */ countDownLatch.await(); Thread.sleep(3000); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentDiscardTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentDiscardTest.java index 09d39136..9395d0c7 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentDiscardTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ConcurrentDiscardTest.java @@ -40,7 +40,7 @@ /** * * @author liangen - * @version $Id: ConcurrentDiscardTest.java, v 0.1 2017年10月23日 下午8:22 liangen Exp $ + * @version $Id: ConcurrentDiscardTest.java, v 0.1 October 23, 2017 8:22 PM liangen Exp $ */ public class ConcurrentDiscardTest { static final String fileNameRoot = TracerLogRootDaemon.LOG_FILE_DIR + File.separator; @@ -120,40 +120,35 @@ public void testConcurrentDiscard() throws InterruptedException, IOException { final CountDownLatch countDownLatch = new CountDownLatch(50); for (int i = 0; i < 50; i++) { - new Thread(new Runnable() { - @Override - public void run() { - SofaTracerSpan span1 = ManagerTestUtil.createSofaTracerSpan(1); - SofaTracerSpan span2 = ManagerTestUtil.createSofaTracerSpan(2); - SofaTracerSpan span3 = ManagerTestUtil.createSofaTracerSpan(3); - SofaTracerSpan span4 = ManagerTestUtil.createSofaTracerSpan(4); - SofaTracerSpan span5 = ManagerTestUtil.createSofaTracerSpan(5); - - for (int j = 0; j < 100; j++) { - if (!asyncCommonDigestAppenderManager.append(span1)) { - discardNum.incrementAndGet(); - } - if (!asyncCommonDigestAppenderManager.append(span2)) { - discardNum.incrementAndGet(); - } - if (!asyncCommonDigestAppenderManager.append(span3)) { - discardNum.incrementAndGet(); - } - if (!asyncCommonDigestAppenderManager.append(span4)) { - discardNum.incrementAndGet(); - } - if (!asyncCommonDigestAppenderManager.append(span5)) { - discardNum.incrementAndGet(); - } - try { - Thread.sleep(10); - } catch (InterruptedException e) { - e.printStackTrace(); - } + new Thread(()-> { + SofaTracerSpan span1 = ManagerTestUtil.createSofaTracerSpan(1); + SofaTracerSpan span2 = ManagerTestUtil.createSofaTracerSpan(2); + SofaTracerSpan span3 = ManagerTestUtil.createSofaTracerSpan(3); + SofaTracerSpan span4 = ManagerTestUtil.createSofaTracerSpan(4); + SofaTracerSpan span5 = ManagerTestUtil.createSofaTracerSpan(5); + for (int j = 0; j < 100; j++) { + if (!asyncCommonDigestAppenderManager.append(span1)) { + discardNum.incrementAndGet(); + } + if (!asyncCommonDigestAppenderManager.append(span2)) { + discardNum.incrementAndGet(); + } + if (!asyncCommonDigestAppenderManager.append(span3)) { + discardNum.incrementAndGet(); + } + if (!asyncCommonDigestAppenderManager.append(span4)) { + discardNum.incrementAndGet(); + } + if (!asyncCommonDigestAppenderManager.append(span5)) { + discardNum.incrementAndGet(); + } + try { + Thread.sleep(10); + } catch (InterruptedException e) { + e.printStackTrace(); } - - countDownLatch.countDown(); } + countDownLatch.countDown(); }).start(); } @@ -161,7 +156,7 @@ public void run() { Thread.sleep(3000); SynchronizingSelfLog.flush(); - /**校验*/ + /**check*/ int log1Num = getLineNum(fileName1); int log2Num = getLineNum(fileName2); int log3Num = getLineNum(fileName3); @@ -169,19 +164,18 @@ public void run() { int log5Num = getLineNum(fileName5); int allNum = log1Num + log2Num + log3Num + log4Num + log5Num; - /**落地日志 + 丢失日志 = 打印日志*/ - SelfLog.info("落地日志:" + allNum); - SelfLog.info("丢失日志:" + discardNum.get()); + /**Landing log + Lost log = Print log*/ + SelfLog.info("Landing log:" + allNum); + SelfLog.info("Lost log:" + discardNum.get()); Assert.assertEquals(25000, allNum + discardNum.get()); - /**sync.log丢失日志数据小于实际丢失数*/ + /** Sync.log lost log data is less than the actual number of lost */ int logDiscard = getDiscardNumFromTracerSelfLog(); - SelfLog.info("sync.log记录丢失日志数:" + logDiscard); + SelfLog.info("Sync.log records the number of lost logs:" + logDiscard); Assert.assertTrue(logDiscard <= discardNum.get()); - /**sync.log记录的具体丢失日志数据的准确性:与真实丢失数的差应该小于500*/ - + /** Accuracy of the specific lost log data recorded by sync.log: the difference from the true lost number should be less than 500 */ int allTraceIdDiscard = traceId1Discard + traceId2Discard + traceId3Discard + traceId4Discard + traceId5Discard; - SelfLog.info("sync.log记录的具有traceId的具体丢失日志数据的数:" + allTraceIdDiscard); + SelfLog.info("The number of specific lost log data with traceId recorded by sync.log:" + allTraceIdDiscard); Assert.assertTrue((discardNum.get() == allTraceIdDiscard) || (discardNum.get() - allTraceIdDiscard) < 500); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ManagerTestUtil.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ManagerTestUtil.java index d197a5b5..f0066f55 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ManagerTestUtil.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/manager/ManagerTestUtil.java @@ -19,30 +19,14 @@ import com.alipay.common.tracer.core.SofaTracer; import com.alipay.common.tracer.core.context.span.SofaTracerSpanContext; import com.alipay.common.tracer.core.span.SofaTracerSpan; - import java.io.File; /** * * @author liangen - * @version $Id: ManagerTestUtil.java, v 0.1 2017年10月23日 下午8:34 liangen Exp $ + * @version $Id: ManagerTestUtil.java, v 0.1 October 23, 2017 8:34 PM liangen Exp $ */ public class ManagerTestUtil { - public static void deleteFile(String filePath) { - - File fileRoot = new File(filePath); - - if (fileRoot.isDirectory()) { - String[] childrens = fileRoot.list(); - for (String children : childrens) { - File file = new File(fileRoot, children); - deleteFile(file.getPath()); - } - - } - - fileRoot.delete(); - } public static SofaTracerSpan createSofaTracerSpan(int sequence) { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SelfLogTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SelfLogTest.java index f2a242b5..f2afc729 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SelfLogTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/appender/self/SelfLogTest.java @@ -35,7 +35,7 @@ * * @author * @version 1.0 - * @since
七月 26, 2017
+ * @since
July 26, 2017
*/ public class SelfLogTest extends AbstractTestBase { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerCallableTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerCallableTest.java index 80baa58e..c2d2a0db 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerCallableTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerCallableTest.java @@ -26,7 +26,7 @@ /** * * @author luoguimu123 - * @version $Id: SofaTracerCallableTest.java, v 0.1 2017年06月22日 下午3:38 luoguimu123 Exp $ + * @version $Id: SofaTracerCallableTest.java, v 0.1 June 22, 2017 3:38 PM luoguimu123 Exp $ */ public class SofaTracerCallableTest { SofaTraceContext traceContext; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerRunnableTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerRunnableTest.java index 16d6a4a8..2d7f86a2 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerRunnableTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/SofaTracerRunnableTest.java @@ -30,7 +30,7 @@ /** * @author luoguimu123 - * @version $Id: SofaTracerRunnableTest.java, v 0.1 2017年06月22日 下午3:53 luoguimu123 Exp $ + * @version $Id: SofaTracerRunnableTest.java, v 0.1 June 22, 2017 3:53 PM luoguimu123 Exp $ */ public class SofaTracerRunnableTest { SofaTraceContext traceContext; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracedExecutorServiceTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracedExecutorServiceTest.java index ea2a9530..b1ce6333 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracedExecutorServiceTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracedExecutorServiceTest.java @@ -34,7 +34,7 @@ /** * * @author luoguimu123 - * @version $Id: TracedExecutorServiceTest.java, v 0.1 2017年06月22日 下午3:59 luoguimu123 Exp $ + * @version $Id: TracedExecutorServiceTest.java, v 0.1 June 22, 2017 3:59 PM luoguimu123 Exp $ */ public class TracedExecutorServiceTest { private static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorServiceTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorServiceTest.java index 3381c690..9283fcf3 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorServiceTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/async/TracerScheduleExecutorServiceTest.java @@ -105,17 +105,10 @@ public void run() { @Test public void scheduleCallable() throws Exception { final Object testObj = new Object(); - Callable callable = new Callable() { - @Override - public Object call() throws Exception { - return testObj; - } - }; ScheduledFuture schedule = tracerScheduleExecutorService - .schedule(callable, 1000, TIME_UNIT); + .schedule(()-> testObj, 1000, TIME_UNIT); Thread.sleep(1100); Object o = schedule.get(); Assert.assertTrue(testObj == o); } - } \ No newline at end of file diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/base/AbstractTestBase.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/base/AbstractTestBase.java index d871e120..2127acbc 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/base/AbstractTestBase.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/base/AbstractTestBase.java @@ -105,13 +105,8 @@ protected static File tracerSelfLog() { return new File(logDirectoryPath + File.separator + "tracer-self.log"); } - protected static File middlewareErrorLog() { - return new File(logDirectoryPath + File.separator - + TracerSystemLogEnum.MIDDLEWARE_ERROR.getDefaultLogName()); - } - /** - * 检查传入的参数和日志中的内容是否匹配 + * Whether the parameters and the contents of the log match * * @param params String Array which is compared with logContent. * @param logContent String Content which is split up with comma @@ -124,8 +119,9 @@ public static boolean checkResult(List params, String logContent) { List slots = Arrays.asList(logContent.split(String .valueOf(XStringBuilder.DEFAULT_SEPARATOR))); - assertEquals("日志内容中的栏位数量为 " + slots.size() + ";参数的栏位数量为" + params.size() + ";两者不一致", - params.size(), slots.size()); + assertEquals("The number of fields in the log content is " + slots.size() + + "; the number of fields in the parameter is " + params.size() + + "; the two are inconsistent", params.size(), slots.size()); for (int i = 0; i < params.size(); i++) { String param = params.get(i); @@ -136,11 +132,16 @@ public static boolean checkResult(List params, String logContent) { } } if (param.length() > 2 && param.startsWith("M|")) { - Assert.assertTrue("日志和参数中的第 " + i + " 栏内容不一致,日志中为 " + slot + ";参数中为 " + param, + Assert.assertTrue( + "The contents of the " + i + + " column in the log and parameters are inconsistent. The log is " + + slot + ";The parameter is " + param, TestUtil.compareSlotMap(param.substring(2), slot)); } else { - Assert.assertTrue("日志和参数中的第 " + i + " 栏内容不一致,日志中为 " + slot + ";参数中为 " + param, - param.equals(slot)); + Assert.assertTrue( + "The contents of the " + i + + " column in the log and parameters are inconsistent. The log is " + + slot + ";The parameter is " + param, param.equals(slot)); } } return true; diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/benchmark/CountBenchmark.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/benchmark/CountBenchmark.java index b63cff72..cc88b3ad 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/benchmark/CountBenchmark.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/benchmark/CountBenchmark.java @@ -32,9 +32,9 @@ import java.util.concurrent.TimeUnit; /** - * 对比 JDK6 下 {@link StringTokenizer#countTokens()} 和 {@link String#split(String)} 的性能. + * Compare the performance of {@link StringTokenizer#countTokens()} and {@link String#split(String)} under JDK6. * - * JDK 6, Mac OS 10.11.1, 性能数据如下: + * JDK 6, Mac OS 10.11.1, The performance data is as follows: * *
  * Benchmark                                Mode    Cnt     Score       Error   Units
diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/configuration/SofaTracerConfigurationTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/configuration/SofaTracerConfigurationTest.java
index 1d5beefd..4c987b7a 100644
--- a/tracer-core/src/test/java/com/alipay/common/tracer/core/configuration/SofaTracerConfigurationTest.java
+++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/configuration/SofaTracerConfigurationTest.java
@@ -29,7 +29,7 @@
 /**
  *
  * @author luoguimu123
- * @version $Id: SofaTracerConfigurationTest.java, v 0.1 2017年06月29日 上午10:06 luoguimu123 Exp $
+ * @version $Id: SofaTracerConfigurationTest.java, v 0.1 June 29, 2017 10:06 AM luoguimu123 Exp $
  */
 public class SofaTracerConfigurationTest {
 
diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContextTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContextTest.java
index 2a29889d..3e89db38 100644
--- a/tracer-core/src/test/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContextTest.java
+++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContextTest.java
@@ -32,7 +32,7 @@
  *
  * @author 
  * @version 1.0
- * @since 
七月 8, 2017
+ * @since
July 8, 2017
*/ public class SofaTracerSpanContextTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/context/trace/SofaTracerThreadLocalTraceContextTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/context/trace/SofaTracerThreadLocalTraceContextTest.java index 7450e6a5..7dc95f82 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/context/trace/SofaTracerThreadLocalTraceContextTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/context/trace/SofaTracerThreadLocalTraceContextTest.java @@ -29,7 +29,7 @@ * * @author * @version 1.0 - * @since
七月 6, 2017
+ * @since
July 6, 2017
*/ public class SofaTracerThreadLocalTraceContextTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolderTest.java index 5b69d614..be90d983 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/holder/SofaTraceContextHolderTest.java @@ -34,7 +34,7 @@ * * @author * @version 1.0 - * @since
七月 6, 2017
+ * @since
July 6, 2017
*/ public class SofaTraceContextHolderTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/listener/SpanReportListenerHolderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/listener/SpanReportListenerHolderTest.java index 00df0768..193b814e 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/listener/SpanReportListenerHolderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/listener/SpanReportListenerHolderTest.java @@ -29,7 +29,7 @@ * * @author * @version 1.0 - * @since
五月 7, 2018
+ * @since
May 7, 2018
*/ public class SpanReportListenerHolderTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/mock/MockSofaTracerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/mock/MockSofaTracerTest.java index b0298d77..e5dd4543 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/mock/MockSofaTracerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/mock/MockSofaTracerTest.java @@ -30,7 +30,7 @@ * * @author * @version 1.0 - * @since
八月 10, 2017
+ * @since
August 10, 2017
*/ public class MockSofaTracerTest extends AbstractTestBase { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/BinaryFormaterTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/BinaryFormaterTest.java index f32b977c..0e7bf342 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/BinaryFormaterTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/BinaryFormaterTest.java @@ -37,7 +37,7 @@ * * @author * @version 1.0 - * @since
六月 24, 2017
+ * @since
June 24, 2017
*/ public class BinaryFormaterTest { @@ -70,7 +70,7 @@ public void testGetFormatType() throws Exception { } /** - * 将我们的 spanContext 放在数据头部 + * Put our spanContext in the data header * Method: inject(SofaTracerSpanContext spanContext, ByteBuffer carrier) *

* Method: extract(ByteBuffer carrier) @@ -89,7 +89,7 @@ public void testExtractCarrier() throws Exception { } /** - * 将我们的 spanContext 放在数据头部 + * Put our spanContext in the data header * Method: inject(SofaTracerSpanContext spanContext, ByteBuffer carrier) *

* Method: extract(ByteBuffer carrier) @@ -97,7 +97,7 @@ public void testExtractCarrier() throws Exception { @Test public void testExtract() throws Exception { SofaTracerSpanContext spanContext = SofaTracerSpanContext.rootStart(); - Map baggage = new HashMap(); + Map baggage = new HashMap<>(); baggage.put("key", "value"); baggage.put("key1", "value1"); baggage.put("key2", "value2"); @@ -115,7 +115,7 @@ public void testExtract() throws Exception { } /** - * 将我们的 spanContext 字节码放在数据中间位置 + * Put our spanContext bytecode in the middle of the data * Method: inject(SofaTracerSpanContext spanContext, ByteBuffer carrier) *

* Method: extract(ByteBuffer carrier) @@ -123,12 +123,12 @@ public void testExtract() throws Exception { @Test public void testExtractInject() throws Exception { SofaTracerSpanContext spanContext = SofaTracerSpanContext.rootStart(); - Map baggage = new HashMap(); + Map baggage = new HashMap<>(); baggage.put("key", "value"); baggage.put("key1", "value1"); baggage.put("key2", "value2"); spanContext.addBizBaggage(baggage); - Map sysBaggage = new HashMap(); + Map sysBaggage = new HashMap<>(); sysBaggage.put("sys1", "value1"); sysBaggage.put("sys2", "value2"); sysBaggage.put("sys3", "value3"); @@ -137,8 +137,8 @@ public void testExtractInject() throws Exception { //inject //200 bytes ByteBuffer carrier = ByteBuffer.allocate(400); - //提前放一些数据进行测试 - String header = "index_=test雪连哈哈"; + //Put some data in advance to test + String header = "index_=testSOFATracerInject"; byte[] headerBytes = header.getBytes(SofaTracerConstant.DEFAULT_UTF8_CHARSET); carrier.put(headerBytes); this.registryExtractorInjector.inject(spanContext, carrier); @@ -153,7 +153,7 @@ public void testExtractInject() throws Exception { } /** - * 注意:此测试用例不通过,只支持堆内存不支持堆外内存 + * Note: This test case does not pass, only supports heap memory does not support off-heap memory * Method: inject(SofaTracerSpanContext spanContext, ByteBuffer carrier) *

* @@ -171,11 +171,10 @@ public void testDirectByteBufferExtractInjectException() throws Exception { //200 bytes ByteBuffer carrier = ByteBuffer.allocateDirect(200); this.registryExtractorInjector.inject(spanContext, carrier); - SofaTracerSpanContext extractContext = null; //extract boolean isException = false; try { - extractContext = this.registryExtractorInjector.extract(carrier); + this.registryExtractorInjector.extract(carrier); } catch (UnsupportedOperationException exception) { isException = true; } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/HttpHeadersB3FormatterTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/HttpHeadersB3FormatterTest.java index 68647f28..28a8ef4f 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/HttpHeadersB3FormatterTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/HttpHeadersB3FormatterTest.java @@ -32,7 +32,7 @@ * * @author * @version 1.0 - * @since

七月 8, 2017
+ * @since
July 8, 2017
*/ public class HttpHeadersB3FormatterTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/HttpHeadersFormatterTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/HttpHeadersFormatterTest.java index f1180821..a6505dc8 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/HttpHeadersFormatterTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/HttpHeadersFormatterTest.java @@ -34,7 +34,7 @@ * * @author * @version 1.0 - * @since
七月 8, 2017
+ * @since
July 8, 2017
*/ public class HttpHeadersFormatterTest { @@ -62,15 +62,14 @@ public void testGetFormatType() throws Exception { @Test public void testEncodedValue() throws Exception { SofaTracerSpanContext spanContext = SofaTracerSpanContext.rootStart(); - Map baggage = new HashMap(); + Map baggage = new HashMap<>(); baggage.put("key", "value"); baggage.put("key1", "value1"); baggage.put("key2", "value2"); spanContext.addBizBaggage(baggage); // final TextMap carrier = new TextMap() { - - Map carr = new HashMap(); + Map carr = new HashMap<>(); @Override public Iterator> iterator() { @@ -89,7 +88,7 @@ public String toString() { }; this.registryExtractorInjector.inject(spanContext, carrier); SofaTracerSpanContext extractContext = this.registryExtractorInjector.extract(carrier); - //traceid spanId sampled + // traceId spanId sampled extractContext.equals(spanContext); assertTrue("Extract baggage : " + extractContext.getBizBaggage(), baggage.equals(extractContext.getBizBaggage())); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TextMapB3FormatterTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TextMapB3FormatterTest.java index f7ce246d..c1919a82 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TextMapB3FormatterTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TextMapB3FormatterTest.java @@ -34,7 +34,7 @@ * * @author * @version 1.0 - * @since
七月 8, 2017
+ * @since
July 8, 2017
*/ public class TextMapB3FormatterTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TextMapFormatterTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TextMapFormatterTest.java index 07ad2b88..8970224b 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TextMapFormatterTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TextMapFormatterTest.java @@ -35,7 +35,7 @@ * * @author * @version 1.0 - * @since
七月 8, 2017
+ * @since
July 8, 2017
*/ public class TextMapFormatterTest { @@ -94,7 +94,7 @@ public String toString() { this.registryExtractorInjector.inject(spanContext, carrier); //carrier SofaTracerSpanContext extractContext = this.registryExtractorInjector.extract(carrier); - //traceid spanId sampled + //traceId spanId sampled extractContext.equals(spanContext); assertTrue("Extract : " + extractContext, baggage.equals(extractContext.getBizBaggage())); } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TracerFormatRegistryTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TracerFormatRegistryTest.java index 492bcb31..90665687 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TracerFormatRegistryTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/registry/TracerFormatRegistryTest.java @@ -26,7 +26,7 @@ * * @author * @version 1.0 - * @since
七月 8, 2017
+ * @since
July 8, 2017
*/ public class TracerFormatRegistryTest { @@ -41,7 +41,7 @@ public void testRegister() throws Exception { .getRegistry(io.opentracing.propagation.Format.Builtin.BINARY); assertTrue(registry == registry1); - //恢复测试影响的registry + //Restore the registry affected by the test BinaryFormater binaryFormater = new BinaryFormater(); TracerFormatRegistry.register(io.opentracing.propagation.Format.Builtin.BINARY, binaryFormater); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/SofaTracerStatisticReporterCycleTimesManagerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/SofaTracerStatisticReporterCycleTimesManagerTest.java index 0832dba2..eb5a4cb3 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/SofaTracerStatisticReporterCycleTimesManagerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/SofaTracerStatisticReporterCycleTimesManagerTest.java @@ -25,7 +25,7 @@ * SofaTracerStatisticReporterCycleTimesManager Tester. * * @author -* @since
六月 22, 2017
+* @since
June 22, 2017
* @version 1.0 */ public class SofaTracerStatisticReporterCycleTimesManagerTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoderTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoderTest.java index 39377a0f..cd693a31 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoderTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonSpanEncoderTest.java @@ -46,7 +46,7 @@ * * @author * @version 1.0 - * @since
七月 15, 2017
+ * @since
July 15, 2017
*/ public class CommonSpanEncoderTest extends AbstractTestBase { @@ -86,15 +86,14 @@ public void testEncode() throws Exception { sofaTracerSpan.setBaggageItem("baggage1", "value1"); sofaTracerSpan.setBaggageItem("baggage2", "value2"); - //记录一条错误日志 + //Record an error log sofaTracerSpan.reportError(errorType, context, exception, appName, errorSources); - //记录一条client 日志 + //Record a client log sofaTracerSpan.finish(); TestUtil.waitForAsyncLog(); - //检查客户端日志 - //client digest + //Check client logs List clientDigestContents = FileUtils.readLines(new File(logDirectoryPath + File.separator + clientLogType)); @@ -104,15 +103,15 @@ public void testEncode() throws Exception { //error log List errorContents = FileUtils .readLines(customFileLog(TracerSystemLogEnum.MIDDLEWARE_ERROR.getDefaultLogName())); - //错误堆栈 + //Error stack assertTrue(errorContents.size() > 1); assertTrue(errorContents.get(0).contains(sofaTracerSpanContext.getTraceId())); - //去掉头 + //remove head String fileContent = errorContents.get(0).substring(errorContents.get(0).indexOf(",") + 1); - //去掉尾巴 + //remove end fileContent = fileContent.substring(0, fileContent.lastIndexOf(",")); - //构造结果 - List params = new ArrayList(); + //construct result + List params = new ArrayList<>(); params.add(sofaTracerSpan.getTagsWithStr().get(SpanTags.CURR_APP_TAG.getKey())); params.add(sofaTracerSpanContext.getTraceId()); params.add(sofaTracerSpanContext.getSpanId()); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManagerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManagerTest.java index a1b0b139..8e210b80 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManagerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/common/CommonTracerManagerTest.java @@ -37,7 +37,7 @@ * * @author * @version 1.0 - * @since
七月 25, 2017
+ * @since
July 25, 2017
*/ public class CommonTracerManagerTest extends AbstractTestBase { @@ -61,7 +61,7 @@ public void testRegisterAndReportCommonSpan() throws Exception { System.currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), null); assertTrue(CommonTracerManager.isAppenderExist(logType)); - //注意:对于 commonSpan 一定要设置日志类型 + //Note: Be sure to set the log type for commonSpan commonLogSpan.setLogType(logType); CommonTracerManager.reportCommonSpan(commonLogSpan); @@ -88,7 +88,7 @@ public void testRegisterAndReportCommonSpanChar() throws Exception { System.currentTimeMillis(), "testReportProfile", SofaTracerSpanContext.rootStart(), null); assertTrue(CommonTracerManager.isAppenderExist(logTypeStr)); - //注意:对于 commonSpan 一定要设置日志类型 + //Note: Be sure to set the log type for commonSpan commonLogSpan.setLogType(logTypeStr); commonLogSpan.addSlot("hello"); commonLogSpan.addSlot("word"); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/composite/SofaTracerCompositeDigestReporterImplTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/composite/SofaTracerCompositeDigestReporterImplTest.java index 8da07dbd..0e3c30d8 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/composite/SofaTracerCompositeDigestReporterImplTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/composite/SofaTracerCompositeDigestReporterImplTest.java @@ -28,7 +28,7 @@ * * @author * @version 1.0 - * @since
五月 8, 2018
+ * @since
May 8, 2018
*/ public class SofaTracerCompositeDigestReporterImplTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImplTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImplTest.java index 753cecd7..aa6b52a7 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImplTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/DiskReporterImplTest.java @@ -47,7 +47,7 @@ * * @author * @version 1.0 - * @since
五月 25, 2018
+ * @since
May 25, 2018
*/ public class DiskReporterImplTest extends AbstractTestBase { @@ -162,7 +162,8 @@ public void testFixInitDigestFile() throws Exception { executor.execute(worker); } Thread.sleep(3 * 1000); - //未控制并发初始化时,report span 会报错;修复方法即初始化未完成时,其他线程需要等待初始化完成 + // When there is no control for concurrent initialization, report span will get an error; + // when the repair method is initialized,other threads need to wait for initialization to complete. List contents = FileUtils.readLines(tracerSelfLog()); assertTrue("Actual concurrent init file size = " + contents.size(), contents.size() == 1); } diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporterImplTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporterImplTest.java index 77276892..3b4259b2 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporterImplTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/SofaTracerStatisticReporterImplTest.java @@ -30,17 +30,14 @@ * * @author * @version 1.0 - * @since
七月 2, 2017
+ * @since
July 2, 2017
*/ public class SofaTracerStatisticReporterImplTest { - /*** - * 1s 钟统计一次 - */ private final long CYCLE_IN_SECONDS = 1; static { - //调整阈值可测性 + //Adjust threshold measurability SofaTracerStatisticReporterManager.CLEAR_STAT_KEY_THRESHOLD = 5; System.setProperty("com.alipay.ldc.zone", "GZ00A"); @@ -57,7 +54,8 @@ public static void afterCl() { } /** - * 测试keys太多,定时清空的场景 如单独测试,可以把TracerConfiguration.CLEAR_STAT_KEY_THRESHOLD调小以方便测试 + * Test too many keys, timed empty scenes. If you test separately, + * you can reduce TracerConfiguration.CLEAR_STAT_KEY_THRESHOLD to facilitate testing. */ @Test public void testClearKeys() throws InterruptedException { @@ -74,7 +72,7 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) { }; - // case 1: 切换时没有达到阈值 + // case 1: Threshold not reached when switching for (int i = 0; i < SofaTracerStatisticReporterManager.CLEAR_STAT_KEY_THRESHOLD; i++) { StatKey statKey = new StatKey(); statKey.setKey(String.valueOf(i)); @@ -89,19 +87,19 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) { Thread.sleep(100); } - // 此时发生过下标切换 + // Subscript switching occurred at this time Assert.assertEquals(0, statReporter.getStatData().size()); Assert.assertEquals(SofaTracerStatisticReporterManager.CLEAR_STAT_KEY_THRESHOLD, statReporter.getOtherStatData().size()); - // case 2: 切换时达到阈值 + // case 2: Threshold reached when switching for (int i = 0; i <= SofaTracerStatisticReporterManager.CLEAR_STAT_KEY_THRESHOLD; i++) { StatKey statKey = new StatKey(); statKey.setKey(String.valueOf(i)); statReporter.addStat(statKey, i); } - // 此时应该发生过下标切换 + // At this point, there should be a subscript switch currentSize = statReporter.getStatData().size(); while (true) { if (statReporter.getStatData().size() != currentSize) { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/model/StatMapKeyTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/model/StatMapKeyTest.java index 0e6ba398..4a3c56be 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/model/StatMapKeyTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/stat/model/StatMapKeyTest.java @@ -27,7 +27,7 @@ * * @author * @version 1.0 - * @since
五月 15, 2018
+ * @since
May 15, 2018
*/ public class StatMapKeyTest { @@ -42,7 +42,7 @@ public void testAddKey() throws Exception { statMapKey.addKey("key3", "value3"); statMapKey.addKey("key4", "value4"); statMapKey.addKey("key5", "value5"); - // + StatMapKey statMapKey1 = new StatMapKey(); statMapKey1.addKey("key3", "value3"); statMapKey1.addKey("key4", "value4"); @@ -52,24 +52,24 @@ public void testAddKey() throws Exception { assertEquals(statMapKey.hashCode(), statMapKey1.hashCode()); assertEquals(statMapKey, statMapKey1); assertEquals(statMapKey.getKeyMap(), statMapKey1.getKeyMap()); - // + StatMapKey statMapKey2 = new StatMapKey(); statMapKey2.addKey("key3", "value3"); statMapKey2.addKey("key4", "value4"); statMapKey2.addKey("key5", "value5"); statMapKey2.addKey("key1", "value1"); assertFalse(statMapKey2.equals(statMapKey1)); - // + statMapKey.setEnd("f"); statMapKey.setResult("Y"); statMapKey.setLoadTest(false); assertFalse(statMapKey.equals(statMapKey1)); - // + statMapKey1.setEnd("t"); statMapKey1.setResult("Y"); statMapKey1.setLoadTest(false); assertFalse(statMapKey.equals(statMapKey1)); - // + statMapKey1.setEnd("f"); statMapKey1.setResult("Y"); statMapKey1.setLoadTest(false); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java index 48fb61fc..f9e8b0ae 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java @@ -42,7 +42,7 @@ * * @author * @version 1.0 - * @since
七月 6, 2017
+ * @since
July 6, 2017
*/ public class SofaTracerSpanTest extends AbstractTestBase { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java index 1d4dd2a7..6375ffa9 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java @@ -38,12 +38,8 @@ import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; - -import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.*; - import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -53,7 +49,7 @@ * * @author * @version 1.0 - * @since
七月 1, 2017
+ * @since
July 1, 2017
*/ public class SofaTracerTest extends AbstractTestBase { @@ -135,7 +131,7 @@ public void put(String key, String value) { public void testReportSpan() throws Exception { SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testInjectSpan") .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start(); - //report 不要禁写 + //Report Do not prohibit writing span.finish(); TestUtil.waitForAsyncLog(); @@ -144,7 +140,7 @@ public void testReportSpan() throws Exception { .getDefaultLogName())); assertTrue(contents.get(0), contents.size() == 1); String contextStr = contents.get(0); - //测试打印一条只放了一个 tags + //Test print one only put one tag assertTrue(contextStr.contains(Tags.SPAN_KIND.getKey()) && contextStr.contains(Tags.SPAN_KIND_CLIENT)); } @@ -154,7 +150,7 @@ public void testReportSpan() throws Exception { */ @Test public void testIsDisableAllDigestLog() { - //全局关闭摘要日志 + //Close the digest log globally SofaTracerConfiguration.setProperty( SofaTracerConfiguration.DISABLE_MIDDLEWARE_DIGEST_LOG_KEY, "true"); SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testInjectSpan") @@ -169,7 +165,7 @@ public void testIsDisableAllDigestLog() { @Test public void testIsDisableClientDigestLog() { - //关闭client摘要日志 + //Close the client digest log String clientLogTypeName = TracerTestLogEnum.RPC_CLIENT.getDefaultLogName(); Map prop = new HashMap(); @@ -182,7 +178,7 @@ public void testIsDisableClientDigestLog() { span.finish(); assertTrue(!customFileLog(clientLogTypeName).exists()); SofaTracerConfiguration.setProperty(SofaTracerConfiguration.DISABLE_DIGEST_LOG_KEY, - new HashMap()); + new HashMap<>()); } /** @@ -207,7 +203,6 @@ public void testTracerClose() { SofaTracer sofaTracer = new SofaTracer.Builder(tracerType).withClientReporter(reporter) .withSampler(sampler).build(); sofaTracer.close(); - //确认被调用 verify(reporter).close(); sampler.close(); verify(sampler).close(); @@ -323,7 +318,7 @@ public void testAsChildOfParentTestBizBaggageAndSysBaggage() { /** * Method: asChildOf(Span parentSpan) - * 多个的时候,baggage 复用 只选择第一个父亲 + * Multiple times, baggage reuse only select the first father */ @Test public void testAsChildOfMultiParentSpan() { @@ -406,9 +401,6 @@ public void testAddReferenceForReferenceTypeReferencedContextAndBaggageMultipleR String fol1BagKey = "fol1BagKey"; String fol1BagValue = "fol1BagValue"; spanFollow1.setBaggageItem(fol1BagKey, fol1BagValue); - - String followTraceId1 = spanFollow1.getSofaTracerSpanContext().getTraceId(); - String followSpanId1 = spanFollow1.getSofaTracerSpanContext().getSpanId(); //follow1 SofaTracerSpan spanFollow2 = (SofaTracerSpan) this.sofaTracer.buildSpan("spanFollow2") .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).start(); diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java index faa3802e..7a9838d1 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java @@ -24,23 +24,15 @@ */ public enum TracerTestLogEnum { - // 其他日志 - RPC_CLIENT("rpc_client_log_name", "rpc_client.log", "rpc_client_rolling"), // 业务成功日志 - RPC_SERVER("rpc_server_log_name", "rpc_server.log", "rpc_server_rolling");// 业务异常日志 + RPC_CLIENT("rpc_client_log_name", "rpc_client.log", "rpc_client_rolling"), RPC_SERVER( + "rpc_server_log_name", + "rpc_server.log", + "rpc_server_rolling"); - /*** - * 获取保留天数 getLogReverseDay 关键字 - */ private String logReverseKey; - /*** - * 默认生成的日志名字 .log 结尾同时作为一个类型 - */ private String defaultLogName; - /*** - * 日志的滚动策略 - */ private String rollingKey; TracerTestLogEnum(String logReverseKey, String defaultLogName, String rollingKey) { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/StringUtilsTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/StringUtilsTest.java index 881bb497..86bdc0b0 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/StringUtilsTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/StringUtilsTest.java @@ -25,7 +25,7 @@ * * @author * @version 1.0 - * @since
五月 15, 2018
+ * @since
May 15, 2018
*/ public class StringUtilsTest { diff --git a/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/TracerUtilsTest.java b/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/TracerUtilsTest.java index 3d03235b..99f4273c 100644 --- a/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/TracerUtilsTest.java +++ b/tracer-core/src/test/java/com/alipay/common/tracer/core/utils/TracerUtilsTest.java @@ -37,20 +37,20 @@ * * @author * @version 1.0 - * @since
七月 2, 2017
+ * @since
July 2, 2017
*/ public class TracerUtilsTest { - /*** - *测试去除URL中的JSessionId_URL为null + /** + * Test removes the JSessionId_URL in the URL to null */ @Test public void JSessionId_URL_is_null() { Assert.assertNull(TracerUtils.removeJSessionIdFromUrl(null)); } - /*** - * 测试去除URL中的JSessionId_URL为空字符串 + /** + * Test removes the JSessionId_URL in the URL to "" */ @Test public void JSessionId_URL_EMPTY() { @@ -58,8 +58,8 @@ public void JSessionId_URL_EMPTY() { TracerUtils.removeJSessionIdFromUrl(StringUtils.EMPTY_STRING)); } - /*** - * 测试去除URL中的JSessionId_URL不包含JSessionId + /** + * The JSessionId_URL in the test removal URL does not contain the JSessionId */ @Test public void JSessionId_URL_NO_JSessionId() { @@ -67,8 +67,8 @@ public void JSessionId_URL_NO_JSessionId() { Assert.assertEquals(url, TracerUtils.removeJSessionIdFromUrl(url)); } - /*** - * 测试去除URL中的JSessionId_URL包含JSessionId + /** + * The JSessionId_URL in the test removal URL contain the JSessionId */ @Test public void JSessionId_URL包含JSessionId() { @@ -87,7 +87,7 @@ public void testGetPID() throws Exception { } @Test - public void 测试_mapToString() { + public void test_mapToString() { Map strMap = new TreeMap(); strMap.put("test1", "test="); strMap.put("test2", "test&"); @@ -97,7 +97,7 @@ public void testGetPID() throws Exception { } @Test - public void 测试_stringToMap() { + public void test_stringToMap() { Map strMap = new HashMap(); StringUtils .stringToMap("test1=test" + XStringBuilder.EQUAL_SEPARATOR_ESCAPE + "&test2=test" @@ -106,30 +106,33 @@ public void testGetPID() throws Exception { Assert.assertEquals("test&", strMap.get("test2")); } - /*** - * 测试_mapToString_stringToMap_包含百分号 + /** + * test_mapToString_stringToMap_contains_percent_sign */ @Test - public void mapToString_stringToMap_() { - Map strMap = new HashMap(); + public void mapToString_stringToMap_contains_percent_sign() { + Map strMap = new HashMap<>(); String key = "test1"; String value = "test" + XStringBuilder.AND_SEPARATOR_ESCAPE; strMap.put(key, value); String result = StringUtils.mapToString(strMap); - Map decodeMap = new HashMap(); + Map decodeMap = new HashMap<>(); StringUtils.stringToMap(result, decodeMap); Assert.assertEquals(value, decodeMap.get(key)); } + /** + * Test parsing log retention time configuration + */ @Test - public void 测试解析日志保留时间配置() { + public void testParseLogRetentionTimeConfig() { LogReserveConfig logReserveConfig = TracerUtils.parseLogReserveConfig("0D1H"); Assert.assertEquals(0, logReserveConfig.getDay()); Assert.assertEquals(1, logReserveConfig.getHour()); } - /*** - * 测试纯数字的日志保留时间配置 + /** + * Test purely digital log retention time configuration */ @Test public void testParseLogReserveConfigByNumber() { @@ -143,7 +146,7 @@ public void testCheckBaggageLength() { SofaTracer sofaTracer = mock(SofaTracer.class); SofaTracerSpanContext sofaTracerSpanContext = new SofaTracerSpanContext(); SofaTracerSpan sofaTracerSpan = new SofaTracerSpan(sofaTracer, System.currentTimeMillis(), - "mock", sofaTracerSpanContext, new HashMap()); + "mock", sofaTracerSpanContext, new HashMap<>()); assertTrue(TracerUtils.checkBaggageLength(sofaTracerSpan, "key", "value")); } diff --git a/tracer-extensions/src/main/java/com/alipay/common/tracer/extensions/log/MDCSpanExtension.java b/tracer-extensions/src/main/java/com/alipay/common/tracer/extensions/log/MDCSpanExtension.java index 7036ad18..81676bf1 100644 --- a/tracer-extensions/src/main/java/com/alipay/common/tracer/extensions/log/MDCSpanExtension.java +++ b/tracer-extensions/src/main/java/com/alipay/common/tracer/extensions/log/MDCSpanExtension.java @@ -25,7 +25,7 @@ /** * @author luoguimu123 - * @version $Id: MDCSpanExtension.java, v 0.1 2017年06月23日 上午11:55 luoguimu123 Exp $ + * @version $Id: MDCSpanExtension.java, v 0.1 June 23, 2017 11:55 AM luoguimu123 Exp $ */ public class MDCSpanExtension implements SpanExtension { diff --git a/tracer-extensions/src/main/java/com/alipay/common/tracer/extensions/log/constants/MDCKeyConstants.java b/tracer-extensions/src/main/java/com/alipay/common/tracer/extensions/log/constants/MDCKeyConstants.java index 33d9d09a..db016750 100644 --- a/tracer-extensions/src/main/java/com/alipay/common/tracer/extensions/log/constants/MDCKeyConstants.java +++ b/tracer-extensions/src/main/java/com/alipay/common/tracer/extensions/log/constants/MDCKeyConstants.java @@ -17,9 +17,9 @@ package com.alipay.common.tracer.extensions.log.constants; /** - * 负责管理MDC中需要存入的key值常量 + * Responsible for managing key value constants that need to be stored in MDC * @author luoguimu123 - * @version $Id: MDCKeyConstants.java, v 0.1 2017年08月07日 上午8:44 luoguimu123 Exp $ + * @version $Id: MDCKeyConstants.java, v 0.1 August 07, 2017 8:44 AM luoguimu123 Exp $ */ public class MDCKeyConstants { diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/properties/SofaTracerDataSourceProperties.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/properties/SofaTracerDataSourceProperties.java index 4dfaa3b8..244ace4e 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/properties/SofaTracerDataSourceProperties.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/datasource/properties/SofaTracerDataSourceProperties.java @@ -19,7 +19,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; /** - * @author qilong.zql 18/9/4-下午1:41 + * @author qilong.zql 18/9/4-PM 1:41 */ @ConfigurationProperties("com.alipay.sofa.tracer.datasource") public class SofaTracerDataSourceProperties { diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/resttemplate/CustomRestTemplateCustomizer.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/resttemplate/CustomRestTemplateCustomizer.java index a1c71364..84905065 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/resttemplate/CustomRestTemplateCustomizer.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/resttemplate/CustomRestTemplateCustomizer.java @@ -29,7 +29,7 @@ * CustomRestTemplateCustomizer * * @version 1.0 - * @author: guolei.sgl 18/11/19 下午11:07 + * @author: guolei.sgl 18/11/19 PM 11:07 * @since: v2.3.0 **/ public class CustomRestTemplateCustomizer implements RestTemplateCustomizer { diff --git a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/resttemplate/configuration/RestTemplateAutoConfiguration.java b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/resttemplate/configuration/RestTemplateAutoConfiguration.java index 16df87ec..b33b3024 100644 --- a/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/resttemplate/configuration/RestTemplateAutoConfiguration.java +++ b/tracer-sofa-boot-starter/src/main/java/com/alipay/sofa/tracer/boot/resttemplate/configuration/RestTemplateAutoConfiguration.java @@ -28,7 +28,7 @@ * RestTemplateAutoConfiguration * * @version 1.0 - * @author: guolei.sgl 18/11/20 上午11:02 + * @author: guolei.sgl 18/11/20 AM 11:02 * @since: v2.3.0 **/ @Configuration diff --git a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/zipkin/ZipkinSofaTracerSpanRemoteReporterTest.java b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/zipkin/ZipkinSofaTracerSpanRemoteReporterTest.java index ecd918fe..7423a0a0 100644 --- a/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/zipkin/ZipkinSofaTracerSpanRemoteReporterTest.java +++ b/tracer-sofa-boot-starter/src/test/java/com/alipay/sofa/tracer/boot/zipkin/ZipkinSofaTracerSpanRemoteReporterTest.java @@ -80,17 +80,14 @@ public void testHexStringToHex() throws Exception { for (int i = 0; i < 10; i++) { String traceId = TraceIdGenerator.generate(); long idValue = ZipkinSofaTracerSpanRemoteReporter.traceIdToId(traceId); - //有了末位的累加数 assertTrue(idValue > time); } - //8 位以内 String hex1 = "0a"; assertEquals(10, ZipkinSofaTracerSpanRemoteReporter.traceIdToId(hex1)); String hex2 = "0e"; assertEquals(14, ZipkinSofaTracerSpanRemoteReporter.traceIdToId(hex2)); String hex3 = "0a0a"; assertEquals(10 + 10 * (16 * 16), ZipkinSofaTracerSpanRemoteReporter.traceIdToId(hex3)); - //大于 8 位且非进程号结尾 String hex4 = "0a0c0d0e100"; assertEquals(100, ZipkinSofaTracerSpanRemoteReporter.traceIdToId(hex4)); String hex5 = "0a0c0d0e9999"; @@ -105,12 +102,6 @@ public void testHexStringToHex() throws Exception { assertTrue(isException); } - /*** - * 测试 FNV64HashCode 算法性能,如果不满足性能要求,那么考虑更优秀算法 - * 目标: 200 万数据务必在 10s 内完成且没有碰撞发生 - * hash FNVHash64 : http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param - * @throws Exception 异常 - */ @Test public void testFNV64HashCode() throws Exception { //one million no redundant @@ -145,9 +136,9 @@ public void testFNV64HashCode() throws Exception { long cost = System.currentTimeMillis() - startTime; long count = (iLong * jLong * kLong * lLong) + (iLong * jLong * kLong) + (iLong * jLong) + iLong; - //目标: 200 万数据务必在 10s 内完成 + //Goal: 2 million data must be completed within 10s assertTrue("Count = " + count + ",FNV64HashCode Cost = " + cost + " ms", cost < 10 * 1000); - //重复 + //repeat Map redundantMap = getRedundant(mapHash); assertTrue("FNV64HashCode Redundant Size = " + redundantMap.size() + " ; Redundant = " + redundantMap, redundantMap.size() <= 0); @@ -168,7 +159,7 @@ private void putMap(long hashCode, Map map) { } private Map getRedundant(Map originMap) { - Map resultMap = new HashMap(); + Map resultMap = new HashMap<>(); for (Map.Entry entry : originMap.entrySet()) { Long value = entry.getValue(); if (value > 1) { @@ -186,7 +177,7 @@ public void testDoServerReport() throws Exception { sofaTracerServerSpan.setOperationName("mockOperationName"); //ss TL this.remoteTracer.serverSend("0"); - //异步汇报,所以 sleep 1s + //Asynchronous reporting, so sleep 1s Thread.sleep(1000); //assert SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext(); @@ -229,7 +220,7 @@ public void testDoReport() throws Exception { assertEquals(sofaTracerServerSpan, sofaTraceContext.getCurrentSpan()); //ss TL this.remoteTracer.serverSend("0"); - //异步汇报,所以 sleep 1s + //Asynchronous reporting, so sleep 1s Thread.sleep(1000); //assert assertTrue(sofaTraceContext.isEmpty()); diff --git a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/MDCMultiThreadTest.java b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/MDCMultiThreadTest.java index ba334e29..d7675251 100644 --- a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/MDCMultiThreadTest.java +++ b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/MDCMultiThreadTest.java @@ -28,7 +28,7 @@ /** * * @author luoguimu123 - * @version $Id: MDCMultiThreadTest.java, v 0.1 2017年06月19日 下午7:42 luoguimu123 Exp $ + * @version $Id: MDCMultiThreadTest.java, v 0.1 June 19, 2017 7:42 PM luoguimu123 Exp $ */ public class MDCMultiThreadTest { diff --git a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/MDCTest.java b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/MDCTest.java index 702c5283..59034ba6 100644 --- a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/MDCTest.java +++ b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/MDCTest.java @@ -32,30 +32,25 @@ /** * * @author luoguimu123 - * @version $Id: MDCTest.java, v 0.1 2017年06月19日 下午6:14 luoguimu123 Exp $ + * @version $Id: MDCTest.java, v 0.1 June 19, 2017 6:14 PM luoguimu123 Exp $ */ public class MDCTest { - - //private static final Logger logger = LoggerFactory.getLogger("traceLog"); - @Test public void test() throws IOException { - Logger logger = LoggerFactory.getLogger("traceLog"); - MDC.clear(); MDC.put("sessionId", "f9e287fad9e84cff8b2c2f2ed92adbe6"); MDC.put("cityId", "1"); - MDC.put("siteName", "北京"); + MDC.put("siteName", "beijing"); MDC.put("userName", "userwyh"); - logger.info("测试MDC打印一"); + logger.info("Test MDC print one"); MDC.put("mobile", "110"); - logger.info("测试MDC打印二"); + logger.info("Test MDC print two"); MDC.put("mchId", "12"); - MDC.put("mchName", "商户名称"); - logger.info("测试MDC打印三"); + MDC.put("mchName", "BusinessName"); + logger.info("Test MDC print three"); BufferedReader reader = new BufferedReader(new FileReader("../logs/trace.log")); List content = new ArrayList(); while (true) { @@ -71,33 +66,33 @@ public void test() throws IOException { SelfLog.info(s); } String[] array = line1.split(","); - Assert.assertEquals(array[0], "北京"); + Assert.assertEquals(array[0], "beijing"); Assert.assertEquals(array[3], "f9e287fad9e84cff8b2c2f2ed92adbe6"); Assert.assertEquals(array[4], "1"); Assert.assertEquals(array[5], "userwyh"); - Assert.assertEquals(array[7], "测试MDC打印一"); + Assert.assertEquals(array[7], "Test MDC print one"); String line2 = content.get(content.size() - 2); line2 = line2.substring(line2.indexOf(",") + 1); String[] array2 = line2.split(","); - Assert.assertEquals(array2[0], "北京"); + Assert.assertEquals(array2[0], "beijing"); Assert.assertEquals(array2[3], "f9e287fad9e84cff8b2c2f2ed92adbe6"); Assert.assertEquals(array2[4], "1"); Assert.assertEquals(array2[5], "userwyh"); Assert.assertEquals(array2[6], "110"); - Assert.assertEquals(array2[7], "测试MDC打印二"); + Assert.assertEquals(array2[7], "Test MDC print two"); String line3 = content.get(content.size() - 1); line3 = line3.substring(line3.indexOf(",") + 1); String[] array3 = line3.split(","); - Assert.assertEquals(array3[0], "北京"); + Assert.assertEquals(array3[0], "beijing"); Assert.assertEquals(array3[1], "12"); - Assert.assertEquals(array3[2], "商户名称"); + Assert.assertEquals(array3[2], "BusinessName"); Assert.assertEquals(array3[3], "f9e287fad9e84cff8b2c2f2ed92adbe6"); Assert.assertEquals(array3[4], "1"); Assert.assertEquals(array3[5], "userwyh"); Assert.assertEquals(array3[6], "110"); - Assert.assertEquals(array3[7], "测试MDC打印三"); + Assert.assertEquals(array3[7], "Test MDC print three"); } diff --git a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/base/AbstractTestBase.java b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/base/AbstractTestBase.java index 39c51d71..66ae792b 100644 --- a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/base/AbstractTestBase.java +++ b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/base/AbstractTestBase.java @@ -80,19 +80,18 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) { statKey .setKey(buildString(new String[] { fromApp, toApp, serviceName, methodName })); statKey.setResult(true ? "Y" : "N"); - //压测 + //Pressure measurement String mark = StringUtils.isBlank(sofaTracerSpan.getTagsWithStr().get( SofaTracerConstant.LOAD_TEST_TAG)) ? "F" : "T"; statKey.setEnd(buildString(new String[] { mark, zone })); - //必须设置,和mark不同,这个只打印mark + //Must be set, unlike mark, this only prints mark statKey.setLoadTest(TracerUtils.isLoadTest(sofaTracerSpan)); - - //次数和耗时,最后一个耗时是单独打印的字段 + //Times and time, the last time is a separately printed field long values[] = new long[] { 1, duration }; addStat(statKey, values); } }; - //摘要日志 + String clientLogType = TracerTestLogEnum.RPC_CLIENT_DIGEST.getDefaultLogName(); //client DiskReporterImpl clientDigestReporter = new DiskReporterImpl(clientLogType, @@ -112,18 +111,14 @@ public void doReportStat(SofaTracerSpan sofaTracerSpan) { String zone = "targetZone"; String serviceName = "service"; String methodName = "method"; - //key 关键字 {@link com.alipay.common.tracer.core.reporter.stat.AbstractSofaTracerStatisticReporter.print} + //key {@link com.alipay.common.tracer.core.reporter.stat.AbstractSofaTracerStatisticReporter.print} statKey .setKey(buildString(new String[] { fromApp, toApp, serviceName, methodName })); statKey.setResult(true ? "Y" : "N"); - //压测 String mark = StringUtils.isBlank(sofaTracerSpan.getTagsWithStr().get( SofaTracerConstant.LOAD_TEST_TAG)) ? "F" : "T"; statKey.setEnd(buildString(new String[] { mark, zone })); - //必须设置,和mark不同,这个只打印mark statKey.setLoadTest(TracerUtils.isLoadTest(sofaTracerSpan)); - - //次数和耗时,最后一个耗时是单独打印的字段 long values[] = new long[] { 1, duration }; addStat(statKey, values); } @@ -162,11 +157,11 @@ public void clearConfig() { SofaTracerConfiguration.setProperty( SofaTracerConfiguration.DISABLE_MIDDLEWARE_DIGEST_LOG_KEY, "false"); SofaTracerConfiguration.setProperty(SofaTracerConfiguration.DISABLE_DIGEST_LOG_KEY, - new HashMap()); + new HashMap<>()); } /** - * 清理日志文件夹 + * Clean up the log folder * * @throws IOException */ @@ -179,7 +174,7 @@ public static void cleanLogDirectory() throws IOException { } /** - * 检查 Tracer 本身是否含有错误 + * Check Whether Tracer itself contains errors */ protected void checkSelfLogContainsError() throws IOException { File tracerSelfLog = new File(logDirectory + File.separator + "tracer-self.log"); @@ -190,7 +185,7 @@ protected void checkSelfLogContainsError() throws IOException { String selfLogContent = FileUtils.readFileToString(tracerSelfLog); boolean result = (selfLogContent == null || !selfLogContent.contains("ERROR")); - Assert.assertTrue("Tracer 中包含错误" + selfLogContent, result); + Assert.assertTrue("Tracer contains an error " + selfLogContent, result); } protected static File customFileLog(String fileName) { @@ -198,13 +193,12 @@ protected static File customFileLog(String fileName) { } public SofaTracerSpan recoverServerSpan(String serverSpanId) { - //假设反序列化回的信息 - //生成 traceId + //Hypothetically back information + //create traceId String traceId = TraceIdGenerator.generate(); - //默认不采样 + //default sampled false SofaTracerSpanContext spanContext = new SofaTracerSpanContext(traceId, serverSpanId, StringUtils.EMPTY_STRING, true); - String callServiceName = "callServiceName"; //create server SofaTracerSpan serverSpan = new SofaTracerSpan(tracer, System.currentTimeMillis(), diff --git a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerDemoTest.java b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerDemoTest.java index 52b396c9..64a5ab30 100644 --- a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerDemoTest.java +++ b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerDemoTest.java @@ -52,8 +52,8 @@ public void beforeMethod() throws IOException { } } - /**** - * 测试摘要日志 + /** + * Test digest log * @throws InterruptedException * @throws IOException */ @@ -62,7 +62,7 @@ public void testBuildTracer() throws Exception { String serverSpanId = "0.1"; SofaTracerSpan serverSpan = recoverServerSpan(serverSpanId); SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext(); - //放到线程上下文 + //Put into the thread context sofaTraceContext.push(serverSpan); //create client1 diff --git a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerStatisticsDemoTest.java b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerStatisticsDemoTest.java index 4a2d9ee5..8a594f0d 100644 --- a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerStatisticsDemoTest.java +++ b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/SofaTracerStatisticsDemoTest.java @@ -64,15 +64,15 @@ public void beforeTest() throws Exception { @Test public void testBuildTracerStatisticsTest() throws Exception { - //清除上下文避免影响 + //Clear context to avoid impact SofaTraceContextHolder.getSofaTraceContext().clear(); String serverSpanId = "0.2.3"; SofaTracerSpan serverSpan = recoverServerSpan(serverSpanId); SofaTraceContext sofaTraceContext = SofaTraceContextHolder.getSofaTraceContext(); - //放到线程上下文 + //Put into the thread context sofaTraceContext.push(serverSpan); - //在调用5次 + //Call 5 times int times = 5; callClientTimes(times); diff --git a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/type/TracerTestLogEnum.java b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/type/TracerTestLogEnum.java index 4674c9ab..9354717a 100644 --- a/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/type/TracerTestLogEnum.java +++ b/tracer-test/core-test/src/test/java/com/alipay/common/tracer/test/core/sofatracer/type/TracerTestLogEnum.java @@ -24,7 +24,7 @@ */ public enum TracerTestLogEnum { - // 摘要日志 + // digest RPC_CLIENT_DIGEST("rpc_client_log_name_reserve", "rpc_client_digest.log", "rpc_client_rolling"), RPC_SERVER_DIGEST( "rpc_server_log_name_reserve", "rpc_server_digest.log", @@ -35,20 +35,10 @@ public enum TracerTestLogEnum { "rpc_server_log_name_reserve", "rpc_server_stat.log", "rpc_server_rolling"), ; - - /*** - * 获取保留天数 getLogReverseDay 关键字 - */ private String logReverseKey; - /*** - * 默认生成的日志名字 .log 结尾同时作为一个类型 - */ private String defaultLogName; - /*** - * 日志的滚动策略 - */ private String rollingKey; TracerTestLogEnum(String logReverseKey, String defaultLogName, String rollingKey) { diff --git a/tracer-test/log4j-test/src/test/java/com/alipay/common/tracer/LogTest.java b/tracer-test/log4j-test/src/test/java/com/alipay/common/tracer/LogTest.java index c690a6fe..4caa6011 100644 --- a/tracer-test/log4j-test/src/test/java/com/alipay/common/tracer/LogTest.java +++ b/tracer-test/log4j-test/src/test/java/com/alipay/common/tracer/LogTest.java @@ -32,9 +32,9 @@ import java.util.Scanner; /** - * 将控制台的输出重定向到项目目录下的output.txt中方便之后对文件中的内容读取并测试 + * Redirect the console output to output.txt in the project directory, then read and test the contents of the file. * @author luoguimu123 - * @version $Id: LogTest.java, v 0.1 2017年08月05日 上午7:59 luoguimu123 Exp $ + * @version $Id: LogTest.java, v 0.1 August 5, 2017 7:59 AM luoguimu123 Exp $ */ public class LogTest { diff --git a/tracer-test/log4j2-test/src/test/java/com/alipay/common/tracer/LogTest.java b/tracer-test/log4j2-test/src/test/java/com/alipay/common/tracer/LogTest.java index e7d510c9..646bc4bc 100644 --- a/tracer-test/log4j2-test/src/test/java/com/alipay/common/tracer/LogTest.java +++ b/tracer-test/log4j2-test/src/test/java/com/alipay/common/tracer/LogTest.java @@ -34,7 +34,7 @@ /** * * @author luoguimu123 - * @version $Id: LogTest.java, v 0.1 2017年08月05日 上午8:06 luoguimu123 Exp $ + * @version $Id: LogTest.java, v 0.1 August 5, 2017 8:06 AM luoguimu123 Exp $ */ public class LogTest { diff --git a/tracer-test/logback-test/src/test/java/com/alipay/commom/tracer/LogTest.java b/tracer-test/logback-test/src/test/java/com/alipay/commom/tracer/LogTest.java index e5b17bf2..79f94914 100644 --- a/tracer-test/logback-test/src/test/java/com/alipay/commom/tracer/LogTest.java +++ b/tracer-test/logback-test/src/test/java/com/alipay/commom/tracer/LogTest.java @@ -32,9 +32,9 @@ import java.util.Scanner; /** - * 将控制台的输出重定向到项目目录下的output.txt中方便之后对文件中的内容读取并测试 + * Redirect the console output to output.txt in the project directory, then read and test the contents of the file. * @author luoguimu123 - * @version $Id: LogTest.java, v 0.1 2017年08月05日 上午7:59 luoguimu123 Exp $ + * @version $Id: LogTest.java, v 0.1 August 5, 2017 7:59 AM luoguimu123 Exp $ */ public class LogTest {