From f9f8da01b2ff9f9fc425c8e7ac06e2b9512ca033 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Mon, 8 Jul 2024 10:02:35 -0700 Subject: [PATCH] Add a flag for throttle notices so we can exclude them from the bot boxes --- config/initializers/rack_attack.rb | 4 +++- config/settings.yml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 1cbf5deb5..1ce64418a 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -64,7 +64,9 @@ match_data = request.env['rack.attack.match_data'] now = match_data[:epoch_time] - Honeybadger.notify("Throttling request", context: { ip: request.ip, path: request.path }.merge(match_data)) if match_data[:count] < 15 || (match_data[:count] % 10).zero? + if (Settings.SEND_THROTTLE_NOTIFICATIONS_TO_HONEYBADGER && match_data[:count] < 15) || (match_data[:count] % 10).zero? + Honeybadger.notify("Throttling request", context: { ip: request.ip, path: request.path }.merge(match_data)) + end headers = { 'RateLimit-Limit' => match_data[:limit].to_s, diff --git a/config/settings.yml b/config/settings.yml index 1bc6eab35..3283c3b19 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -23,6 +23,7 @@ GENERATE_SITEMAP: true DEVISE_SECRET_KEY: <%= Rails.application.secret_key_base %> DISABLE_SESSIONS: false THROTTLE_TRAFFIC: false +SEND_THROTTLE_NOTIFICATIONS_TO_HONEYBADGER: true OCLC: API_KEY: the-oclc-api-key BASE_URL: http://www.worldcat.org/webservices/catalog/content/citations