From 3ee63d46132900d89dd4a805aab73b3b97b46d55 Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Fri, 20 Oct 2023 08:58:33 +0200 Subject: [PATCH] do not log Notifications#polling action anymore, by default, can be enable via env variable ENABLE_NOTIFICATIONS_POLLING_LOGGING=true --- CHANGELOG.md | 1 + Gemfile | 1 + Gemfile.lock | 2 ++ app/controllers/api/notifications_controller.rb | 6 +++--- config/initializers/silencer.rb | 13 +++++++++++++ config/secrets.yml | 4 ++++ 6 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 config/initializers/silencer.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 63ec79177..e498e5495 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix a bug: fix all failing tasks of rake task file chain.rake - Fix a bug: file_size_validator.rb was broken since ruby v3, see https://github.com/rails/rails/issues/41270 - decreases sidekiq concurrency from 25 to 5, 25 is too much and consumes memory for nothing +- do not log Notifications#polling action anymore, by default, can be enable via env variable ENABLE_NOTIFICATIONS_POLLING_LOGGING=true ## v6.2.0 2023 October 13 diff --git a/Gemfile b/Gemfile index f7198a90f..94aa61a42 100644 --- a/Gemfile +++ b/Gemfile @@ -153,3 +153,4 @@ gem 'sentry-ruby' gem "reverse_markdown" gem "ancestry" +gem 'silencer', require: false \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 1d41c1961..e5bdfad2b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -462,6 +462,7 @@ GEM concurrent-ruby (~> 1.0, >= 1.0.5) sidekiq (>= 5.0, < 8.0) thor (>= 0.20, < 3.0) + silencer (2.0.0) simplecov (0.19.0) docile (~> 1.1) simplecov-html (~> 0.11) @@ -611,6 +612,7 @@ DEPENDENCIES sidekiq (>= 6.0.7) sidekiq-scheduler sidekiq-unique-jobs (~> 7.1.23) + silencer spring (~> 4) spring-watcher-listen (~> 2.1.0) stripe (= 5.29.0) diff --git a/app/controllers/api/notifications_controller.rb b/app/controllers/api/notifications_controller.rb index c226d2b82..8f8c72c03 100644 --- a/app/controllers/api/notifications_controller.rb +++ b/app/controllers/api/notifications_controller.rb @@ -52,9 +52,9 @@ class API::NotificationsController < API::APIController def polling @notifications = current_user.notifications - .with_valid_notification_type - .where('notifications.is_read = false AND notifications.created_at >= :date', date: params[:last_poll]) - .order('notifications.created_at DESC') + .with_valid_notification_type + .where('notifications.is_read = false AND notifications.created_at >= :date', date: params[:last_poll]) + .order('notifications.created_at DESC') @totals = { total: current_user.notifications.with_valid_notification_type.delivered_in_system(current_user).count, unread: current_user.notifications.with_valid_notification_type.delivered_in_system(current_user).where(is_read: false).count diff --git a/config/initializers/silencer.rb b/config/initializers/silencer.rb new file mode 100644 index 000000000..d54aaa727 --- /dev/null +++ b/config/initializers/silencer.rb @@ -0,0 +1,13 @@ +require 'silencer/rails/logger' + +silenced_actions = [] +silenced_actions << "/api/notifications/polling" unless Rails.application.secrets.enable_notifications_polling_logging + +Rails.application.configure do + config.middleware.swap( + Rails::Rack::Logger, + Silencer::Logger, + config.log_tags, + silence: silenced_actions + ) +end \ No newline at end of file diff --git a/config/secrets.yml b/config/secrets.yml index 55e062efd..5c878f860 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -43,6 +43,7 @@ development: adminsys_email: <%= ENV["ADMINSYS_EMAIL"] %> allow_insecure_http: <%= ENV.fetch("ALLOW_INSECURE_HTTP", false) %> locked_settings: <%= ENV.fetch("LOCKED_SETTINGS", 'uuid,origin').split(/,/) %> + enable_notifications_polling_logging: <%= ENV.fetch("ENABLE_NOTIFICATIONS_POLLING_LOGGING", false) %> test: secret_key_base: 83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30 @@ -75,6 +76,7 @@ test: adminsys_email: <%= ENV["ADMINSYS_EMAIL"] %> allow_insecure_http: <%= ENV.fetch("ALLOW_INSECURE_HTTP", false) %> locked_settings: <%= ENV.fetch("LOCKED_SETTINGS", 'uuid,origin').split(/,/) %> + enable_notifications_polling_logging: <%= ENV.fetch("ENABLE_NOTIFICATIONS_POLLING_LOGGING", false) %> staging: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> @@ -117,6 +119,7 @@ staging: enable_in_context_translation: <%= ENV["ENABLE_IN_CONTEXT_TRANSLATION"] %> allow_insecure_http: <%= ENV.fetch("ALLOW_INSECURE_HTTP", false) %> locked_settings: <%= ENV.fetch("LOCKED_SETTINGS", 'uuid,origin').split(/,/) %> + enable_notifications_polling_logging: <%= ENV.fetch("ENABLE_NOTIFICATIONS_POLLING_LOGGING", false) %> # Do not keep production secrets in the repository, # instead read values from the environment. @@ -162,3 +165,4 @@ production: adminsys_email: <%= ENV["ADMINSYS_EMAIL"] %> allow_insecure_http: <%= ENV.fetch("ALLOW_INSECURE_HTTP", false) %> locked_settings: <%= ENV.fetch("LOCKED_SETTINGS", 'uuid,origin').split(/,/) %> + enable_notifications_polling_logging: <%= ENV.fetch("ENABLE_NOTIFICATIONS_POLLING_LOGGING", false) %>