add - 添加 api 调用慢的告警

This commit is contained in:
wangli 2024-02-25 21:38:24 +08:00
parent 668a3c7bf4
commit ed5fb2d6fd
3 changed files with 44 additions and 2 deletions

View File

@ -69,7 +69,8 @@ public class EngineExecutionStartListener implements ExecutionListener {
private ObjectProvider<BpmnTaskDelegate> bpmTaskDelegate;
@Resource
private List<BpmnTaskAssigneeSelector> selectors;
@Value("${workflow.api.timeout:10}")
private Long apiTimeout;
@Value("${workflow.mock:false}")
private Boolean mock;
@Value("${workflow.assignee.global:true}")
@ -290,4 +291,8 @@ public class EngineExecutionStartListener implements ExecutionListener {
assigners);
});
}
public Long getApiTimeout() {
return apiTimeout;
}
}

View File

@ -35,4 +35,20 @@ public class DingTalkUtils {
request.setMarkdown(markdown);
OapiRobotSendResponse response = client.execute(request);
}
@SneakyThrows
public static void sendDingTalkForSlowUrl(String profile, Double time, String apiUrl, Object requestParam, Object responseBody) {
DingTalkClient client = new DefaultDingTalkClient(dingtalk_robot_webhook);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle("Notice 请求二方接口慢 URL, Env: " + profile);
markdown.setText("#### [" + profile + "]请求二方接口过慢\n" +
"> 接口地址: " + apiUrl + ",经过了" + time + "\n\n" +
"> 请求参数: " + JSON.toJSONString(requestParam) + "\n\n" +
"> ###### 结果: " + JSON.toJSONString(responseBody) + " \n");
request.setMarkdown(markdown);
OapiRobotSendResponse response = client.execute(request);
}
}

View File

@ -7,6 +7,8 @@ import cn.axzo.workflow.core.common.utils.BpmnMetaParserHelper;
import cn.axzo.workflow.core.deletage.BpmnTaskAssigneeSelector;
import cn.axzo.workflow.core.deletage.approverscope.ApproverScopeDTO;
import cn.axzo.workflow.core.deletage.approverscope.ApproverScopeProcessor;
import cn.axzo.workflow.core.engine.listener.EngineExecutionStartListener;
import cn.axzo.workflow.server.common.util.DingTalkUtils;
import cn.hutool.core.lang.Assert;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONUtil;
@ -39,6 +41,12 @@ import static cn.axzo.workflow.core.common.code.FlowableEngineRespCode.ENGINE_US
@Slf4j
public abstract class AbstractBpmnTaskAssigneeSelector implements BpmnTaskAssigneeSelector, ApplicationContextAware {
private ApplicationContext applicationContext;
private EngineExecutionStartListener executionStartListener;
public AbstractBpmnTaskAssigneeSelector() {
executionStartListener = applicationContext.getBean(EngineExecutionStartListener.class);
log.info("apiTimeOut: {}", executionStartListener.getApiTimeout());
}
@Override
public List<BpmnTaskDelegateAssigner> select(UserTask userTask, DelegateExecution execution,
@ -78,7 +86,20 @@ public abstract class AbstractBpmnTaskAssigneeSelector implements BpmnTaskAssign
stopWatch.start();
ApiResult<T> result = supplier.get();
stopWatch.stop();
log.info("{}-Cost:{}, Result: {}", operatorDesc, stopWatch.shortSummary(), JSONUtil.toJsonStr(result));
log.info("{}-Cost:{}, Result: {}", operatorDesc,
"StopWatch '" + stopWatch.getId() + "': running time = " + stopWatch.getTotalTimeSeconds() + " s",
JSONUtil.toJsonStr(result));
try {
if (stopWatch.getTotalTimeSeconds() > executionStartListener.getApiTimeout()) {
DingTalkUtils.sendDingTalkForSlowUrl(applicationContext.getEnvironment().getProperty("spring.profiles.active"),
stopWatch.getTotalTimeSeconds(),
extInfo,
param,
result);
}
} catch (Exception e) {
// ignore
}
Assert.notNull(result, "服务调用异常");
// 200自定义处理
if (HttpStatus.HTTP_OK != result.getCode()) {