From 665cf064f72ee7f1e2ce0cccb206f972f9be29e3 Mon Sep 17 00:00:00 2001 From: Roy Clarkson Date: Wed, 13 Sep 2023 10:56:50 -0400 Subject: [PATCH] Include serviceInstanceId in controller error logging --- .../ServiceInstanceBindingController.java | 58 ++++++++++--------- .../controller/ServiceInstanceController.java | 52 +++++++++-------- 2 files changed, 60 insertions(+), 50 deletions(-) diff --git a/spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/controller/ServiceInstanceBindingController.java b/spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/controller/ServiceInstanceBindingController.java index 0dc023ba..f245a341 100644 --- a/spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/controller/ServiceInstanceBindingController.java +++ b/spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/controller/ServiceInstanceBindingController.java @@ -74,10 +74,14 @@ public class ServiceInstanceBindingController extends BaseController { private static final String INFO_RESPONSE = "{} service instance binding succeeded: serviceInstanceId={}, " + "bindingId={}"; + private static final String DEBUG_REQUEST = "request={}"; private static final String DEBUG_RESPONSE = "response={}"; + private static final String ERROR_RESPONSE = "Error {} service instance binding: serviceInstanceId={}; " + + "serviceBindingId={}; error={}"; + private final ServiceInstanceBindingService service; /** @@ -149,8 +153,8 @@ public Mono> createServiceI LOG.debug(DEBUG_RESPONSE, response); } }) - .doOnError(e -> LOG.error("Error creating service instance binding. error=" + - e.getMessage(), e))) + .doOnError(e -> LOG.error(String.format(ERROR_RESPONSE, "creating", serviceInstanceId, + bindingId, e.getMessage()), e))) .map(response -> new ResponseEntity<>(response, getCreateResponseCode(response))) .switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.CREATED))); } @@ -192,15 +196,15 @@ public Mono> getServiceInstanc @RequestHeader(value = ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString, @RequestHeader(value = ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, required = false) String requestIdentity) { return Mono.just(GetServiceInstanceBindingRequest.builder() - .serviceInstanceId(serviceInstanceId) - .bindingId(bindingId) - .serviceDefinitionId(serviceDefinitionId) - .planId(planId) - .platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE)) - .apiInfoLocation(apiInfoLocation) - .originatingIdentity(parseOriginatingIdentity(originatingIdentityString)) - .requestIdentity(requestIdentity) - .build()) + .serviceInstanceId(serviceInstanceId) + .bindingId(bindingId) + .serviceDefinitionId(serviceDefinitionId) + .planId(planId) + .platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE)) + .apiInfoLocation(apiInfoLocation) + .originatingIdentity(parseOriginatingIdentity(originatingIdentityString)) + .requestIdentity(requestIdentity) + .build()) .flatMap(req -> service.getServiceInstanceBinding(req) .doOnRequest(v -> { if (LOG.isInfoEnabled()) { @@ -218,8 +222,8 @@ public Mono> getServiceInstanc LOG.debug(DEBUG_RESPONSE, response); } }) - .doOnError(e -> LOG.error("Error getting service instance binding. error=" + - e.getMessage(), e))) + .doOnError(e -> LOG.error(String.format(ERROR_RESPONSE, "getting", serviceInstanceId, + bindingId, e.getMessage()), e))) .map(response -> new ResponseEntity<>(response, HttpStatus.OK)) .switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK))) .onErrorResume(e -> { @@ -259,16 +263,16 @@ public Mono> getServiceIn @RequestHeader(value = ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString, @RequestHeader(value = ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, required = false) String requestIdentity) { return Mono.just(GetLastServiceBindingOperationRequest.builder() - .serviceDefinitionId(serviceDefinitionId) - .serviceInstanceId(serviceInstanceId) - .bindingId(bindingId) - .planId(planId) - .operation(operation) - .platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE)) - .apiInfoLocation(apiInfoLocation) - .originatingIdentity(parseOriginatingIdentity(originatingIdentityString)) - .requestIdentity(requestIdentity) - .build()) + .serviceDefinitionId(serviceDefinitionId) + .serviceInstanceId(serviceInstanceId) + .bindingId(bindingId) + .planId(planId) + .operation(operation) + .platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE)) + .apiInfoLocation(apiInfoLocation) + .originatingIdentity(parseOriginatingIdentity(originatingIdentityString)) + .requestIdentity(requestIdentity) + .build()) .flatMap(request -> service.getLastOperation(request) .doOnRequest(v -> { if (LOG.isInfoEnabled()) { @@ -287,8 +291,8 @@ public Mono> getServiceIn LOG.debug(DEBUG_RESPONSE, response); } }) - .doOnError(e -> LOG.error("Error getting service instance binding last operation. error=" + - e.getMessage(), e))) + .doOnError(e -> LOG.error(String.format(ERROR_RESPONSE, "getting last operation for", + serviceInstanceId, bindingId, e.getMessage()), e))) .flatMap(response -> Mono .just(response.getState().equals(OperationState.SUCCEEDED) && response.isDeleteOperation()) .flatMap(isSuccessfulDelete -> @@ -356,8 +360,8 @@ public Mono> deleteServiceI LOG.debug(DEBUG_RESPONSE, response); } }) - .doOnError(e -> LOG.error("Error deleting a service instance binding. error=" + - e.getMessage(), e))) + .doOnError(e -> LOG.error(String.format(ERROR_RESPONSE, "deleting", serviceInstanceId, + bindingId, e.getMessage()), e))) .map(response -> new ResponseEntity<>(response, getAsyncResponseCode(response))) .switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK))) .onErrorResume(e -> { diff --git a/spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/controller/ServiceInstanceController.java b/spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/controller/ServiceInstanceController.java index 979bcd34..eb8afdb7 100644 --- a/spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/controller/ServiceInstanceController.java +++ b/spring-cloud-open-service-broker-core/src/main/java/org/springframework/cloud/servicebroker/controller/ServiceInstanceController.java @@ -79,6 +79,8 @@ public class ServiceInstanceController extends BaseController { private static final String DEBUG_RESPONSE = "response={}"; + private static final String ERROR_RESPONSE = "Error {} service instance: serviceInstanceId={}; error={}"; + private final ServiceInstanceService service; /** @@ -145,7 +147,8 @@ public Mono> createServiceInstance LOG.debug(DEBUG_RESPONSE, response); } }) - .doOnError(e -> LOG.error("Error creating service instance. error=" + e.getMessage(), e))) + .doOnError(e -> LOG.error(String.format(ERROR_RESPONSE, "creating", serviceInstanceId, + e.getMessage()), e))) .map(response -> new ResponseEntity<>(response, getCreateResponseCode(response))) .switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.CREATED))); } @@ -185,14 +188,14 @@ public Mono> getServiceInstance( @RequestHeader(value = ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString, @RequestHeader(value = ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, required = false) String requestIdentity) { return Mono.just(GetServiceInstanceRequest.builder() - .serviceInstanceId(serviceInstanceId) - .serviceDefinitionId(serviceDefinitionId) - .planId(planId) - .platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE)) - .apiInfoLocation(apiInfoLocation) - .originatingIdentity(parseOriginatingIdentity(originatingIdentityString)) - .requestIdentity(requestIdentity) - .build()) + .serviceInstanceId(serviceInstanceId) + .serviceDefinitionId(serviceDefinitionId) + .planId(planId) + .platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE)) + .apiInfoLocation(apiInfoLocation) + .originatingIdentity(parseOriginatingIdentity(originatingIdentityString)) + .requestIdentity(requestIdentity) + .build()) .flatMap(request -> service.getServiceInstance(request) .doOnRequest(v -> { if (LOG.isInfoEnabled()) { @@ -210,7 +213,8 @@ public Mono> getServiceInstance( LOG.debug(DEBUG_RESPONSE, response); } }) - .doOnError(e -> LOG.error("Error getting service instance. error=" + e.getMessage(), e))) + .doOnError(e -> LOG.error(String.format(ERROR_RESPONSE, "getting", serviceInstanceId, + e.getMessage()), e))) .map(response -> new ResponseEntity<>(response, HttpStatus.OK)) .switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK))) .onErrorResume(e -> { @@ -247,15 +251,15 @@ public Mono> getServiceInstanceL @RequestHeader(value = ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString, @RequestHeader(value = ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, required = false) String requestIdentity) { return Mono.just(GetLastServiceOperationRequest.builder() - .serviceDefinitionId(serviceDefinitionId) - .serviceInstanceId(serviceInstanceId) - .planId(planId) - .operation(operation) - .platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE)) - .apiInfoLocation(apiInfoLocation) - .originatingIdentity(parseOriginatingIdentity(originatingIdentityString)) - .requestIdentity(requestIdentity) - .build()) + .serviceDefinitionId(serviceDefinitionId) + .serviceInstanceId(serviceInstanceId) + .planId(planId) + .operation(operation) + .platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE)) + .apiInfoLocation(apiInfoLocation) + .originatingIdentity(parseOriginatingIdentity(originatingIdentityString)) + .requestIdentity(requestIdentity) + .build()) .flatMap(request -> service.getLastOperation(request) .doOnRequest(v -> { if (LOG.isInfoEnabled()) { @@ -273,8 +277,8 @@ public Mono> getServiceInstanceL LOG.debug(DEBUG_RESPONSE, response); } }) - .doOnError(e -> LOG.error("Error getting service instance last operation. error=" + - e.getMessage(), e))) + .doOnError(e -> LOG.error(String.format(ERROR_RESPONSE, "getting last operation for", + serviceInstanceId, e.getMessage()), e))) .map(response -> { boolean isSuccessfulDelete = OperationState.SUCCEEDED.equals(response.getState()) && response .isDeleteOperation(); @@ -348,7 +352,8 @@ public Mono> deleteServiceInstance LOG.debug(DEBUG_RESPONSE, response); } }) - .doOnError(e -> LOG.error("Error deleting a service instance. error=" + e.getMessage(), e))) + .doOnError(e -> LOG.error(String.format(ERROR_RESPONSE, "deleting", serviceInstanceId, + e.getMessage()), e))) .map(response -> new ResponseEntity<>(response, getAsyncResponseCode(response))) .switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK))) .onErrorResume(e -> { @@ -415,7 +420,8 @@ public Mono> updateServiceInstance LOG.debug(DEBUG_RESPONSE, response); } }) - .doOnError(e -> LOG.error("Error updating service instance. error=" + e.getMessage(), e))) + .doOnError(e -> LOG.error(String.format(ERROR_RESPONSE, "updating", serviceInstanceId, + e.getMessage()), e))) .map(response -> new ResponseEntity<>(response, getAsyncResponseCode(response))) .switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK))); }