FlowStat is optional
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
package we.controller;
|
package we.controller;
|
||||||
|
|
||||||
import org.openjdk.jol.info.GraphLayout;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -74,7 +75,7 @@ public class CacheCheckController {
|
|||||||
@Resource
|
@Resource
|
||||||
private CircuitBreakManager circuitBreakManager;
|
private CircuitBreakManager circuitBreakManager;
|
||||||
|
|
||||||
@Resource
|
@Autowired(required = false)
|
||||||
private FlowStat flowStat;
|
private FlowStat flowStat;
|
||||||
|
|
||||||
@GetMapping("/gatewayGroups")
|
@GetMapping("/gatewayGroups")
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public abstract class FizzWebFilter implements WebFilter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
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);
|
return chain.filter(exchange);
|
||||||
} else {
|
} else {
|
||||||
return doFilter(exchange, chain);
|
return doFilter(exchange, chain);
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ public class FlowControlFilter extends FizzWebFilter {
|
|||||||
|
|
||||||
private static final String qps = "qps";
|
private static final String qps = "qps";
|
||||||
|
|
||||||
|
private static final String favPath = "/favicon.ico";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FlowControlFilterProperties flowControlFilterProperties;
|
private FlowControlFilterProperties flowControlFilterProperties;
|
||||||
@@ -110,28 +115,37 @@ public class FlowControlFilter extends FizzWebFilter {
|
|||||||
|
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
String path = request.getPath().value();
|
String path = request.getPath().value();
|
||||||
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
|
boolean adminReq = false, proxyTestReq = false, fizzApiReq = false, favReq = false;
|
||||||
if (secFS == -1) {
|
if (path.equals(favPath)) {
|
||||||
return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "request path should like /optional-prefix/service-name/real-biz-path");
|
exchange.getAttributes().put(WebUtils.FAV_REQUEST, Consts.S.EMPTY);
|
||||||
|
favReq = true;
|
||||||
}
|
}
|
||||||
String service = path.substring(1, secFS);
|
|
||||||
boolean adminReq = false, proxyTestReq = false, fizzApiReq = false;
|
String service = null;
|
||||||
if (service.equals(admin) || service.equals(actuator)) {
|
if (!favReq) {
|
||||||
adminReq = true;
|
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||||
exchange.getAttributes().put(WebUtils.ADMIN_REQUEST, Consts.S.EMPTY);
|
if (secFS == -1) {
|
||||||
} else if (service.equals(SystemConfig.DEFAULT_GATEWAY_TEST)) {
|
return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "request path should like /optional-prefix/service-name/real-biz-path");
|
||||||
proxyTestReq = true;
|
|
||||||
} else {
|
|
||||||
service = WebUtils.getClientService(exchange);
|
|
||||||
if (service.startsWith(_fizz)) {
|
|
||||||
fizzApiReq = true;
|
|
||||||
exchange.getAttributes().put(WebUtils.FIZZ_REQUEST, Consts.S.EMPTY);
|
|
||||||
}
|
}
|
||||||
|
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 (!favReq && flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) {
|
||||||
|
|
||||||
if (flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) {
|
|
||||||
String traceId = WebUtils.getTraceId(exchange);
|
String traceId = WebUtils.getTraceId(exchange);
|
||||||
// LogService.setBizId(traceId);
|
// LogService.setBizId(traceId);
|
||||||
org.apache.logging.log4j.ThreadContext.put(Consts.TRACE_ID, traceId);
|
org.apache.logging.log4j.ThreadContext.put(Consts.TRACE_ID, traceId);
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ public abstract class WebUtils {
|
|||||||
|
|
||||||
public static final String FIZZ_REQUEST = "fr@";
|
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 BODY_ENCRYPT = "b-ecyt";
|
||||||
|
|
||||||
public static final String ORIGINAL_ERROR = "origerr@";
|
public static final String ORIGINAL_ERROR = "origerr@";
|
||||||
@@ -117,6 +119,10 @@ public abstract class WebUtils {
|
|||||||
private WebUtils() {
|
private WebUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isFavReq(ServerWebExchange exchange) {
|
||||||
|
return exchange.getAttribute(FAV_REQUEST) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isAdminReq(ServerWebExchange exchange) {
|
public static boolean isAdminReq(ServerWebExchange exchange) {
|
||||||
return exchange.getAttribute(ADMIN_REQUEST) != null;
|
return exchange.getAttribute(ADMIN_REQUEST) != null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user