Code style
This commit is contained in:
@@ -37,8 +37,6 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* log4j2初始化时通过该类从Apollo加载相应的log4j2的配置信息
|
* log4j2初始化时通过该类从Apollo加载相应的log4j2的配置信息
|
||||||
* 当通过Apollo修改log4j2配置后,能立即生效。例如,动态修改日志级别。
|
* 当通过Apollo修改log4j2配置后,能立即生效。例如,动态修改日志级别。
|
||||||
* @author honam
|
|
||||||
* @date 2019-08-05
|
|
||||||
*/
|
*/
|
||||||
// @Plugin(name = "ApolloLog4j2ConfigurationFactory", category = ConfigurationFactory.CATEGORY)
|
// @Plugin(name = "ApolloLog4j2ConfigurationFactory", category = ConfigurationFactory.CATEGORY)
|
||||||
// @Order(50)
|
// @Order(50)
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
// /*
|
|
||||||
// * Copyright (C) 2020 the original author or authors.
|
|
||||||
// *
|
|
||||||
// * This program is free software: you can redistribute it and/or modify
|
|
||||||
// * it under the terms of the GNU General Public License as published by
|
|
||||||
// * the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// * any later version.
|
|
||||||
// *
|
|
||||||
// * This program is distributed in the hope that it will be useful,
|
|
||||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// * GNU General Public License for more details.
|
|
||||||
// *
|
|
||||||
// * You should have received a copy of the GNU General Public License
|
|
||||||
// * along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
// */
|
|
||||||
//
|
|
||||||
// package we.config;
|
|
||||||
//
|
|
||||||
// import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
// import org.springframework.context.annotation.Bean;
|
|
||||||
// import org.springframework.context.annotation.Configuration;
|
|
||||||
// import org.springframework.web.reactive.function.client.WebClient;
|
|
||||||
// import reactor.netty.resources.LoopResources;
|
|
||||||
// import we.util.JacksonUtils;
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @author hongqiaowei
|
|
||||||
// */
|
|
||||||
//
|
|
||||||
// @Configuration
|
|
||||||
// @ConfigurationProperties(prefix = AggrWebClientConfig.prefix)
|
|
||||||
// public class AggrWebClientConfig extends WebClientConfig {
|
|
||||||
//
|
|
||||||
// protected static final String prefix = "aggr-webclient";
|
|
||||||
//
|
|
||||||
// public static final String aggrWebClient = "aggrWebClient";
|
|
||||||
//
|
|
||||||
// @Bean(aggrWebClient)
|
|
||||||
// public WebClient webClient() {
|
|
||||||
// log.info(aggrWebClient + ": " + this);
|
|
||||||
// return super.webClient();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@@ -42,15 +42,17 @@ import javax.annotation.Resource;
|
|||||||
*
|
*
|
||||||
* @author zhongjie
|
* @author zhongjie
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class AggregateRedisConfig extends RedisReactiveConfig {
|
public class AggregateRedisConfig extends RedisReactiveConfig {
|
||||||
static final String AGGREGATE_REACTIVE_REDIS_PROPERTIES = "aggregateReactiveRedisProperties";
|
|
||||||
private static final String AGGREGATE_REACTIVE_REDIS_CONNECTION_FACTORY = "aggregateReactiveRedisConnectionFactory";
|
|
||||||
public static final String AGGREGATE_REACTIVE_REDIS_TEMPLATE = "aggregateReactiveRedisTemplate";
|
|
||||||
public static final String AGGREGATE_REACTIVE_REDIS_MESSAGE_LISTENER_CONTAINER = "aggregateReactiveRedisMessageListenerContainer";
|
|
||||||
|
|
||||||
private static final String SEND_LOG_TYPE_REDIS = "redis";
|
static final String AGGREGATE_REACTIVE_REDIS_PROPERTIES = "aggregateReactiveRedisProperties";
|
||||||
public static ProxyLettuceConnectionFactory proxyLettuceConnectionFactory;
|
private static final String AGGREGATE_REACTIVE_REDIS_CONNECTION_FACTORY = "aggregateReactiveRedisConnectionFactory";
|
||||||
|
public static final String AGGREGATE_REACTIVE_REDIS_TEMPLATE = "aggregateReactiveRedisTemplate";
|
||||||
|
public static final String AGGREGATE_REACTIVE_REDIS_MESSAGE_LISTENER_CONTAINER = "aggregateReactiveRedisMessageListenerContainer";
|
||||||
|
private static final String SEND_LOG_TYPE_REDIS = "redis";
|
||||||
|
|
||||||
|
public static ProxyLettuceConnectionFactory proxyLettuceConnectionFactory;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AggregateRedisConfigProperties aggregateRedisConfigProperties;
|
private AggregateRedisConfigProperties aggregateRedisConfigProperties;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package we.config;
|
package we.config;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -26,6 +27,7 @@ import org.springframework.stereotype.Component;
|
|||||||
*
|
*
|
||||||
* @author zhongjie
|
* @author zhongjie
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
@Component
|
@Component
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author unknown
|
|
||||||
*/
|
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
@Component
|
@Component
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@@ -110,25 +110,6 @@ public class FlowStatSchedConfig extends SchedConfig {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// resourceTimeWindow2totalBlockRequestsMap.clear();
|
|
||||||
// resourceTimeWindowStats.forEach(rtws -> {
|
|
||||||
// String resource = rtws.getResourceId();
|
|
||||||
// List<TimeWindowStat> wins = rtws.getWindows();
|
|
||||||
// wins.forEach(w -> {
|
|
||||||
// long t = w.getStartTime();
|
|
||||||
// long blockRequests = w.getBlockRequests();
|
|
||||||
// resourceTimeWindow2totalBlockRequestsMap.put(resource + t, new AtomicLong(blockRequests));
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
// resourceTimeWindowStats.forEach(rtws -> {
|
|
||||||
// String resource = rtws.getResourceId();
|
|
||||||
// List<TimeWindowStat> wins = rtws.getWindows();
|
|
||||||
// wins.forEach(w -> {
|
|
||||||
// accumulateParents(resource, w.getStartTime(), w.getBlockRequests());
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
resourceTimeWindowStats.forEach(
|
resourceTimeWindowStats.forEach(
|
||||||
rtws -> {
|
rtws -> {
|
||||||
String resource = rtws.getResourceId();
|
String resource = rtws.getResourceId();
|
||||||
@@ -194,8 +175,6 @@ public class FlowStatSchedConfig extends SchedConfig {
|
|||||||
pRps = peakRps.doubleValue();
|
pRps = peakRps.doubleValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// AtomicLong totalBlockRequests = resourceTimeWindow2totalBlockRequestsMap.get(resource + timeWin);
|
|
||||||
// long tbrs = (totalBlockRequests == null ? w.getBlockRequests() : w.getBlockRequests() + totalBlockRequests.longValue());
|
|
||||||
long tbrs = w.getTotalBlockRequests();
|
long tbrs = w.getTotalBlockRequests();
|
||||||
|
|
||||||
b.append(Consts.S.LEFT_BRACE);
|
b.append(Consts.S.LEFT_BRACE);
|
||||||
@@ -263,18 +242,6 @@ public class FlowStatSchedConfig extends SchedConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private void accumulateParents(String resource, long timeWin, long blockRequests) {
|
|
||||||
// List<String> prl = ThreadContext.getArrayList(parentResourceList, String.class);
|
|
||||||
// resourceRateLimitConfigService.getParentsTo(resource, prl);
|
|
||||||
// for (int i = 0; i < prl.size(); i++) {
|
|
||||||
// String parentResource = prl.get(i);
|
|
||||||
// AtomicLong parentTotalBlockRequests = resourceTimeWindow2totalBlockRequestsMap.get(parentResource + timeWin);
|
|
||||||
// if (parentTotalBlockRequests != null) {
|
|
||||||
// parentTotalBlockRequests.addAndGet(blockRequests);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private long getRecentEndTimeSlot(FlowStat flowStat) {
|
private long getRecentEndTimeSlot(FlowStat flowStat) {
|
||||||
long currentTimeSlot = flowStat.currentTimeSlotId();
|
long currentTimeSlot = flowStat.currentTimeSlotId();
|
||||||
int second = DateTimeUtils.transform(currentTimeSlot).getSecond();
|
int second = DateTimeUtils.transform(currentTimeSlot).getSecond();
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public abstract class ManualApiConfig {
|
|||||||
apiConfigService.serviceConfigMap.put(ac.service, sc);
|
apiConfigService.serviceConfigMap.put(ac.service, sc);
|
||||||
}
|
}
|
||||||
sc.add(ac);
|
sc.add(ac);
|
||||||
log.info("manual add " + ac);
|
log.info("manual add {}", ac);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class ProxyWebClientConfig extends WebClientConfig {
|
|||||||
|
|
||||||
@Bean(proxyWebClient)
|
@Bean(proxyWebClient)
|
||||||
public WebClient webClient() {
|
public WebClient webClient() {
|
||||||
log.info(proxyWebClient + ": " + this);
|
log.info("proxy web client: {}", this);
|
||||||
return super.webClient();
|
return super.webClient();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import we.util.JacksonUtils;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author unknown
|
* @author hongqiaowei
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -41,22 +41,22 @@ import javax.annotation.Resource;
|
|||||||
public class CacheCheckController {
|
public class CacheCheckController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private GatewayGroupService gatewayGroupService;
|
private GatewayGroupService gatewayGroupService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AppService appService;
|
private AppService appService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ApiConfigService apiConfigService;
|
private ApiConfigService apiConfigService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ResourceRateLimitConfigService resourceRateLimitConfigService;
|
private ResourceRateLimitConfigService resourceRateLimitConfigService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ApiConifg2appsService apiConifg2appsService;
|
private ApiConifg2appsService apiConifg2appsService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DictService dictService;
|
private DictService dictService;
|
||||||
|
|
||||||
@GetMapping("/gatewayGroups")
|
@GetMapping("/gatewayGroups")
|
||||||
public Mono<String> gatewayGroups(ServerWebExchange exchange) {
|
public Mono<String> gatewayGroups(ServerWebExchange exchange) {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* @author hongqiaowei
|
* @author hongqiaowei
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/admin/flowStat")
|
@RequestMapping("/admin/flowStat")
|
||||||
@@ -54,7 +55,6 @@ public class FlowControlController {
|
|||||||
@Value("${flowControl:false}")
|
@Value("${flowControl:false}")
|
||||||
private boolean flowControl;
|
private boolean flowControl;
|
||||||
|
|
||||||
// @Resource
|
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private FlowStat flowStat;
|
private FlowStat flowStat;
|
||||||
|
|
||||||
|
|||||||
@@ -48,11 +48,7 @@ public class CorsFilterConfig {
|
|||||||
|
|
||||||
CorsConfiguration config = new CorsConfiguration();
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
|
|
||||||
// Possibly...
|
|
||||||
// config.applyPermitDefaultValues()
|
|
||||||
|
|
||||||
config.setAllowCredentials(true);
|
config.setAllowCredentials(true);
|
||||||
// config.addAllowedOrigin("https://domain0.com");
|
|
||||||
config.addAllowedOrigin("*");
|
config.addAllowedOrigin("*");
|
||||||
|
|
||||||
// config.addAllowedMethod("*");
|
// config.addAllowedMethod("*");
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import we.util.WebUtils;
|
|||||||
@Order(0)
|
@Order(0)
|
||||||
public class FizzLogFilter implements WebFilter {
|
public class FizzLogFilter implements WebFilter {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(FizzLogFilter.class);
|
private static final Logger log = LoggerFactory.getLogger(FizzLogFilter.class);
|
||||||
|
|
||||||
private static final String resp = "\nresponse ";
|
private static final String resp = "\nresponse ";
|
||||||
|
|
||||||
@@ -47,15 +47,15 @@ public class FizzLogFilter implements WebFilter {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
return chain.filter(exchange).doFinally(
|
return chain.filter(exchange).doFinally(
|
||||||
(c) -> {
|
(c) -> {
|
||||||
if (LOGGER.isInfoEnabled()) {
|
if (log.isInfoEnabled()) {
|
||||||
StringBuilder b = ThreadContext.getStringBuilder();
|
StringBuilder b = ThreadContext.getStringBuilder();
|
||||||
WebUtils.request2stringBuilder(exchange, b);
|
WebUtils.request2stringBuilder(exchange, b);
|
||||||
b.append(resp).append(exchange.getResponse().getStatusCode())
|
b.append(resp).append(exchange.getResponse().getStatusCode())
|
||||||
.append(in) .append(System.currentTimeMillis() - startTime);
|
.append(in) .append(System.currentTimeMillis() - start);
|
||||||
LOGGER.info(b.toString(), LogService.BIZ_ID, WebUtils.getTraceId(exchange));
|
log.info(b.toString(), LogService.BIZ_ID, WebUtils.getTraceId(exchange));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -71,45 +71,44 @@ public class PreprocessFilter extends FizzWebFilter {
|
|||||||
Map<String, FilterResult> fc = new HashMap<>(); fc.put(WebUtils.PREV_FILTER_RESULT, succFr);
|
Map<String, FilterResult> fc = new HashMap<>(); fc.put(WebUtils.PREV_FILTER_RESULT, succFr);
|
||||||
Map<String, String> appendHdrs = new HashMap<>(8);
|
Map<String, String> appendHdrs = new HashMap<>(8);
|
||||||
Map<String, Object> eas = exchange.getAttributes(); eas.put(WebUtils.FILTER_CONTEXT, fc);
|
Map<String, Object> eas = exchange.getAttributes(); eas.put(WebUtils.FILTER_CONTEXT, fc);
|
||||||
eas.put(WebUtils.APPEND_HEADERS, appendHdrs);
|
eas.put(WebUtils.APPEND_HEADERS, appendHdrs);
|
||||||
|
|
||||||
Mono vm = statPluginFilter.filter(exchange, null, null);
|
Mono vm = statPluginFilter.filter(exchange, null, null);
|
||||||
return process(exchange, chain, eas, vm);
|
return process(exchange, chain, eas, vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: improve
|
|
||||||
private Mono<Void> process(ServerWebExchange exchange, WebFilterChain chain, Map<String, Object> eas, Mono vm) {
|
private Mono<Void> process(ServerWebExchange exchange, WebFilterChain chain, Map<String, Object> eas, Mono vm) {
|
||||||
return chain(exchange, vm, authPluginFilter).defaultIfEmpty(ReactorUtils.NULL)
|
return chain(exchange, vm, authPluginFilter).defaultIfEmpty(ReactorUtils.NULL)
|
||||||
.flatMap(
|
.flatMap(
|
||||||
v -> {
|
v -> {
|
||||||
Result<ApiConfig> authRes = (Result<ApiConfig>) WebUtils.getFilterResultDataItem(exchange, AuthPluginFilter.AUTH_PLUGIN_FILTER, AuthPluginFilter.RESULT);
|
Result<ApiConfig> authRes = (Result<ApiConfig>) WebUtils.getFilterResultDataItem(exchange, AuthPluginFilter.AUTH_PLUGIN_FILTER, AuthPluginFilter.RESULT);
|
||||||
if (authRes.code == Result.FAIL) {
|
if (authRes.code == Result.FAIL) {
|
||||||
return WebUtils.responseError(exchange, HttpStatus.FORBIDDEN.value(), authRes.msg);
|
return WebUtils.responseError(exchange, HttpStatus.FORBIDDEN.value(), authRes.msg);
|
||||||
}
|
}
|
||||||
Mono m = ReactorUtils.getInitiateMono();
|
Mono m = ReactorUtils.getInitiateMono();
|
||||||
ApiConfig ac = authRes.data;
|
ApiConfig ac = authRes.data;
|
||||||
if (ac == null) {
|
if (ac == null) {
|
||||||
afterAuth(exchange, null, null);
|
afterAuth(exchange, null, null);
|
||||||
m = executeFixedPluginFilters(exchange);
|
m = executeFixedPluginFilters(exchange);
|
||||||
return m.defaultIfEmpty(ReactorUtils.NULL).flatMap(func(exchange, chain));
|
return m.defaultIfEmpty(ReactorUtils.NULL).flatMap(func(exchange, chain));
|
||||||
}
|
}
|
||||||
Route route = ac.getRoute(exchange);
|
Route route = ac.getRoute(exchange);
|
||||||
eas.put(WebUtils.ROUTE, route);
|
eas.put(WebUtils.ROUTE, route);
|
||||||
afterAuth(exchange, ac, route);
|
afterAuth(exchange, ac, route);
|
||||||
m = executeFixedPluginFilters(exchange);
|
m = executeFixedPluginFilters(exchange);
|
||||||
m = m.defaultIfEmpty(ReactorUtils.NULL);
|
m = m.defaultIfEmpty(ReactorUtils.NULL);
|
||||||
if (CollectionUtils.isEmpty(route.pluginConfigs)) {
|
if (CollectionUtils.isEmpty(route.pluginConfigs)) {
|
||||||
return m.flatMap(func(exchange, chain));
|
return m.flatMap(func(exchange, chain));
|
||||||
} else {
|
} else {
|
||||||
return m.flatMap(
|
return m.flatMap(
|
||||||
nil -> {
|
nil -> {
|
||||||
eas.put(FizzPluginFilterChain.WEB_FILTER_CHAIN, chain);
|
eas.put(FizzPluginFilterChain.WEB_FILTER_CHAIN, chain);
|
||||||
return FizzPluginFilterChain.next(exchange);
|
return FizzPluginFilterChain.next(exchange);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void afterAuth(ServerWebExchange exchange, ApiConfig ac, Route route) {
|
private void afterAuth(ServerWebExchange exchange, ApiConfig ac, Route route) {
|
||||||
|
|||||||
@@ -102,10 +102,7 @@ public class RouteFilter extends FizzWebFilter {
|
|||||||
|
|
||||||
ServerHttpRequest req = exchange.getRequest();
|
ServerHttpRequest req = exchange.getRequest();
|
||||||
String traceId = WebUtils.getTraceId(exchange);
|
String traceId = WebUtils.getTraceId(exchange);
|
||||||
|
|
||||||
// ApiConfig ac = WebUtils.getApiConfig(exchange);
|
|
||||||
Route route = WebUtils.getRoute(exchange);
|
Route route = WebUtils.getRoute(exchange);
|
||||||
|
|
||||||
HttpHeaders hdrs = null;
|
HttpHeaders hdrs = null;
|
||||||
|
|
||||||
if (route.type != ApiConfig.Type.DUBBO) {
|
if (route.type != ApiConfig.Type.DUBBO) {
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
public final class FizzPluginFilterChain {
|
public final class FizzPluginFilterChain {
|
||||||
|
|
||||||
private static final String pluginConfigsIt = "@pcsit";
|
private static final String pluginConfigsIt = "pcsit@";
|
||||||
|
|
||||||
public static final String WEB_FILTER_CHAIN = "@wfc";
|
public static final String WEB_FILTER_CHAIN = "wfc@";
|
||||||
|
|
||||||
private FizzPluginFilterChain() {
|
private FizzPluginFilterChain() {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user