Repository navigation
v3 circuit breaker #683
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
Merged
Merged
v3 circuit breaker #683
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # HTTP Storage Circuit Breaker | ||
|
|
||
| This document describes how circuit breaker works for [`com.here.naksha.storage.http.HttpStorage`](../here-naksha-storage-http/src/jvmMain/java/com/here/naksha/storage/http/HttpStorage.java). | ||
|
|
||
| ## Where it is applied | ||
|
|
||
| The CircuitBreaker is applied whenever Naksha wants to forward a request to HttpStorage. | ||
|
|
||
| **Key Points:** | ||
| - The CB config is read from the individual HTTP Storage definition. | ||
| - At runtime, the CB logic is executed against individual `storageId`. | ||
| - Different Storage definitions can imply different CB behavior based on their respective configurations. | ||
| - Whenever a Storage definition changes (via storage `updatedAt` value), the internal CB cache for that `storageId` is invalidated and a new CB is created with the updated configuration. | ||
| - This ensures that configuration changes are immediately reflected in the CB behavior without requiring an application restart. | ||
|
|
||
| ## Why it exists | ||
|
|
||
| The goal is to isolate slow or failing requests by `storageId`. | ||
| If one storage starts timing out or responding slowly, only that storage's traffic should be throttled. | ||
| Requests for other storages should not be affected. | ||
|
|
||
|
|
||
| ## HTTP Storage Configuration | ||
|
|
||
| For detailed configuration properties and their validation rules, refer to: | ||
| - [HttpStorageProperties](../here-naksha-storage-http/src/jvmMain/java/com/here/naksha/storage/http/HttpStorageProperties.java) - HTTP storage-specific settings (URL, timeouts, headers, etc.) | ||
| - [CircuitBreakerProps](../here-naksha-lib-circuit-breaker/src/jvmMain/java/com/here/naksha/lib/circuitbreaker/models/CircuitBreakerProps.java) - Circuit breaker configuration | ||
|
|
||
| ### Example Storage JSON | ||
|
|
||
| ```json | ||
| { | ||
| "id": "my_storage", | ||
| "type": "Storage", | ||
| "className": "com.here.naksha.storage.http.HttpStorage", | ||
| "properties": { | ||
| "url": "https://example.com/api", | ||
| "connectTimeout": 10, | ||
| "socketTimeout": 30, | ||
| "httpInterface": "ffwAdapter", | ||
| "maxRetries": 3, | ||
| "headers": { | ||
| "Authorization": "Bearer token123" | ||
| }, | ||
| "circuitBreaker": { | ||
| "slidingWindowSize": 20, | ||
| "minimumNumberOfCalls": 10, | ||
| "slowCallDurationThresholdMs": 29000, | ||
| "slowCallRateThreshold": 50, | ||
| "waitDurationInOpenStateMs": 120000, | ||
| "permittedNumberOfCallsInHalfOpenState": 4 | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| **Note:** The `circuitBreakerConfig` configuration is optional. If omitted, HTTP requests are sent without circuit breaking. | ||
|
|
||
|
|
||
| ## CircuitBreaker Behavior | ||
|
|
||
| - **CLOSED**: This is default state during start of application where requests flow normally. | ||
| - **OPEN**: Requests are rejected immediately when circuit is in OPEN state. Circuit moves to or remains in OPEN state whenever the slow call rate exceeds `slowCallRateThreshold` (after minimum `minimumNumberOfCalls` have been observed). | ||
| - **HALF_OPEN**: Circuit transitions from OPEN to HALF_OPEN after waiting `waitDurationInOpenStateMs`. Limited number of probe calls (`permittedNumberOfCallsInHalfOpenState`) are allowed. It moves back to OPEN state if slow call rate exceeds `slowCallRateThreshold`. It moves to CLOSED state if slow call rate drops below `slowCallRateThreshold`. | ||
| - If probe calls are fast enough, the breaker closes. | ||
| - If probe calls are still slow, the breaker opens again. | ||
|
|
||
| ## Notes | ||
|
|
||
| - The breaker is configured per `storageId`. | ||
| - Storage updates are detected through `updatedAt`. | ||
| - The storage JSON validation happens when storages are created or updated through the storage API. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let us stick with "circuitBreakerConfig" everywhere. There is an issue with v2 implementation and already raised a MR for this.