SMOODEV-950: Circuit breaker — rate-based detection + onStateChange in Rust/Python/Go#76
Merged
Merged
Conversation
…Rust/Python/Go Surface a subset of TS's mollitia-style breaker knobs across the other ports: Python ------ - New `failure_rate_threshold` + `sliding_window_size` on `CircuitBreakerOptions`. When set, the breaker tracks the most recent outcomes and trips when the failure ratio meets the threshold (after `failure_threshold` minimum samples have been observed). - New `on_state_change: (from_state, to_state) -> None` callback fires on every transition (Closed/Open/HalfOpen). User-callback errors are swallowed so they cannot corrupt the breaker's internal bookkeeping. - `CircuitStateChangeCallback` type alias exported. Rust ---- - `CircuitBreaker::with_failure_rate_threshold(threshold, window)` builder enables rate-based detection. - `CircuitBreaker::with_on_state_change(callback)` registers a state-change callback. Callback type: `Arc<dyn Fn(CircuitState, CircuitState) + Send + Sync>`. - `CircuitState` is now `Copy` (for ergonomic pass-by-value in the callback). - New `CircuitStateChangeCallback` type exported at crate root. Go -- - New `ClientBuilder.WithCircuitBreakerStateChange(fn)` helper exposes the underlying sony/gobreaker `OnStateChange` at the top-level builder API. (The callback was already reachable via `WithCircuitBreaker(name, opts)`, but not surfaced as a first-class builder method — SMOODEV-950 explicitly called this out.) Tests ----- - Python: 3 new cases covering on_state_change firing on all transitions, rate-based threshold tripping, and the minimum-sample suppression. - Rust: 3 new unit tests in `circuit_breaker.rs`. - Go: 1 new builder test covering `WithCircuitBreakerStateChange`.
🦋 Changeset detectedLatest commit: 0573cb4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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
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.
Summary
Surfaces a subset of TS's mollitia-style breaker knobs in the other ports:
failure_rate_threshold+sliding_window_size(rate-based tripping) andon_state_changecallback onCircuitBreakerOptions.CircuitBreaker::with_failure_rate_threshold(...)+with_on_state_change(...).CircuitStateis nowCopyfor ergonomic pass-by-value into callbacks. NewCircuitStateChangeCallbackexported.ClientBuilder.WithCircuitBreakerStateChange(fn)exposes the existing sony/gobreakerOnStateChangeas a first-class builder method.Test plan
uv run pytest(121 passed; 3 new)cargo test(110 passed; 3 new)go test ./...(95 passed; 1 new)