From a31cc6ee70e517fdc408b3b888ded862bca5987a Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Tue, 7 Jun 2022 18:32:47 +0800 Subject: [PATCH] FlowStat is optional --- .../we/controller/CacheCheckController.java | 3 +- .../main/java/we/filter/FizzWebFilter.java | 2 +- .../java/we/filter/FlowControlFilter.java | 50 ++++++++++++------- fizz-core/src/main/java/we/util/WebUtils.java | 6 +++ 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/fizz-core/src/main/java/we/controller/CacheCheckController.java b/fizz-core/src/main/java/we/controller/CacheCheckController.java index 4f0aa71..7d62fa6 100644 --- a/fizz-core/src/main/java/we/controller/CacheCheckController.java +++ b/fizz-core/src/main/java/we/controller/CacheCheckController.java @@ -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") diff --git a/fizz-core/src/main/java/we/filter/FizzWebFilter.java b/fizz-core/src/main/java/we/filter/FizzWebFilter.java index c348584..2f3b21a 100644 --- a/fizz-core/src/main/java/we/filter/FizzWebFilter.java +++ b/fizz-core/src/main/java/we/filter/FizzWebFilter.java @@ -31,7 +31,7 @@ public abstract class FizzWebFilter implements WebFilter { @Override public Mono 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); diff --git a/fizz-core/src/main/java/we/filter/FlowControlFilter.java b/fizz-core/src/main/java/we/filter/FlowControlFilter.java index 637abdf..77c4c43 100644 --- a/fizz-core/src/main/java/we/filter/FlowControlFilter.java +++ b/fizz-core/src/main/java/we/filter/FlowControlFilter.java @@ -78,6 +78,11 @@ public class FlowControlFilter extends FizzWebFilter { private static final String qps = "qps"; + private static final String favPath = "/favicon.ico"; + + + + @Resource private FlowControlFilterProperties flowControlFilterProperties; @@ -111,28 +116,37 @@ public class FlowControlFilter extends FizzWebFilter { ServerHttpRequest request = exchange.getRequest(); String path = request.getPath().value(); - 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"); + 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 = path.substring(1, secFS); - boolean adminReq = false, proxyTestReq = false, fizzApiReq = false; - if (service.equals(admin) || service.equals(actuator)) { - adminReq = true; - exchange.getAttributes().put(WebUtils.ADMIN_REQUEST, Consts.S.EMPTY); - } else if (service.equals(SystemConfig.DEFAULT_GATEWAY_TEST)) { - proxyTestReq = true; - } else { - service = WebUtils.getClientService(exchange); - if (service.startsWith(_fizz)) { - fizzApiReq = true; - exchange.getAttributes().put(WebUtils.FIZZ_REQUEST, Consts.S.EMPTY); + + 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"); } + service = path.substring(1, secFS); + + if (service.equals(admin) || service.equals(actuator)) { + adminReq = true; + exchange.getAttributes().put(WebUtils.ADMIN_REQUEST, Consts.S.EMPTY); + } else if (service.equals(SystemConfig.DEFAULT_GATEWAY_TEST)) { + proxyTestReq = true; + } else { + service = WebUtils.getClientService(exchange); + if (service.startsWith(_fizz)) { + fizzApiReq = true; + exchange.getAttributes().put(WebUtils.FIZZ_REQUEST, Consts.S.EMPTY); + } + } + + setTraceId(exchange); } - setTraceId(exchange); - - if (flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) { + if (!favReq && flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) { String traceId = WebUtils.getTraceId(exchange); LogService.setBizId(traceId); if (!apiConfigService.serviceConfigMap.containsKey(service)) { diff --git a/fizz-core/src/main/java/we/util/WebUtils.java b/fizz-core/src/main/java/we/util/WebUtils.java index d02f8f2..983ca76 100644 --- a/fizz-core/src/main/java/we/util/WebUtils.java +++ b/fizz-core/src/main/java/we/util/WebUtils.java @@ -110,6 +110,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@"; @@ -118,6 +120,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; }