Skip to content

Commit

Permalink
fixed review options
Browse files Browse the repository at this point in the history
  • Loading branch information
chengyouling committed Jul 18, 2024
1 parent 12b5f6c commit 6eea2ff
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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";

Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +40,7 @@ public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next)
}

private ClientResponse logServiceInfo(ClientResponse response, ClientRequest request) {
if (response.statusCode() != HttpStatusCode.valueOf(200)) {
if (response.statusCode().value() != 200) {
Optional<Object> invocationContext = request.attribute(RetryContext.RETRY_SERVICE_INSTANCE);
if (invocationContext.isPresent() && invocationContext.get() instanceof ServiceInstance instance) {
LOGGER.error("request >>>>>>>>>>>>>> service {}[{}:{}] failed", instance.getServiceId(), instance.getHost(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {

@Override
public int getOrder() {
return GovernanceProperties.WEB_FILTER_REQUEST_SERVICE_LOGGER_ORDER;
return GovernanceProperties.WEB_FILTER_REQUEST_LOGGER_ORDER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public FilterRegistrationBean<RateLimitingFilter> rateLimitingFilter(
}

@Bean
@ConditionalOnProperty(value = GovernanceProperties.WEBMVC_REQUEST_SERVICE_LOGGER_ENABLED,
@ConditionalOnProperty(value = GovernanceProperties.WEBMVC_REQUEST_LOGGER_ENABLED,
havingValue = "true", matchIfMissing = true)
public FilterRegistrationBean<RequestServiceInfoLoggerFilter> requestServiceInfoLoggerFilter() {
FilterRegistrationBean<RequestServiceInfoLoggerFilter> 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;
}
Expand Down

0 comments on commit 6eea2ff

Please sign in to comment.