diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index ebe65cfe..1f1f509c 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -59,7 +59,6 @@ |spring.cloud.loadbalancer.sticky-session | | Properties for LoadBalancer sticky-session. |spring.cloud.loadbalancer.sticky-session.add-service-instance-cookie | `false` | Indicates whether a cookie with the newly selected instance should be added by LoadBalancer. |spring.cloud.loadbalancer.sticky-session.instance-id-cookie-name | `sc-lb-instance-id` | The name of the cookie holding the preferred instance id. -|spring.cloud.loadbalancer.use-raw-status-code-in-response-data | `false` | Indicates that raw status codes should be used in {@link ResponseData}. |spring.cloud.loadbalancer.x-forwarded | | Enabling X-Forwarded Host and Proto Headers. |spring.cloud.loadbalancer.x-forwarded.enabled | `false` | To Enable X-Forwarded Headers. |spring.cloud.loadbalancer.zone | | Spring Cloud LoadBalancer zone. diff --git a/docs/src/main/asciidoc/spring-cloud-commons.adoc b/docs/src/main/asciidoc/spring-cloud-commons.adoc index 9f5c12f4..90dd22f1 100644 --- a/docs/src/main/asciidoc/spring-cloud-commons.adoc +++ b/docs/src/main/asciidoc/spring-cloud-commons.adoc @@ -1222,28 +1222,20 @@ One type of bean that it may be useful to register using < request)`, `onStartRequest(Request request, Response lbResponse)` and `onComplete(CompletionContext completionContext)`, that you should implement to specify what actions should take place before and after load-balancing. -`onStart(Request request)` takes a `Request` object as a parameter. -It contains data that is used to select an appropriate instance, including the downstream client request and <>. `onStartRequest` also takes the `Request` object and, additionally, the `Response` object as parameters. -On the other hand, a `CompletionContext` object is provided to the `onComplete(CompletionContext completionContext)` method. -It contains the LoadBalancer `Response`, including the selected service instance, the `Status` of the request executed against that service instance and (if available) the response returned to the downstream client, and (if an exception has occurred) the corresponding `Throwable`. +`onStart(Request request)` takes a `Request` object as a parameter. It contains data that is used to select an appropriate instance, including the downstream client request and <>. `onStartRequest` also takes the `Request` object and, additionally, the `Response` object as parameters. On the other hand, a `CompletionContext` object is provided to the `onComplete(CompletionContext completionContext)` method. It contains the LoadBalancer `Response`, including the selected service instance, the `Status` of the request executed against that service instance and (if available) the response returned to the downstream client, and (if an exception has occurred) the corresponding `Throwable`. The `supports(Class requestContextClass, Class responseClass, -Class serverTypeClass)` method can be used to determine whether the processor in question handles objects of provided types. -If not overridden by the user, it returns `true`. +Class serverTypeClass)` method can be used to determine whether the processor in question handles objects of provided types. If not overridden by the user, it returns `true`. NOTE: In the preceding method calls, `RC` means `RequestContext` type, `RES` means client response type, and `T` means returned server type. -WARNING: If you are using custom HTTP status codes, you will be getting exceptions. -In order to prevent this, you can set the value of `spring.cloud.loadbalancer.use-raw-status-code-in-response-data`. -It will cause raw status codes to be used instead of `HttpStatus` enums. -The `httpStatus` field in `ResponseData` will then be used, but you'll be able to get the raw status code from the `rawHttpStatus` field. - [[loadbalancer-micrometer-stats-lifecycle]] === Spring Cloud LoadBalancer Statistics We provide a `LoadBalancerLifecycle` bean called `MicrometerStatsLoadBalancerLifecycle`, which uses Micrometer to provide statistics for load-balanced calls. -In order to get this bean added to your application context, set the value of the `spring.cloud.loadbalancer.stats.micrometer.enabled` to `true` and have a `MeterRegistry` available (for example, by adding https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html[Spring Boot Actuator] to your project). +In order to get this bean added to your application context, +set the value of the `spring.cloud.loadbalancer.stats.micrometer.enabled` to `true` and have a `MeterRegistry` available (for example, by adding https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html[Spring Boot Actuator] to your project). `MicrometerStatsLoadBalancerLifecycle` registers the following meters in `MeterRegistry`: diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerProperties.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerProperties.java index 9ae6b58b..f0f01bff 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerProperties.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/LoadBalancerProperties.java @@ -71,11 +71,6 @@ public class LoadBalancerProperties { */ private StickySession stickySession = new StickySession(); - /** - * Indicates that raw status codes should be used in {@link ResponseData}. - */ - private boolean useRawStatusCodeInResponseData; - public HealthCheck getHealthCheck() { return healthCheck; } @@ -129,14 +124,6 @@ public class LoadBalancerProperties { return xForwarded; } - public boolean isUseRawStatusCodeInResponseData() { - return useRawStatusCodeInResponseData; - } - - public void setUseRawStatusCodeInResponseData(boolean useRawStatusCodeInResponseData) { - this.useRawStatusCodeInResponseData = useRawStatusCodeInResponseData; - } - public static class StickySession { /** diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerExchangeFilterFunction.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerExchangeFilterFunction.java index 1b3057f4..3f586130 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerExchangeFilterFunction.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactorLoadBalancerExchangeFilterFunction.java @@ -128,8 +128,8 @@ public class ReactorLoadBalancerExchangeFilterFunction implements LoadBalancedEx LOG.debug(String.format("LoadBalancer has retrieved the instance for service %s: %s", serviceId, instance.getUri())); } - LoadBalancerProperties properties = loadBalancerFactory.getProperties(serviceId); - LoadBalancerProperties.StickySession stickySessionProperties = properties.getStickySession(); + LoadBalancerProperties.StickySession stickySessionProperties = loadBalancerFactory.getProperties(serviceId) + .getStickySession(); ClientRequest newRequest = buildClientRequest(clientRequest, instance, stickySessionProperties.getInstanceIdCookieName(), stickySessionProperties.isAddServiceInstanceCookie(), transformers); @@ -140,19 +140,10 @@ public class ReactorLoadBalancerExchangeFilterFunction implements LoadBalancedEx CompletionContext.Status.FAILED, throwable, lbRequest, lbResponse)))) .doOnSuccess(clientResponse -> supportedLifecycleProcessors.forEach( lifecycle -> lifecycle.onComplete(new CompletionContext<>(CompletionContext.Status.SUCCESS, - lbRequest, lbResponse, buildResponseData(requestData, clientResponse, - properties.isUseRawStatusCodeInResponseData()))))); + lbRequest, lbResponse, new ResponseData(clientResponse, requestData))))); }); } - private ResponseData buildResponseData(RequestData requestData, ClientResponse clientResponse, - boolean useRawStatusCodes) { - if (useRawStatusCodes) { - return new ResponseData(requestData, clientResponse); - } - return new ResponseData(clientResponse, requestData); - } - protected Mono> choose(String serviceId, Request request) { ReactiveLoadBalancer loadBalancer = loadBalancerFactory.getInstance(serviceId); if (loadBalancer == null) { diff --git a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClient.java b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClient.java index 8e8a6aac..47c1bacc 100644 --- a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClient.java +++ b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClient.java @@ -96,8 +96,7 @@ public class BlockingLoadBalancerClient implements LoadBalancerClient { .forEach(lifecycle -> lifecycle.onStartRequest(lbRequest, new DefaultResponse(serviceInstance))); try { T response = request.apply(serviceInstance); - LoadBalancerProperties properties = loadBalancerClientFactory.getProperties(serviceId); - Object clientResponse = getClientResponse(response, properties.isUseRawStatusCodeInResponseData()); + Object clientResponse = getClientResponse(response); supportedLifecycleProcessors .forEach(lifecycle -> lifecycle.onComplete(new CompletionContext<>(CompletionContext.Status.SUCCESS, lbRequest, defaultResponse, clientResponse))); @@ -116,16 +115,13 @@ public class BlockingLoadBalancerClient implements LoadBalancerClient { return null; } - private Object getClientResponse(T response, boolean useRawStatusCodes) { + private Object getClientResponse(T response) { ClientHttpResponse clientHttpResponse = null; if (response instanceof ClientHttpResponse) { clientHttpResponse = (ClientHttpResponse) response; } if (clientHttpResponse != null) { try { - if (useRawStatusCodes) { - return new ResponseData(null, clientHttpResponse); - } return new ResponseData(clientHttpResponse, null); } catch (IOException ignored) {