baseplate.py
baseplate.py copied to clipboard
Circuit breakers
This is largely copied from reddit/reddit-service-graphql/tree/master/graphql_api/lib/circuit_breaker. That code is great and running in production in a few service.
I added docstrings and types where missing and then added the CircuitBreakerClientWrapperFactory
interface to hopefully make it a bit easier to integrate with baseplate service.
I'm going to copy/paste this code into thing service and r2 to ensure it works as expected and isn't missing anything. Then we can consider merging this PR into baseplate.
👓 @suzie-su @pnovotnak @spladug @manishapme @jennLam
Note from Manisha:
only request is some docs that show how you set it up in the tests in the docstring somewhere. like add this to your init.py file
breaker_box = breaker_box_from_config(
app_config={
"brkr.samples": "4",
"brkr.trip_failure_ratio": "0.75",
"brkr.trip_for": "1 minute",
"brkr.fuzz_ratio": "0.1",
}
wrapped_client_factory = CircuitBreakerClientWrapperFactory(
client_factory, self.breaker_box
)
baseplate.add_to_context("wrapped_client", wrapped_client_factory)
🏃♂️