From c820fcda3f08d1d502593f82a0a6247255ec3fbf Mon Sep 17 00:00:00 2001 From: byteblogs168 <598092184@qq.com> Date: Wed, 20 Mar 2024 23:30:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=203.2.0=201.=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E7=B1=BB=EF=BC=8C=E9=81=BF=E5=85=8D=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/report/AbstractLogReport.java | 41 ++++++++++++++++++- .../retry/client/core/log/RetryLogReport.java | 31 ++++++++++++++ .../client/job/core/log/JobLogReport.java | 31 ++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogReport.java create mode 100644 easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogReport.java diff --git a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java index 3e061369..79538385 100644 --- a/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java +++ b/easy-retry-client/easy-retry-client-common/src/main/java/com/aizuda/easy/retry/client/common/report/AbstractLogReport.java @@ -1,15 +1,54 @@ package com.aizuda.easy.retry.client.common.report; +import com.aizuda.easy.retry.client.common.Lifecycle; +import com.aizuda.easy.retry.client.common.config.EasyRetryProperties; +import com.aizuda.easy.retry.client.common.window.SlidingWindow; +import com.aizuda.easy.retry.common.log.EasyRetryLog; import com.aizuda.easy.retry.common.log.dto.LogContentDTO; +import com.aizuda.easy.retry.server.model.dto.LogTaskDTO; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Objects; /** * @author xiaowoniu * @date 2024-03-20 22:56:53 * @since 3.2.0 */ -public abstract class AbstractLogReport implements LogReport{ +public abstract class AbstractLogReport implements Lifecycle, LogReport { + @Autowired + private EasyRetryProperties easyRetryProperties; + private SlidingWindow slidingWindow; @Override public void report(LogContentDTO logContentDTO) { + slidingWindow.add(buildLogTaskDTO(logContentDTO)); + } + protected abstract LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO); + + @Override + public void start() { + + EasyRetryProperties.LogSlidingWindowConfig logSlidingWindow = easyRetryProperties.getLogSlidingWindow(); + + slidingWindow = SlidingWindow + .Builder + .newBuilder() + .withTotalThreshold(logSlidingWindow.getTotalThreshold()) + .withWindowTotalThreshold(logSlidingWindow.getWindowTotalThreshold()) + .withDuration(logSlidingWindow.getDuration(), logSlidingWindow.getChronoUnit()) + .withListener(new ReportLogListener()) + .build(); + + slidingWindow.start(); + } + + @Override + public void close() { + EasyRetryLog.LOCAL.info("AsyncReport Log about to shutdown"); + if (Objects.nonNull(slidingWindow)) { + slidingWindow.end(); + } + EasyRetryLog.LOCAL.info("AsyncReport Log has been shutdown"); } } diff --git a/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogReport.java b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogReport.java new file mode 100644 index 00000000..ae1d8626 --- /dev/null +++ b/easy-retry-client/easy-retry-client-core/src/main/java/com/aizuda/easy/retry/client/core/log/RetryLogReport.java @@ -0,0 +1,31 @@ +package com.aizuda.easy.retry.client.core.log; + +import com.aizuda.easy.retry.client.common.report.AbstractLogReport; +import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.common.core.model.JobContext; +import com.aizuda.easy.retry.common.log.dto.LogContentDTO; +import com.aizuda.easy.retry.server.model.dto.LogTaskDTO; +import org.springframework.stereotype.Component; + +/** + * @author xiaowoniu + * @date 2024-03-20 23:25:24 + * @since 3.2.0 + */ +//@Component +public class RetryLogReport extends AbstractLogReport { + @Override + protected LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO) { +// JobContext context = ThreadLocalLogUtil.getContext(); + + LogTaskDTO logTaskDTO = new LogTaskDTO(); +// logTaskDTO.setJobId(context.getJobId()); +// logTaskDTO.setTaskId(context.getTaskId()); +// logTaskDTO.setTaskBatchId(context.getTaskBatchId()); +// logTaskDTO.setRealTime(logContentDTO.getTimeStamp()); +// logTaskDTO.setNamespaceId(context.getNamespaceId()); +// logTaskDTO.setGroupName(context.getGroupName()); + logTaskDTO.setFieldList(logContentDTO.getFieldList()); + return logTaskDTO; + } +} diff --git a/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogReport.java b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogReport.java new file mode 100644 index 00000000..5828428b --- /dev/null +++ b/easy-retry-client/easy-retry-client-job-core/src/main/java/com/aizuda/easy/retry/client/job/core/log/JobLogReport.java @@ -0,0 +1,31 @@ +package com.aizuda.easy.retry.client.job.core.log; + +import com.aizuda.easy.retry.client.common.report.AbstractLogReport; +import com.aizuda.easy.retry.client.common.util.ThreadLocalLogUtil; +import com.aizuda.easy.retry.common.core.model.JobContext; +import com.aizuda.easy.retry.common.log.dto.LogContentDTO; +import com.aizuda.easy.retry.server.model.dto.LogTaskDTO; +import org.springframework.stereotype.Component; + +/** + * @author xiaowoniu + * @date 2024-03-20 23:25:24 + * @since 3.2.0 + */ +//@Component +public class JobLogReport extends AbstractLogReport { + @Override + protected LogTaskDTO buildLogTaskDTO(LogContentDTO logContentDTO) { + JobContext context = ThreadLocalLogUtil.getContext(); + + LogTaskDTO logTaskDTO = new LogTaskDTO(); + logTaskDTO.setJobId(context.getJobId()); + logTaskDTO.setTaskId(context.getTaskId()); + logTaskDTO.setTaskBatchId(context.getTaskBatchId()); + logTaskDTO.setRealTime(logContentDTO.getTimeStamp()); + logTaskDTO.setNamespaceId(context.getNamespaceId()); + logTaskDTO.setGroupName(context.getGroupName()); + logTaskDTO.setFieldList(logContentDTO.getFieldList()); + return logTaskDTO; + } +}