From cfe1f403474f5d85bacd78561ed04faad9fdd33a Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Wed, 18 Jan 2023 11:53:04 +0100 Subject: [PATCH] Recheck for null service instance to avoid micrometer NPE. --- docs/src/main/asciidoc/_configprops.adoc | 1 + .../blocking/client/BlockingLoadBalancerClient.java | 3 +++ .../META-INF/additional-spring-configuration-metadata.json | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 509f3fd7..ea2dd79a 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -53,6 +53,7 @@ |spring.cloud.loadbalancer.retry.retry-on-all-operations | `+++false+++` | Indicates retries should be attempted on operations other than `HttpMethod.GET`}. |spring.cloud.loadbalancer.retry.retryable-status-codes | `+++{}+++` | A `Set` of status codes that should trigger a retry. |spring.cloud.loadbalancer.service-discovery.timeout | | String representation of Duration of the timeout for calls to service discovery. +|spring.cloud.loadbalancer.stats.micrometer.enabled | `+++false+++` | Enables Spring Cloud LoadBalancer Micrometer stats. |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}. 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 8cc4bdcc..f9463dbc 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 @@ -105,6 +105,9 @@ public class BlockingLoadBalancerClient implements LoadBalancerClient { @Override public T execute(String serviceId, ServiceInstance serviceInstance, LoadBalancerRequest request) throws IOException { + if (serviceInstance == null) { + throw new IllegalArgumentException("Service Instance cannot be null"); + } DefaultResponse defaultResponse = new DefaultResponse(serviceInstance); Set supportedLifecycleProcessors = getSupportedLifecycleProcessors(serviceId); Request lbRequest = request instanceof Request ? (Request) request : new DefaultRequest<>(); diff --git a/spring-cloud-loadbalancer/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-loadbalancer/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 0981898e..66141df7 100644 --- a/spring-cloud-loadbalancer/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-cloud-loadbalancer/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -33,6 +33,12 @@ "name": "spring.cloud.loadbalancer.enabled", "description": "Enables Spring Cloud LoadBalancer.", "type": "java.lang.Boolean" + }, + { + "defaultValue": "false", + "name": "spring.cloud.loadbalancer.stats.micrometer.enabled", + "description": "Enables Spring Cloud LoadBalancer Micrometer stats.", + "type": "java.lang.Boolean" } ] }