FlowStat is optional

This commit is contained in:
hongqiaowei
2022-06-07 18:32:47 +08:00
parent cac6e84837
commit ee40ebd899
4 changed files with 41 additions and 20 deletions

View File

@@ -18,6 +18,7 @@
package we.controller;
import org.openjdk.jol.info.GraphLayout;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -74,7 +75,7 @@ public class CacheCheckController {
@Resource
private CircuitBreakManager circuitBreakManager;
@Resource
@Autowired(required = false)
private FlowStat flowStat;
@GetMapping("/gatewayGroups")

View File

@@ -31,7 +31,7 @@ public abstract class FizzWebFilter implements WebFilter {
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
if (WebUtils.isAdminReq(exchange) || WebUtils.isFizzReq(exchange)) {
if (WebUtils.isAdminReq(exchange) || WebUtils.isFizzReq(exchange) || WebUtils.isFavReq(exchange)) {
return chain.filter(exchange);
} else {
return doFilter(exchange, chain);

View File

@@ -77,6 +77,11 @@ public class FlowControlFilter extends FizzWebFilter {
private static final String qps = "qps";
private static final String favPath = "/favicon.ico";
@Resource
private FlowControlFilterProperties flowControlFilterProperties;
@@ -110,12 +115,20 @@ public class FlowControlFilter extends FizzWebFilter {
ServerHttpRequest request = exchange.getRequest();
String path = request.getPath().value();
boolean adminReq = false, proxyTestReq = false, fizzApiReq = false, favReq = false;
if (path.equals(favPath)) {
exchange.getAttributes().put(WebUtils.FAV_REQUEST, Consts.S.EMPTY);
favReq = true;
}
String service = null;
if (!favReq) {
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
if (secFS == -1) {
return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "request path should like /optional-prefix/service-name/real-biz-path");
}
String service = path.substring(1, secFS);
boolean adminReq = false, proxyTestReq = false, fizzApiReq = false;
service = path.substring(1, secFS);
if (service.equals(admin) || service.equals(actuator)) {
adminReq = true;
exchange.getAttributes().put(WebUtils.ADMIN_REQUEST, Consts.S.EMPTY);
@@ -130,8 +143,9 @@ public class FlowControlFilter extends FizzWebFilter {
}
setTraceId(exchange);
}
if (flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) {
if (!favReq && flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) {
String traceId = WebUtils.getTraceId(exchange);
// LogService.setBizId(traceId);
org.apache.logging.log4j.ThreadContext.put(Consts.TRACE_ID, traceId);

View File

@@ -109,6 +109,8 @@ public abstract class WebUtils {
public static final String FIZZ_REQUEST = "fr@";
public static final String FAV_REQUEST = "fa@";
public static final String BODY_ENCRYPT = "b-ecyt";
public static final String ORIGINAL_ERROR = "origerr@";
@@ -117,6 +119,10 @@ public abstract class WebUtils {
private WebUtils() {
}
public static boolean isFavReq(ServerWebExchange exchange) {
return exchange.getAttribute(FAV_REQUEST) != null;
}
public static boolean isAdminReq(ServerWebExchange exchange) {
return exchange.getAttribute(ADMIN_REQUEST) != null;
}