-
Notifications
You must be signed in to change notification settings - Fork 21
fix: Improve Circuit breaker behaviour #1017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
...n-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java
Outdated
Show resolved
Hide resolved
| .when(destinationServiceAdapter) | ||
| .getConfigurationAsJson(eq("/v1/subaccountDestinations"), any()); | ||
|
|
||
| DestinationService.Cache.setGetAllDocumentsPrepended(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Major)
Please consider different API options, to reflect on existing available methods.
- DestinationService.Cache.setGetAllDocumentsPrepended(true);
+ DestinationService.Cache.enableGetAllDocumentsPrepended();
+ DestinationService.Cache.enableGetAllDestinationsPrepended();
+ DestinationService.Cache.enablePreLookupCheck();
+ DestinationService.Cache.enableExistenceCheck();Also your feature would be enabled by default - right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed it to DestinationService.Cache.enablePreLookupCheck().
Right now I have so that the behaviour is disabled by default. I did that to not introduce breaking changes (and also we talked about that this might increase response times for the first call). Do you think it should be enabled by default?
| if( prependGetAllDestinationCall && !destinationExists() ) { | ||
| final String msg = "Destination %s was not found among the destinations of the current tenant."; | ||
| return Try.failure(new DestinationAccessException(String.format(msg, destinationName))); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Question/Minor)
Not a huge fan of Boolean (sic) prependGetAllDestinationCall additional 7th argument.
Have you considered wrapping this check into destinationRetriever argument before calling the method? If it's not too complex/too much additional code (likely).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boolean was a typo, should of course have been boolean 😬
I struggled a bit with placing this into destinationRetriever but found another solution by putting it directly into DestinationService.tryGetDestination. Is there anything that speaks against this?
rpanackal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Question)
So the idea was instead of directly augmenting resilience config cache key, we introduce a (opt-in) check for the existence of a destination, essentially avoid tripping the circuit breaker in the first place.
But, I wonder what if a destination call fails for a different reason than DestinationAccessException? Is that possible? If so, I don't see how the current approach would resolve the issue?
Yes, this is indeed possible and this approach does not solve the issue. We discussed this and came to the conclusion that the problem we solve with the current approach is the main problem we want to solve. Solving the issue you describe here might lead to unexpected behaviour of the SDK so we decided against trying to solve that. Our hope was that by adding this additional check we solve the main amount of problems. |
...n-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java
Outdated
Show resolved
Hide resolved
...n-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java
Show resolved
Hide resolved
...n-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java
Outdated
Show resolved
Hide resolved
I was made aware we want this to be "opt-out" instead of "opt-in" (?)
I adapted the code accordingly.
I wrote some docs now. |
...n-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java
Outdated
Show resolved
Hide resolved
...n-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java
Outdated
Show resolved
Hide resolved
...n-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/DestinationService.java
Outdated
Show resolved
Hide resolved
rpanackal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Context
SAP/cloud-sdk-java-backlog#495
This PR improves the circuit breaker logic by prepending an additional check to
tryGetDestination. When a single destination is called, it is first checked whether this destination appears in the result of a get all destination call. If the destination is not present, no call to the destination is made. Thus the circuit breaker does not open when non-existing destination(s) are called multiple times.This new behaviour is implemented as opt-in to not introduce breaking changes.
Feature scope:
Definition of Done