-
Notifications
You must be signed in to change notification settings - Fork 210
Time-based Rolling window #90
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
Conversation
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
Contributor
Author
|
@YoshiyukiMineo did you have the chance to review this PR? |
Member
|
Thank you. I will merge this PR to the master branch after review, trial, and some modification if needed. |
YoshiyukiMineo
added a commit
that referenced
this pull request
Aug 16, 2025
* Time-based Rolling window (#90) * feat: add rolling window * fix: new bucket expiry time * test: add tests for rolling window circuit breaker * chore: remove comments --------- Co-authored-by: Yoshiyuki Mineo <Yoshiyuki.Mineo@jp.sony.com> * Update distributed_gobreaker.go * Refactor circuit breaker implementation to replace WindowCounts with a new structure, improving clarity and consistency in handling counts. Update related tests to reflect this change. * Remove mutex locks from windowCounts methods to simplify the implementation and improve performance. This change enhances the clarity of the code while maintaining functionality. * Refactor DistributedCircuitBreaker to replace BucketCounts with Buckets in SharedState and related structures. Update methods and tests accordingly to ensure consistency and correctness in handling counts. * Update README and gobreaker.go for consistency in language. Changed "doesn't" to "does not" for clarity in CircuitBreaker documentation. * Fix nil pointer dereference in windowCounts.rotate method by adding a check for oldBucket. This ensures safe access to oldBucket's values before performing calculations on counts. * Refactor windowCounts initialization and bucket management in gobreaker. Update tests to reflect changes in bucket handling and ensure correct state assertions. * Refactor toCountsArray function in distributed_gobreaker.go to use a slice instead of a list for improved performance. Update related tests in gobreaker_test.go to reflect changes in bucket handling and ensure accurate assertions. * Implement clear method for Counts struct and update state reset logic in distributed_gobreaker_test.go. This enhances clarity and ensures proper state management during circuit breaker operations. * Implement bucketAt method in windowCounts for circular buffer indexing and update related tests in gobreaker_test.go to ensure accurate assertions on bucket retrieval. This enhances the clarity and functionality of the rolling window circuit breaker. * Refactor windowCounts to use age for bucket management instead of current index. Update related methods and tests in gobreaker_test.go to ensure accurate bucket access and state management in the rolling window circuit breaker. * Enhance SharedState in DistributedCircuitBreaker by adding Age field and updating bucket management. Refactor inject and extract methods to utilize new age property and improve bucket copying logic. This change ensures better state management and clarity in the circuit breaker implementation. * Refactor Counts struct methods in gobreaker to improve state management during requests, successes, and failures. Update windowCounts to utilize these methods for better clarity and performance in bucket handling. Adjust initialization logic for bucket management in CircuitBreaker to ensure accurate configuration based on interval and bucket period. * Refactor gobreaker to replace windowCounts with rollingCounts for improved bucket management. Update related methods and tests to ensure accurate state handling and assertions in the CircuitBreaker implementation. This change enhances clarity and performance in managing circuit breaker states. * Refactor bucketAt method in rollingCounts to improve index handling and prevent out-of-bounds errors. This change enhances the robustness of bucket access by ensuring proper index calculations and returning an empty Counts struct when necessary. * Rename rotate method to roll in rollingCounts for improved clarity and update related references in gobreaker. This change enhances code readability and maintains consistent terminology across the implementation. * Refactor CircuitBreaker methods to incorporate age parameter for improved state management during requests, successes, and failures. Update related methods to ensure accurate handling of bucket access and enhance clarity in the CircuitBreaker implementation. * Update CircuitBreaker and rollingCounts to improve state management and bucket handling. Adjust tests to reflect changes in interval handling and expiry checks, ensuring accurate assertions in the CircuitBreaker implementation. * Refactor age calculation in CircuitBreaker to handle negative elapsed time and improve clarity in bucket growth logic. This change enhances state management and ensures accurate handling of time intervals in the rollingCounts implementation. * Refactor age calculation in CircuitBreaker by extracting it into a separate method for improved clarity and reusability. This change simplifies the bucket growth logic and enhances state management during circuit operations. * Refactor age calculation in CircuitBreaker to use an intermediate variable for improved clarity and maintainability. This change ensures accurate handling of elapsed time and enhances the overall readability of the age method. * Enhance rollingCounts logic in gobreaker to ensure accurate state management by preventing negative values for consecutive successes, failures, requests, and total counts. This refactor improves clarity and robustness in the roll method, ensuring proper handling of bucket data during state transitions. * Add BucketPeriod to Settings and update documentation for rolling window strategy This commit introduces a new `BucketPeriod` field in the `Settings` struct, defining the duration for each bucket in the rolling window strategy. The documentation has been updated to clarify how `BucketPeriod` interacts with `Interval`, ensuring accurate handling of internal counts and bucket updates in the CircuitBreaker implementation. --------- Co-authored-by: Daniel Moura <dmouraneto@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add support for time-based rolling window.
Add BucketPeriod to the struct Settings, as specified in https://github.com/sony/gobreaker/wiki/Draft-Specification-for-Time%E2%80%90Based-Rolling-Window
It uses a double linked list, from the standard package
container/list, to store theBucketCounts.The
countsis encapsulated in#64