Releases: bolshakov/stoplight
v3.0.2
What's Changed
- Add human-friendly error message when Stoplight is used a wrong way by @bolshakov in #211
Full Changelog: v3.0.1...v3.0.2
v4.1.0
What's Changed
- Expose CircuitBreaker#name and CircuitBreaker#state methods by @bolshakov in #198
- Bump version by @bolshakov in #199
Full Changelog: v4.0.0...v4.1.0
v4.0.0
Stoplight 4.0 🎉
The next major release has been published, bringing a number of improvements and new features! However, it also introduces breaking changes. As a result, we removed certain notifiers. However, upgrading from Stoplight 3.x to Stoplight 4.0 need not be difficult. In fact, we have listed all the necessary steps in the UPGRADING.md documentation.
New Features
Stoplight() interface has changed
We aim to make Stoplight's configuration sharable across the code. The following change, enables Stoplight to run different code blocks with the same configuration:
light = Stoplight('http-api').with_cool_off_time(300)
light.run { call_this }
light.run { call_that }
The Stoplight()
returns an immutable Stoplight::CircuitBreaker
object that can be safely reconfigured. It makes it compatible with various Dependency Injections systems:
notifier = Stoplight::Sentry::Notifier.new(Sentry)
API_STOPLIGHT = Stoplight('http-api')
.with_notifiers([notifier])
.with_threshold(10)
class GetChangeOrdersApi
def initialize(circuit_breaker: API_STOPLIGHT)
@circuit_breaker = circuit_breaker.with_fallback { [] }
end
def call(order_id:)
@circuit_breaker.run do
# calls HTTP API
end
end
end
class GetOrderApi
def initialize(circuit_breaker: API_STOPLIGHT)
@circuit_breaker = circuit_breaker.with_fallback { NullOrder.new }
end
def call(order_id:)
@circuit_breaker.run do
# calls HTTP API
end
end
end
Another benefit is that now you can easily inspect the status of the circuit breaker without passing an empty block:
light.color
Introducing Sliding Window Error Counting
By default, every recorded failure contributes to reaching the threshold, regardless of when it occurs, causing the Stoplight to turn red. In this release, to provide more flexibility, we've introduced a sliding window configuration using the #with_window_size
method (#172) that allows you to control how errors are counted within a specified time frame. Here's how it works:
Let's say you set the window size to 2 seconds:
window_size_in_seconds = 2
light = Stoplight('example-threshold')
.with_window_size(window_size_in_seconds)
.with_threshold(1)
# => #<Stoplight::CircuitBreaker:...>
light.run { 1 / 0 }#=> #<ZeroDivisionError: divided by 0>
sleep(3)
light.run { 1 / 0 }
Without the window size configuration, the second light.run { 1 / 0 }
call will result in a Stoplight::Error::RedLight
exception being raised, as the Stoplight transitions to the red state after the first call. With a sliding window of 2 seconds, only the errors that occur within the latest 2 seconds are considered. The first error causes the Stoplight to turn red, but after 3 seconds (when the second error occurs), the window has shifted, and the Stoplight switches to green state causing the error to raise again. This provides a way to focus on the most recent errors.
It's worth noting that the default window size is set to infinity, meaning that all failures are counted regardless of timing.
Stoplight Gains an Interface for Locking Lights
In earlier versions, when you wanted to lock lights, you had to access Stoplight's internals. Stoplight 4.0 brings a new user-friendly interface to both lock and unlock lights:
light.lock('red')
light.unlock
light.lock('green')
What's Changed
- Use actions/setup-ruby@v1 by ruby/setup-ruby@v1 by @bolshakov in #164
- Move data store specs into shared examples by @bolshakov in #166
- Update rubocop by @bolshakov in #167
- Use Redis in specs by @bolshakov in #173
- Add .idea to gitignore by @bolshakov in #175
- Shared specs for Stoplight::Light::Runnable by @bolshakov in #176
- Do not use the same error instance for tests by @bolshakov in #177
- Drop branded notifiers by @bolshakov in #174
- Test against different redis versions by @bolshakov in #179
- Implement window size by @bolshakov in #172
- feat | Light lock interface improvement by @Lokideos in #170
- Update gemfile lock by @bolshakov in #181
- Add stoplight-sentry by @bolshakov in #182
- Chore | Fix documentation for lockable methods by @Lokideos in #183
- Interface rework by @bolshakov in #180
- Update issue templates by @bolshakov in #189
- Create SECURITY.md by @bolshakov in #190
- Update rubocop.yml by @bolshakov in #191
- Update supported ruby version in ruby by @bolshakov in #193
- Update docs by @bolshakov in #194
- Specs for the circuit breaker module by @bolshakov in #195
Full Changelog: v3.0.1...v4.0.0
v3.0.1
What's Changed
#159 Fix race condition when sending notifications @Lokideos
#154 Drop HipChat support @BobbyMcWho @artygus
New Contributors
- @BobbyMcWho made their first contribution in #154
- @artygus made their first contribution in #157
- @Lokideos made their first contribution in #159
Full Changelog: v3.0.0...v3.0.1
v3.0.0
What's Changed
#146 Drop ruby 2.5.x support by @bolshakov
#146 Add ruby 3.0.x support by @bolshakov
#150 Fix deprecated uses of Redis#pipelined
by @casperisfine
Full Changelog: v2.2.1...v3.0.0