diff --git a/app.rb b/app.rb index 6b8f205..de43f76 100644 --- a/app.rb +++ b/app.rb @@ -23,6 +23,7 @@ require "config" CHUNK_SIZE = 1024**2 SESSION_SECRET_HEX_LENGTH = 64 JWT_SECRET_HEX_LENGTH = 64 +DEFAULT_FLAKEY = 50 ENV_PREFIX = "KUBERNAUT" @@ -207,6 +208,13 @@ Health.instance.up Ready.instance.up Sleep.instance.wake +def flaky(pct = DEFAULT_FLAKEY) + r = Random.rand(0..100) + unless r < (100 - pct) + halt 500, "so unreliable" + end +end + enable :sessions configure do @@ -218,6 +226,17 @@ before do sleep(1) while Sleep.instance.asleep? && request.path_info != "/livez/sleep" content_type :text if request.path_info.start_with? "/_cat" request.session_options[:skip] = !request.path_info.start_with?("/session") + + if params.has_key? :flaky + begin + pct = Integer(params[:flaky]) + pct = pct.clamp(0, 100) + rescue => e + logger.warn "#{e.message}: falling back to default flaky percentage of #{DEFAULT_FLAKEY}" + pct = DEFAULT_FLAKEY + end + flaky(pct) + end end helpers do