Selectively cause requests to your rack app to fail - the idea being that by having an artifically flakey API, you are forced to build resilience in to your clients (à la Chaos Monkey from Netflix).
Install the Rack::Wreck gem; or add it to your Gemfile with bundler:
# In your Gemfile
gem 'rack-wreck'
Tell your app to use the Rack::Wreck middleware. For Rails apps:
# In config/application.rb
config.middleware.use Rack::Wreck
Or for Rackup files:
# In config.ru
require "rack/wreck"
use Rack::Wreck
See examples for example apps/configrations.
Bug reports and pull requests are welcome on GitHub at https://github.com/jkburges/rack-wreck. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Thanks to the rack-attack gem for providing a great basis for writing rack middleware!
-
rules matched top to bottom
-
what to fail?
- block which takes rack env
-
when to fail?
- MVP -
Random.rand > x
- extend to https://github.com/clbustos/distribution
- MVP -
-
how to fail?
- the normal Rack response, e.g.
['500', {'Content-Type' => 'text/html'}, ["You've been wrecked!"]]
- the normal Rack response, e.g.
Rack::Wreck.rules do
override "/login", method: :post, chance: 0.1, status: 500
override /widget/, chance: 0.05, status: 403, body: ["Nice try!"]
end
It's also possible to delay responses as follows:
Rack::Wreck.configure do
delay "/expensive", duration: 5.seconds
# TODO: distributions from https://github.com/clbustos/distribution
end