Skip to content

A platform for community discussion. Free, open, simple.

DEV: Deal with log spam for upcoming changes (#37429)

Martin Brennand8e47d08936a
diff --git a/app/jobs/scheduled/check_upcoming_changes.rb b/app/jobs/scheduled/check_upcoming_changes.rb
index 29739c19606..722efb169ab 100644
--- a/app/jobs/scheduled/check_upcoming_changes.rb
+++ b/app/jobs/scheduled/check_upcoming_changes.rb
@@ -55,6 +55,10 @@ module Jobs
end
end
+ on_model_not_found(:all_admins) do |model_name|
+ verbose_log(site, :debug, "No admins found, skipping tracking of upcoming changes")
+ end
+
on_failure do
verbose_log(
site,
@@ -71,16 +75,33 @@ module Jobs
change_notification_statuses.each do |setting_name, status|
if status[:success]
verbose_log(site, :info, "Notified site admins about promotion of '#{setting_name}'")
- else
- verbose_log(
- site,
- :error,
- "Failed to notify about promotion of '#{setting_name}': #{status[:error]} with backtrace: #{status[:backtrace]&.join("\n") || "N/A"}",
- )
+ next
end
+
+ log_level =
+ case status[:error_key]
+ when :does_not_meet_or_exceed_promotion_status
+ :info
+ when :already_notified_about_promotion
+ :debug
+ when :already_manually_toggled
+ :debug
+ else
+ :error
+ end
+
+ verbose_log(
+ site,
+ log_level,
+ "Failed to notify about promotion of '#{setting_name}': #{status[:error]} with backtrace: #{status[:backtrace]&.join("\n") || "N/A"}",
+ )
end
end
+ on_model_not_found(:admin_user_ids) do |model_name|
+ verbose_log(site, :debug, "No admins found, skipping notification of promotions")
+ end
+
on_failure do
verbose_log(
site,
diff --git a/app/services/upcoming_changes/notify_promotions.rb b/app/services/upcoming_changes/notify_promotions.rb
index 250073aa47e..58b510588ce 100644
--- a/app/services/upcoming_changes/notify_promotions.rb
+++ b/app/services/upcoming_changes/notify_promotions.rb
@@ -29,6 +29,8 @@ class UpcomingChanges::NotifyPromotions
SiteSetting.upcoming_change_site_settings.index_with do |setting_name|
status_hash = {}
+ # NOTE: Make sure to handle additional error_key values in the
+ # CheckUpcomingChanges job's verbose_log.
UpcomingChanges::NotifyPromotion.call(
params: {
setting_name: setting_name.to_sym,
@@ -41,28 +43,33 @@ class UpcomingChanges::NotifyPromotions
on_failed_policy(:setting_is_available) do |policy|
status_hash[:error] = "Setting #{setting_name} is not available"
+ status_hash[:error_key] = :setting_not_available
end
on_failed_policy(:meets_or_exceeds_status) do |policy|
status_hash[
:error
] = "Setting #{setting_name} does not meet or exceed the promotion status"
+ status_hash[:error_key] = :does_not_meet_or_exceed_promotion_status
end
on_failed_policy(:change_has_not_already_been_notified_about_promotion) do |policy|
status_hash[
:error
] = "Setting #{setting_name} has already notified admins about promotion"
+ status_hash[:error_key] = :already_notified_about_promotion
end
on_failed_policy(:admin_has_not_manually_toggled) do |policy|
status_hash[
:error
] = "Setting #{setting_name} has been manually opted in or out by an admin, we did not notify admins about promotion"
+ status_hash[:error_key] = :already_manually_toggled
end
on_exceptions do |exception|
status_hash[:error] = exception.message
+ status_hash[:error_key] = :unexpected_error
status_hash[:backtrace] = exception.backtrace
end
end
diff --git a/spec/jobs/scheduled/check_upcoming_changes_spec.rb b/spec/jobs/scheduled/check_upcoming_changes_spec.rb
index 6c3f14bbc90..ed4edf58ab8 100644
--- a/spec/jobs/scheduled/check_upcoming_changes_spec.rb
+++ b/spec/jobs/scheduled/check_upcoming_changes_spec.rb
@@ -278,7 +278,7 @@ RSpec.describe Jobs::CheckUpcomingChanges do
it "logs the error" do
track_log_messages do |logger|
described_class.new.execute({})
- expect(logger.errors.join("\n")).to include(
+ expect(logger.infos.join("\n")).to include(
"Failed to notify about promotion of 'enable_upload_debug_mode': Setting enable_upload_debug_mode does not meet or exceed the promotion status",
)
end
diff --git a/spec/services/upcoming_changes/notify_promotions_spec.rb b/spec/services/upcoming_changes/notify_promotions_spec.rb
index d509617528f..9155a8eee07 100644
--- a/spec/services/upcoming_changes/notify_promotions_spec.rb
+++ b/spec/services/upcoming_changes/notify_promotions_spec.rb
@@ -47,11 +47,13 @@ RSpec.describe UpcomingChanges::NotifyPromotions do
enable_upload_debug_mode: {
success: false,
error: "test error",
+ error_key: :unexpected_error,
backtrace: a_kind_of(Array),
},
show_user_menu_avatars: {
success: false,
error: "Setting show_user_menu_avatars does not meet or exceed the promotion status",
+ error_key: :does_not_meet_or_exceed_promotion_status,
},
)
end
@@ -68,6 +70,7 @@ RSpec.describe UpcomingChanges::NotifyPromotions do
show_user_menu_avatars: {
success: false,
error: "Setting show_user_menu_avatars does not meet or exceed the promotion status",
+ error_key: :does_not_meet_or_exceed_promotion_status,
},
)
end
@@ -188,6 +191,14 @@ RSpec.describe UpcomingChanges::NotifyPromotions do
events = DiscourseEvent.track_events { result }
expect(events.select { |e| e[:event_name] == :upcoming_change_enabled }).to be_empty
end
+
+ it "returns the correct error and error key" do
+ expect(result[:change_notification_statuses][:enable_upload_debug_mode]).to match(
+ success: false,
+ error: "Setting enable_upload_debug_mode does not meet or exceed the promotion status",
+ error_key: :does_not_meet_or_exceed_promotion_status,
+ )
+ end
end
context "when settings are already notified about promotion" do
@@ -217,6 +228,14 @@ RSpec.describe UpcomingChanges::NotifyPromotions do
end,
).to be_empty
end
+
+ it "returns the correct error and error key" do
+ expect(result[:change_notification_statuses][:enable_upload_debug_mode]).to match(
+ success: false,
+ error: "Setting enable_upload_debug_mode has already notified admins about promotion",
+ error_key: :already_notified_about_promotion,
+ )
+ end
end
context "when settings are opted out" do
@@ -240,6 +259,15 @@ RSpec.describe UpcomingChanges::NotifyPromotions do
end,
).to be_empty
end
+
+ it "returns the correct error and error key" do
+ expect(result[:change_notification_statuses][:enable_upload_debug_mode]).to match(
+ success: false,
+ error:
+ "Setting enable_upload_debug_mode has been manually opted in or out by an admin, we did not notify admins about promotion",
+ error_key: :already_manually_toggled,
+ )
+ end
end
end
end