fix:2.5.0

1. 修复钉钉发送失败问题
2. 客户端异常信息添加空间ID
3. 修复告警阈值没有匹配最大重试次数问题
This commit is contained in:
byteblogs168 2023-12-09 22:12:55 +08:00
parent 9d553ab2c1
commit 8e9eafb4c8
9 changed files with 128 additions and 54 deletions

View File

@ -47,16 +47,17 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static String retryErrorMoreThresholdTextMessageFormatter =
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试组件异常</font> \r\n" +
"> 名称:{} \r\n" +
"> 时间:{} \r\n" +
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试组件异常</font> \n" +
"> 空间ID:{} \n" +
"> 名称:{} \n" +
"> 时间:{} \n" +
"> 异常:{} \n";
private final StandardEnvironment standardEnvironment;
private final RetryStrategy retryStrategy;
public EasyRetryInterceptor(StandardEnvironment standardEnvironment,
RetryStrategy localRetryStrategies) {
RetryStrategy localRetryStrategies) {
this.standardEnvironment = standardEnvironment;
this.retryStrategy = localRetryStrategies;
}
@ -84,10 +85,10 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
} finally {
LogUtils.debug(log, "Start retrying. traceId:[{}] scene:[{}] executorClassName:[{}]", traceId,
retryable.scene(), executorClassName);
retryable.scene(), executorClassName);
// 入口则开始处理重试
retryerResultContext = doHandlerRetry(invocation, traceId, retryable, executorClassName, methodEntrance,
throwable);
throwable);
}
LogUtils.debug(log, "Method return value is [{}]. traceId:[{}]", result, traceId, throwable);
@ -96,8 +97,8 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
if (Objects.nonNull(retryerResultContext)) {
// 重试成功直接返回结果 若注解配置了isThrowException=false 则不抛出异常
if (retryerResultContext.getRetryResultStatusEnum().getStatus()
.equals(RetryResultStatusEnum.SUCCESS.getStatus())
|| !retryable.isThrowException()) {
.equals(RetryResultStatusEnum.SUCCESS.getStatus())
|| !retryable.isThrowException()) {
// 若返回值是NULL且是基本类型则返回默认值
Method method = invocation.getMethod();
@ -119,32 +120,32 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
private RetryerResultContext doHandlerRetry(MethodInvocation invocation, String traceId, Retryable retryable,
String executorClassName, String methodEntrance, Throwable throwable) {
String executorClassName, String methodEntrance, Throwable throwable) {
if (!RetrySiteSnapshot.isMethodEntrance(methodEntrance)
|| RetrySiteSnapshot.isRunning()
|| Objects.isNull(throwable)
// 重试流量不开启重试
|| RetrySiteSnapshot.isRetryFlow()
// 下游响应不重试码不开启重试
|| RetrySiteSnapshot.isRetryForStatusCode()
// 匹配异常信息
|| !validate(throwable, RetryerInfoCache.get(retryable.scene(), executorClassName))
|| RetrySiteSnapshot.isRunning()
|| Objects.isNull(throwable)
// 重试流量不开启重试
|| RetrySiteSnapshot.isRetryFlow()
// 下游响应不重试码不开启重试
|| RetrySiteSnapshot.isRetryForStatusCode()
// 匹配异常信息
|| !validate(throwable, RetryerInfoCache.get(retryable.scene(), executorClassName))
) {
if (!RetrySiteSnapshot.isMethodEntrance(methodEntrance)) {
LogUtils.debug(log, "Non-method entry does not enable local retries. traceId:[{}] [{}]", traceId,
RetrySiteSnapshot.getMethodEntrance());
RetrySiteSnapshot.getMethodEntrance());
} else if (RetrySiteSnapshot.isRunning()) {
LogUtils.debug(log, "Existing running retry tasks do not enable local retries. traceId:[{}] [{}]",
traceId, EnumStage.valueOfStage(RetrySiteSnapshot.getStage()));
traceId, EnumStage.valueOfStage(RetrySiteSnapshot.getStage()));
} else if (Objects.isNull(throwable)) {
LogUtils.debug(log, "No exception, no local retries. traceId:[{}]", traceId);
} else if (RetrySiteSnapshot.isRetryFlow()) {
LogUtils.debug(log, "Retry traffic does not enable local retries. traceId:[{}] [{}]", traceId,
RetrySiteSnapshot.getRetryHeader());
RetrySiteSnapshot.getRetryHeader());
} else if (RetrySiteSnapshot.isRetryForStatusCode()) {
LogUtils.debug(log, "Existing exception retry codes do not enable local retries. traceId:[{}]",
traceId);
traceId);
} else if (!validate(throwable, RetryerInfoCache.get(retryable.scene(), executorClassName))) {
LogUtils.debug(log, "Exception mismatch. traceId:[{}]", traceId);
} else {
@ -157,7 +158,7 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
}
private RetryerResultContext openRetry(MethodInvocation point, String traceId, Retryable retryable,
String executorClassName, Throwable throwable) {
String executorClassName, Throwable throwable) {
try {
@ -165,7 +166,7 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
initHeaders(retryable);
RetryerResultContext context = retryStrategy.openRetry(retryable.scene(), executorClassName,
point.getArguments());
point.getArguments());
if (RetryResultStatusEnum.SUCCESS.getStatus().equals(context.getRetryResultStatusEnum().getStatus())) {
LogUtils.debug(log, "local retry successful. traceId:[{}] result:[{}]", traceId, context.getResult());
} else {
@ -204,6 +205,7 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
AlarmContext context = AlarmContext.build()
.text(retryErrorMoreThresholdTextMessageFormatter,
EnvironmentUtils.getActiveProfile(),
standardEnvironment.getProperty("easy-retry.namespace", StrUtil.EMPTY),
EasyRetryProperties.getGroup(),
LocalDateTime.now().format(formatter),
e.getMessage())
@ -247,7 +249,7 @@ public class EasyRetryInterceptor implements MethodInterceptor, AfterAdvice, Ser
@Override
public int getOrder() {
String order = standardEnvironment
.getProperty("easy-retry.aop.order", String.valueOf(Ordered.HIGHEST_PRECEDENCE));
.getProperty("easy-retry.aop.order", String.valueOf(Ordered.HIGHEST_PRECEDENCE));
return Integer.parseInt(order);
}

View File

@ -40,9 +40,10 @@ import java.util.concurrent.TimeUnit;
public class ReportListener implements Listener<RetryTaskDTO> {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static String reportErrorTextMessageFormatter =
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 上报失败</font> \r\n" +
"> 名称:{} \r\n" +
"> 时间:{} \r\n" +
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 异步批量上报异常</font> \n" +
"> 空间ID:{} n" +
"> 名称:{} \n" +
"> 时间:{} \n" +
"> 异常:{} \n"
;
@ -106,20 +107,24 @@ public class ReportListener implements Listener<RetryTaskDTO> {
try {
ConfigDTO.Notify notifyAttribute = GroupVersionCache.getNotifyAttribute(NotifySceneEnum.CLIENT_REPORT_ERROR.getNotifyScene());
if (Objects.nonNull(notifyAttribute)) {
AlarmContext context = AlarmContext.build()
.text(reportErrorTextMessageFormatter,
EnvironmentUtils.getActiveProfile(),
EasyRetryProperties.getGroup(),
LocalDateTime.now().format(formatter),
e.getMessage())
.title("上报异常:[{}]", EasyRetryProperties.getGroup())
.notifyAttribute(notifyAttribute.getNotifyAttribute());
EasyRetryAlarmFactory easyRetryAlarmFactory = SpringContext.getBeanByType(EasyRetryAlarmFactory.class);
Alarm<AlarmContext> alarmType = easyRetryAlarmFactory.getAlarmType(notifyAttribute.getNotifyType());
alarmType.asyncSendMessage(context);
if (Objects.isNull(notifyAttribute)) {
return;
}
EasyRetryProperties properties = SpringContext.CONTEXT.getBean(EasyRetryProperties.class);
AlarmContext context = AlarmContext.build()
.text(reportErrorTextMessageFormatter,
EnvironmentUtils.getActiveProfile(),
properties.getNamespace(),
EasyRetryProperties.getGroup(),
LocalDateTime.now().format(formatter),
e.getMessage())
.title("上报异常:[{}]", EasyRetryProperties.getGroup())
.notifyAttribute(notifyAttribute.getNotifyAttribute());
EasyRetryAlarmFactory easyRetryAlarmFactory = SpringContext.getBeanByType(EasyRetryAlarmFactory.class);
Alarm<AlarmContext> alarmType = easyRetryAlarmFactory.getAlarmType(notifyAttribute.getNotifyType());
alarmType.asyncSendMessage(context);
} catch (Exception e1) {
LogUtils.error(log, "客户端发送组件异常告警失败", e1);
}

View File

@ -1,16 +1,29 @@
package com.aizuda.easy.retry.client.core.report;
import com.aizuda.easy.retry.client.common.cache.GroupVersionCache;
import com.aizuda.easy.retry.client.common.config.EasyRetryProperties;
import com.aizuda.easy.retry.client.common.proxy.RequestBuilder;
import com.aizuda.easy.retry.client.core.client.NettyClient;
import com.aizuda.easy.retry.client.core.retryer.RetryerInfo;
import com.aizuda.easy.retry.common.core.alarm.Alarm;
import com.aizuda.easy.retry.common.core.alarm.AlarmContext;
import com.aizuda.easy.retry.common.core.alarm.EasyRetryAlarmFactory;
import com.aizuda.easy.retry.common.core.context.SpringContext;
import com.aizuda.easy.retry.common.core.enums.NotifySceneEnum;
import com.aizuda.easy.retry.common.core.log.LogUtils;
import com.aizuda.easy.retry.common.core.model.NettyResult;
import com.aizuda.easy.retry.common.core.util.EnvironmentUtils;
import com.aizuda.easy.retry.common.core.util.JsonUtil;
import com.aizuda.easy.retry.server.model.dto.ConfigDTO;
import com.aizuda.easy.retry.server.model.dto.RetryTaskDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
@ -24,6 +37,19 @@ import java.util.concurrent.TimeUnit;
@Slf4j
public class SyncReport extends AbstractReport {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static String reportErrorTextMessageFormatter =
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 同步上报异常</font> \n" +
"> 空间ID:{} \n" +
"> 名称:{} \n" +
"> 时间:{} \n" +
"> 异常:{} \n"
;
@Autowired
private EasyRetryProperties easyRetryProperties;
@Override
public boolean supports(boolean async) {
return !async;
@ -49,11 +75,42 @@ public class SyncReport extends AbstractReport {
.unit(unit)
.build();
NettyResult result = client.reportRetryInfo(Collections.singletonList(retryTaskDTO));
LogUtils.debug(log, "Data report result result:[{}]", JsonUtil.toJsonString(result));
try {
NettyResult result = client.reportRetryInfo(Collections.singletonList(retryTaskDTO));
LogUtils.debug(log, "Data report result result:[{}]", JsonUtil.toJsonString(result));
return (Boolean) result.getData();
} catch (Exception e) {
sendMessage(e);
throw e;
}
return (Boolean) result.getData();
}
private void sendMessage(Throwable e) {
try {
ConfigDTO.Notify notifyAttribute = GroupVersionCache.getNotifyAttribute(NotifySceneEnum.CLIENT_REPORT_ERROR.getNotifyScene());
if (Objects.isNull(notifyAttribute)) {
return;
}
AlarmContext context = AlarmContext.build()
.text(reportErrorTextMessageFormatter,
EnvironmentUtils.getActiveProfile(),
easyRetryProperties.getNamespace(),
EasyRetryProperties.getGroup(),
LocalDateTime.now().format(formatter),
e.getMessage())
.title("同步上报异常:[{}]", EasyRetryProperties.getGroup())
.notifyAttribute(notifyAttribute.getNotifyAttribute());
EasyRetryAlarmFactory easyRetryAlarmFactory = SpringContext.getBeanByType(EasyRetryAlarmFactory.class);
Alarm<AlarmContext> alarmType = easyRetryAlarmFactory.getAlarmType(notifyAttribute.getNotifyType());
alarmType.asyncSendMessage(context);
} catch (Exception e1) {
LogUtils.error(log, "客户端发送组件异常告警失败", e1);
}
}
}

View File

@ -40,9 +40,10 @@ import java.util.function.Consumer;
public abstract class AbstractRetryStrategies implements RetryStrategy {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static String retryErrorMoreThresholdTextMessageFormatter =
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试组件异常</font> \r\n" +
"> 名称:{} \r\n" +
"> 时间:{} \r\n" +
"<font face=\"微软雅黑\" color=#ff0000 size=4>{}环境 重试期间发生非预期异常</font> \n" +
"> 空间ID:{} \n" +
"> 名称:{} \n" +
"> 时间:{} \n" +
"> 异常:{} \n"
;
@ -52,6 +53,8 @@ public abstract class AbstractRetryStrategies implements RetryStrategy {
private EasyRetryAlarmFactory easyRetryAlarmFactory;
@Autowired
private List<Report> reports;
@Autowired
private EasyRetryProperties easyRetryProperties;
@Override
public RetryerResultContext openRetry(String sceneName, String executorClassName, Object[] params) {
@ -176,6 +179,7 @@ public abstract class AbstractRetryStrategies implements RetryStrategy {
AlarmContext context = AlarmContext.build()
.text(retryErrorMoreThresholdTextMessageFormatter,
EnvironmentUtils.getActiveProfile(),
easyRetryProperties.getNamespace(),
EasyRetryProperties.getGroup(),
LocalDateTime.now().format(formatter),
e.getMessage())

View File

@ -53,8 +53,8 @@ public class DingDingUtils {
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle(title);
request.setMarkdown(markdown);
markdown.setText(subTextLength(getAtText(ats, text)));
request.setMarkdown(markdown);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
at.setAtMobiles(ats);
@ -81,9 +81,10 @@ public class DingDingUtils {
public static boolean sendMessage(OapiRobotSendRequest request, String url) {
try {
if (StrUtil.isNotBlank(url)) {
if (StrUtil.isBlank(url)) {
return false;
}
DingTalkClient client = new DefaultDingTalkClient(url);
client.execute(request);

View File

@ -119,7 +119,7 @@ public abstract class AbstractAlarm<E extends ApplicationEvent, A extends AlarmI
}
if (Objects.nonNull(alarmDTO.getCount()) && Objects.nonNull(notifyConfig.getNotifyThreshold())) {
if (notifyConfig.getNotifyThreshold() > alarmDTO.getCount()) {
if (notifyConfig.getNotifyThreshold() >= alarmDTO.getCount()) {
continue;
}
}

View File

@ -20,7 +20,7 @@ import java.util.List;
*/
@RestController
@RequestMapping("/scene-config")
public class SceneConfigSceneController {
public class SceneConfigController {
@Autowired
private SceneConfigService sceneConfigService;

View File

@ -67,7 +67,7 @@ public class SceneConfigServiceImpl implements SceneConfigService {
List<SceneConfig> sceneConfigs = accessTemplate.getSceneConfigAccess()
.list(new LambdaQueryWrapper<SceneConfig>()
.select(SceneConfig::getSceneName, SceneConfig::getDescription)
.select(SceneConfig::getSceneName, SceneConfig::getDescription, SceneConfig::getMaxRetryCount)
.eq(SceneConfig::getNamespaceId, namespaceId)
.eq(SceneConfig::getGroupName, groupName)
.orderByDesc(SceneConfig::getCreateDt));

View File

@ -42,6 +42,7 @@
v-else
id="inputNumber"
:min="1"
:max="maxNotifyThreshold"
style="width: -webkit-fill-available"
v-decorator="[
'notifyThreshold',
@ -63,8 +64,8 @@
</a-col>
<a-col :lg="6" :md="12" :sm="24">
<a-form-item label="场景">
<a-select :disabled="sceneNameDisabled.includes(this.notifySceneValue)" placeholder="请选择场景" v-decorator="['sceneName', { rules: [{ required: !sceneNameDisabled.includes(this.notifySceneValue), message: '请选择场景' }] }]" >
<a-select-option v-for="item in sceneList" :value="item.sceneName" :key="item.sceneName">{{ item.sceneName }}</a-select-option>
<a-select :disabled="sceneNameDisabled.includes(this.notifySceneValue)" placeholder="请选择场景" v-decorator="['sceneName', { rules: [{ required: !sceneNameDisabled.includes(this.notifySceneValue), message: '请选择场景' }] }]" @select="changeSceneName">
<a-select-option v-for="item in sceneList" :value="item.sceneName" :maxRetryCount="item.maxRetryCount" :key="item.sceneName">{{ item.sceneName }}</a-select-option>
</a-select>
</a-form-item>
</a-col>
@ -321,7 +322,8 @@ export default {
notifySceneValue: '1',
rateLimiterStatusValue: '0',
defaultRateLimiterStatusValue: '0',
defaultRateLimiterThreshold: '100'
defaultRateLimiterThreshold: '100',
maxNotifyThreshold: 999
}
},
beforeCreate () {
@ -365,6 +367,9 @@ export default {
this.sceneList = res.data
})
},
changeSceneName (value, option) {
this.maxNotifyThreshold = option.data.attrs.maxRetryCount
},
changeRateLimiterStatus (rateLimiterStatus) {
this.rateLimiterStatusValue = rateLimiterStatus
},