forked from github/dataease
Merge pull request #12383 from dataease/pr@dev-v2@perf_export_panel
perf(X-Pack): 后台导出仪表板并发参数可配置
This commit is contained in:
commit
186b87c5a4
2
de-xpack
2
de-xpack
@ -1 +1 @@
|
|||||||
Subproject commit c8534a3fe6d2892bc519d7eeb345a74ebac414c7
|
Subproject commit f0cccdc95b184735f6ea73ff82eb7d84423e1464
|
@ -6,7 +6,7 @@ import java.lang.annotation.*;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
@Documented
|
||||||
public @interface DeTraffic {
|
public @interface DeTraffic {
|
||||||
int value() default 2;
|
int value() default 0;
|
||||||
|
|
||||||
String api();
|
String api();
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,11 @@ import io.dataease.traffic.dao.mapper.CoreApiTrafficMapper;
|
|||||||
import io.dataease.utils.IDUtils;
|
import io.dataease.utils.IDUtils;
|
||||||
import io.dataease.utils.LogUtil;
|
import io.dataease.utils.LogUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@ -22,6 +22,9 @@ public class DeTrafficAop {
|
|||||||
@Resource
|
@Resource
|
||||||
private CoreApiTrafficMapper coreApiTrafficMapper;
|
private CoreApiTrafficMapper coreApiTrafficMapper;
|
||||||
|
|
||||||
|
@Value("${dataease.traffic:2}")
|
||||||
|
private Integer defaultTraffic;
|
||||||
|
|
||||||
final private static String errorMsg = "当前API【%s】设定并发阈值为【%s】,现已经达到限流阈值,请稍后再试!";
|
final private static String errorMsg = "当前API【%s】设定并发阈值为【%s】,现已经达到限流阈值,请稍后再试!";
|
||||||
|
|
||||||
@Around(value = "@annotation(io.dataease.traffic.DeTraffic)")
|
@Around(value = "@annotation(io.dataease.traffic.DeTraffic)")
|
||||||
@ -29,9 +32,14 @@ public class DeTrafficAop {
|
|||||||
MethodSignature ms = (MethodSignature) point.getSignature();
|
MethodSignature ms = (MethodSignature) point.getSignature();
|
||||||
Method method = ms.getMethod();
|
Method method = ms.getMethod();
|
||||||
DeTraffic traffic = method.getAnnotation(DeTraffic.class);
|
DeTraffic traffic = method.getAnnotation(DeTraffic.class);
|
||||||
|
|
||||||
int value = traffic.value();
|
int value = traffic.value();
|
||||||
|
if (value == 0) {
|
||||||
|
value = defaultTraffic;
|
||||||
|
}
|
||||||
String api = traffic.api();
|
String api = traffic.api();
|
||||||
Object result = null;
|
Object result = null;
|
||||||
|
boolean access = false;
|
||||||
try {
|
try {
|
||||||
Integer count = coreApiTrafficMapper.apiCount(api);
|
Integer count = coreApiTrafficMapper.apiCount(api);
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
@ -41,19 +49,21 @@ public class DeTrafficAop {
|
|||||||
apiTraffic.setThreshold(value);
|
apiTraffic.setThreshold(value);
|
||||||
apiTraffic.setApi(api);
|
apiTraffic.setApi(api);
|
||||||
coreApiTrafficMapper.insert(apiTraffic);
|
coreApiTrafficMapper.insert(apiTraffic);
|
||||||
|
access = true;
|
||||||
result = point.proceed();
|
result = point.proceed();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
int alive = coreApiTrafficMapper.getAlive(api);
|
int alive = coreApiTrafficMapper.getAlive(api);
|
||||||
if (alive < value) {
|
if (alive < value) {
|
||||||
coreApiTrafficMapper.upgrade(api);
|
coreApiTrafficMapper.upgrade(api);
|
||||||
|
access = true;
|
||||||
result = point.proceed();
|
result = point.proceed();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e.getMessage(), e);
|
LogUtil.error(e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
if (ObjectUtils.isNotEmpty(result)) {
|
if (access) {
|
||||||
coreApiTrafficMapper.releaseAlive(api);
|
coreApiTrafficMapper.releaseAlive(api);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user