From 6eea2ff3e1238e7b6f3f44c4c0cb95af2c6b7126 Mon Sep 17 00:00:00 2001 From: chengyouling Date: Thu, 18 Jul 2024 16:35:41 +0800 Subject: [PATCH] fixed review options --- .../configration/dynamic/GovernanceProperties.java | 14 +++++++------- .../adapters/RequestServiceInfoLoggerUtil.java | 8 +++----- .../ServiceInfoLoggerExchangeFilterFunction.java | 3 +-- .../adapters/webclient/WebClientConfiguration.java | 2 +- .../webflux/RequestServiceInfoLoggerWebFilter.java | 2 +- .../adapters/webflux/WebFluxConfiguration.java | 2 +- .../adapters/webmvc/WebMvcConfiguration.java | 4 ++-- 7 files changed, 16 insertions(+), 19 deletions(-) diff --git a/spring-cloud-huawei-common/src/main/java/com/huaweicloud/common/configration/dynamic/GovernanceProperties.java b/spring-cloud-huawei-common/src/main/java/com/huaweicloud/common/configration/dynamic/GovernanceProperties.java index 7a5727f3c..41f4e32c6 100644 --- a/spring-cloud-huawei-common/src/main/java/com/huaweicloud/common/configration/dynamic/GovernanceProperties.java +++ b/spring-cloud-huawei-common/src/main/java/com/huaweicloud/common/configration/dynamic/GovernanceProperties.java @@ -30,7 +30,7 @@ public class GovernanceProperties { public static final int WEB_FILTER_SERVICE_AUTH_ORDER = -60000; - public static final int WEB_FILTER_REQUEST_SERVICE_LOGGER_ORDER = -35000; + public static final int WEB_FILTER_REQUEST_LOGGER_ORDER = -35000; private static final int WEB_CLIENT_LOAD_BALANCE_BASE = 0; @@ -58,8 +58,8 @@ public class GovernanceProperties { public static final String WEBCLIENT_FAULT_INJECTION_ENABLED = PREFIX + "." + "webclient.faultInjection.enabled"; - public static final String WEBCLIENT_REQUEST_SERVICE_LOGGER_ENABLED = - PREFIX + "." + "webclient.requestServiceLogger.enabled"; + public static final String WEBCLIENT_REQUEST_LOGGER_ENABLED = + PREFIX + "." + "webclient.requestLogger.enabled"; public static final String GATEWAY_GOVERNANCE_ENABLED = PREFIX + "." + "gateway.governance.enabled"; @@ -83,11 +83,11 @@ public class GovernanceProperties { public static final String WEBFLUX_CONTEXT_MAPPER_ENABLED = PREFIX + "." + "webflux.contextMapper.enabled"; - public static final String WEBFLUX_REQUEST_SERVICE_LOGGER_ENABLED = - PREFIX + "." + "webflux.requestServiceLogger.enabled"; + public static final String WEBFLUX_REQUEST_LOGGER_ENABLED = + PREFIX + "." + "webflux.requestLogger.enabled"; - public static final String WEBMVC_REQUEST_SERVICE_LOGGER_ENABLED = - PREFIX + "." + "webmvc.requestServiceLogger.enabled"; + public static final String WEBMVC_REQUEST_LOGGER_ENABLED = + PREFIX + "." + "webmvc.requestLogger.enabled"; public static final String WEBMVC_RATE_LIMITING_ENABLED = PREFIX + "." + "webmvc.rateLimiting.enabled"; diff --git a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/RequestServiceInfoLoggerUtil.java b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/RequestServiceInfoLoggerUtil.java index 380143e5a..ab734f4ca 100644 --- a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/RequestServiceInfoLoggerUtil.java +++ b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/RequestServiceInfoLoggerUtil.java @@ -29,11 +29,9 @@ public class RequestServiceInfoLoggerUtil { public static void logServiceInfo(InvocationContext context, Throwable e) { if (context != null && context.getLocalContext(GovernanceConst.CONTEXT_CURRENT_INSTANCE) != null) { - if (context.getLocalContext(GovernanceConst.CONTEXT_CURRENT_INSTANCE) instanceof ServiceInstance) { - ServiceInstance instance = context.getLocalContext(GovernanceConst.CONTEXT_CURRENT_INSTANCE); - LOGGER.error("request >>>>>>>>>>>>>> service {}[{}:{}] failed", instance.getServiceId(), instance.getHost(), - instance.getPort(), e); - } + ServiceInstance instance = context.getLocalContext(GovernanceConst.CONTEXT_CURRENT_INSTANCE); + LOGGER.error("request >>>>>>>>>>>>>> service {}[{}:{}] failed", instance.getServiceId(), instance.getHost(), + instance.getPort(), e); } } } diff --git a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webclient/ServiceInfoLoggerExchangeFilterFunction.java b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webclient/ServiceInfoLoggerExchangeFilterFunction.java index 44f592267..30b987c59 100644 --- a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webclient/ServiceInfoLoggerExchangeFilterFunction.java +++ b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webclient/ServiceInfoLoggerExchangeFilterFunction.java @@ -22,7 +22,6 @@ import org.slf4j.LoggerFactory; import org.springframework.cloud.client.ServiceInstance; import org.springframework.core.Ordered; -import org.springframework.http.HttpStatusCode; import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.ExchangeFilterFunction; @@ -41,7 +40,7 @@ public Mono filter(ClientRequest request, ExchangeFunction next) } private ClientResponse logServiceInfo(ClientResponse response, ClientRequest request) { - if (response.statusCode() != HttpStatusCode.valueOf(200)) { + if (response.statusCode().value() != 200) { Optional invocationContext = request.attribute(RetryContext.RETRY_SERVICE_INSTANCE); if (invocationContext.isPresent() && invocationContext.get() instanceof ServiceInstance instance) { LOGGER.error("request >>>>>>>>>>>>>> service {}[{}:{}] failed", instance.getServiceId(), instance.getHost(), diff --git a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webclient/WebClientConfiguration.java b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webclient/WebClientConfiguration.java index 7d640a990..f8d017013 100644 --- a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webclient/WebClientConfiguration.java +++ b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webclient/WebClientConfiguration.java @@ -72,7 +72,7 @@ public StatusCodeExtractor clientResponseStatusCodeExtractor(Environment environ } @Bean - @ConditionalOnProperty(value = GovernanceProperties.WEBCLIENT_REQUEST_SERVICE_LOGGER_ENABLED, + @ConditionalOnProperty(value = GovernanceProperties.WEBCLIENT_REQUEST_LOGGER_ENABLED, havingValue = "true", matchIfMissing = true) public ServiceInfoLoggerExchangeFilterFunction serviceInfoLoggerExchangeFilterFunction() { return new ServiceInfoLoggerExchangeFilterFunction(); diff --git a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webflux/RequestServiceInfoLoggerWebFilter.java b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webflux/RequestServiceInfoLoggerWebFilter.java index 87353f04f..1f26b372b 100644 --- a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webflux/RequestServiceInfoLoggerWebFilter.java +++ b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webflux/RequestServiceInfoLoggerWebFilter.java @@ -40,6 +40,6 @@ public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { @Override public int getOrder() { - return GovernanceProperties.WEB_FILTER_REQUEST_SERVICE_LOGGER_ORDER; + return GovernanceProperties.WEB_FILTER_REQUEST_LOGGER_ORDER; } } diff --git a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webflux/WebFluxConfiguration.java b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webflux/WebFluxConfiguration.java index 4c70cff50..6da05c7d8 100644 --- a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webflux/WebFluxConfiguration.java +++ b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webflux/WebFluxConfiguration.java @@ -75,7 +75,7 @@ public WebFilter contextMapperWebFilter(@Qualifier("contextMapperHandler") Mappe } @Bean - @ConditionalOnProperty(value = GovernanceProperties.WEBFLUX_REQUEST_SERVICE_LOGGER_ENABLED, + @ConditionalOnProperty(value = GovernanceProperties.WEBFLUX_REQUEST_LOGGER_ENABLED, havingValue = "true", matchIfMissing = true) public WebFilter requestServiceInfoLoggerWebFilter() { return new RequestServiceInfoLoggerWebFilter(); diff --git a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webmvc/WebMvcConfiguration.java b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webmvc/WebMvcConfiguration.java index bae9eb1d3..97da60902 100644 --- a/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webmvc/WebMvcConfiguration.java +++ b/spring-cloud-huawei-governance/src/main/java/com/huaweicloud/governance/adapters/webmvc/WebMvcConfiguration.java @@ -55,13 +55,13 @@ public FilterRegistrationBean rateLimitingFilter( } @Bean - @ConditionalOnProperty(value = GovernanceProperties.WEBMVC_REQUEST_SERVICE_LOGGER_ENABLED, + @ConditionalOnProperty(value = GovernanceProperties.WEBMVC_REQUEST_LOGGER_ENABLED, havingValue = "true", matchIfMissing = true) public FilterRegistrationBean requestServiceInfoLoggerFilter() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); registrationBean.setFilter(new RequestServiceInfoLoggerFilter()); registrationBean.addUrlPatterns("/*"); - registrationBean.setOrder(GovernanceProperties.WEB_FILTER_REQUEST_SERVICE_LOGGER_ORDER); + registrationBean.setOrder(GovernanceProperties.WEB_FILTER_REQUEST_LOGGER_ORDER); return registrationBean; }