Migration from sony/gobreaker#
AutoBreaker is a drop-in replacement for sony/gobreaker with enhanced features.
Quick Migration#
Replace the import and constructor:
| |
API Compatibility#
Identical APIs#
Execute(func() (interface{}, error))State()returns same enum values (0=Closed, 1=Open, 2=HalfOpen)ErrOpenState,ErrTooManyRequestserror typesCounts()struct with same fieldsSettingsstruct with same field names/types
Enhanced Features#
- Adaptive thresholds (percentage-based, enabled by default)
- Runtime updates via
UpdateSettings() - Better observability with
Metrics()andDiagnostics() - Callback safety with panic recovery
Settings Mapping#
| sony/gobreaker | AutoBreaker | Notes |
|---|---|---|
Name | Name | Same |
MaxRequests | MaxRequests | Same |
Interval | Interval | Same |
Timeout | Timeout | Same |
ReadyToTrip | ReadyToTrip | Enhanced with adaptive logic |
OnStateChange | OnStateChange | Same, plus panic recovery |
| - | AdaptiveThreshold | New: Enable percentage-based thresholds |
| - | FailureRateThreshold | New: Trip at >X% error rate |
| - | MinimumObservations | New: Minimum requests before evaluating |
| - | IsSuccessful | New: Custom error classification |
Behavior Differences#
1. Adaptive Thresholds (Default)#
sony/gobreaker uses absolute counts: ConsecutiveFailures > 5
AutoBreaker uses percentage-based: (TotalFailures / Requests) > 0.05
To match sony/gobreaker behavior:
| |
2. Callback Safety#
AutoBreaker wraps callbacks in panic recovery. If your callback panics, AutoBreaker continues working.
3. Runtime Updates#
AutoBreaker supports updating settings without recreating the breaker.
Migration Checklist#
- Update imports
- Update constructor (
NewCircuitBreaker→New) - Review settings (enable/disable adaptive thresholds as needed)
- Test thoroughly (behavior may differ with adaptive thresholds)
- Consider enhancements (runtime updates, better observability)
Example Migration#
| |
Benefits of Migration#
- Adaptive thresholds - Works correctly at any traffic level
- Runtime updates - Change settings without restart
- Better observability - More metrics and diagnostics
- Callback safety - Panics won’t break the circuit
- Active maintenance - Regular updates and improvements
Need Help?#
- GitHub Issues: https://github.com/1mb-dev/autobreaker/issues
- Examples: See examples/