From 3b18676f59aa0bdb7308f2754acb412711540eba Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 27 May 2014 16:58:20 -0700 Subject: [PATCH] Add a new class of chaos monkey errors after the inner code has run. Lower the overall error rate to reduce traffic. --- config.py | 2 +- lib/utils.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 92e43f6..a4ed3a7 100644 --- a/config.py +++ b/config.py @@ -6,4 +6,4 @@ NAMESPACE = 'cosmopolite' CHANNEL_DURATION_SECONDS = 60 * 60 * 2 # 2 hours # Probabilities -CHAOS_PROBABILITY = 0.50 +CHAOS_PROBABILITY = 0.05 diff --git a/lib/utils.py b/lib/utils.py index 58b00f6..64ed36d 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -52,7 +52,15 @@ def chaos_monkey(handler): self.response.headers['Retry-After'] = '0' self.error(503) return - return handler(self) + + ret = handler(self) + + if random.random() < config.CHAOS_PROBABILITY: + self.response.headers['Retry-After'] = '0' + self.error(503) + return + + return ret return IntroduceFailures