-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/APPEALS-21351-merged
- Loading branch information
Showing
25 changed files
with
638 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
# @abstract Subclass and override {.call} to implement a custom DeprecationWarnings handler class. | ||
# @note For use with `ActiveSupport::Deprecation.behavior=`. | ||
module DeprecationWarnings | ||
class BaseHandler | ||
class << self | ||
# Subclasses must respond to `.call` to play nice with `ActiveSupport::Deprecation.behavior=`. | ||
# https://github.com/rails/rails/blob/a4581b53aae93a8dd3205abae0630398cbce9204/activesupport/lib/active_support/deprecation/behaviors.rb#L70-L71 | ||
# :reek:LongParameterList | ||
def call(_message, _callstack, _deprecation_horizon, _gem_name) | ||
fail NotImplementedError | ||
end | ||
|
||
# Subclasses must respond to `.arity` to play nice with `ActiveSupport::Deprecation.behavior=`. | ||
# Must return number of arguments accepted by `.call`. | ||
# https://github.com/rails/rails/blob/a4581b53aae93a8dd3205abae0630398cbce9204/activesupport/lib/active_support/deprecation/behaviors.rb#L101 | ||
def arity | ||
method(:call).arity | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "disallowed_deprecations" | ||
|
||
# @note For use with `ActiveSupport::Deprecation.behavior=`. | ||
module DeprecationWarnings | ||
class DevelopmentHandler < BaseHandler | ||
extend DisallowedDeprecations | ||
|
||
class << self | ||
# :reek:LongParameterList | ||
def call(message, _callstack, _deprecation_horizon, _gem_name) | ||
raise_if_disallowed_deprecation!(message) | ||
emit_warning_to_application_logs(message) | ||
end | ||
|
||
private | ||
|
||
def emit_warning_to_application_logs(message) | ||
Rails.logger.warn(message) | ||
end | ||
end | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
app/services/deprecation_warnings/disallowed_deprecations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
# @note Temporary solution for disallowed deprecation warnings. | ||
# To be replaced by ActiveSupport Disallowed Deprecations after upgrading to Rails 6.1: | ||
# https://rubyonrails.org/2020/12/9/Rails-6-1-0-release#disallowed-deprecation-support | ||
module DisallowedDeprecations | ||
class ::DisallowedDeprecationError < StandardError; end | ||
|
||
# Regular expressions for Rails 5.2 deprecation warnings that we have addressed in the codebase | ||
RAILS_5_2_FIXED_DEPRECATION_WARNING_REGEXES = [ | ||
/Dangerous query method \(method whose arguments are used as raw SQL\) called with non\-attribute argument\(s\)/ | ||
].freeze | ||
|
||
# Regular expressions for deprecation warnings that should raise an exception on detection | ||
DISALLOWED_DEPRECATION_WARNING_REGEXES = [ | ||
*RAILS_5_2_FIXED_DEPRECATION_WARNING_REGEXES | ||
].freeze | ||
|
||
# @param message [String] deprecation warning message to be checked against disallow list | ||
def raise_if_disallowed_deprecation!(message) | ||
if DISALLOWED_DEPRECATION_WARNING_REGEXES.any? { |re| re.match?(message) } | ||
fail DisallowedDeprecationError, message | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
# @note For use with `ActiveSupport::Deprecation.behavior=`. | ||
module DeprecationWarnings | ||
class ProductionHandler < BaseHandler | ||
APP_NAME = "caseflow" | ||
SLACK_ALERT_CHANNEL = "#appeals-deprecation-alerts" | ||
|
||
class << self | ||
# :reek:LongParameterList | ||
def call(message, callstack, deprecation_horizon, gem_name) | ||
emit_warning_to_application_logs(message) | ||
emit_warning_to_sentry(message, callstack, deprecation_horizon, gem_name) | ||
emit_warning_to_slack_alerts_channel(message) | ||
rescue StandardError => error | ||
Raven.capture_exception(error) | ||
end | ||
|
||
private | ||
|
||
def emit_warning_to_application_logs(message) | ||
Rails.logger.warn(message) | ||
end | ||
|
||
# :reek:LongParameterList | ||
def emit_warning_to_sentry(message, callstack, deprecation_horizon, gem_name) | ||
# Pre-emptive bugfix for future versions of the `sentry-raven` gem: | ||
# Need to convert callstack elements from `Thread::Backtrace::Location` objects to `Strings` | ||
# to avoid a `TypeError` on `options.deep_dup` in `Raven.capture_message`: | ||
# https://github.com/getsentry/sentry-ruby/blob/2e07e0295ba83df4c76c7bf3315d199c7050a7f9/lib/raven/instance.rb#L114 | ||
callstack_strings = callstack.map(&:to_s) | ||
|
||
Raven.capture_message( | ||
message, | ||
level: "warning", | ||
extra: { | ||
message: message, | ||
gem_name: gem_name, | ||
deprecation_horizon: deprecation_horizon, | ||
callstack: callstack_strings, | ||
environment: Rails.env | ||
} | ||
) | ||
end | ||
|
||
def emit_warning_to_slack_alerts_channel(message) | ||
slack_alert_title = "Deprecation Warning - #{APP_NAME} (#{ENV['DEPLOY_ENV']})" | ||
|
||
SlackService | ||
.new(url: ENV["SLACK_DISPATCH_ALERT_URL"]) | ||
.send_notification(message, slack_alert_title, SLACK_ALERT_CHANNEL) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "disallowed_deprecations" | ||
|
||
# @note For use with `ActiveSupport::Deprecation.behavior=`. | ||
module DeprecationWarnings | ||
class TestHandler < BaseHandler | ||
extend DisallowedDeprecations | ||
|
||
class << self | ||
# :reek:LongParameterList | ||
def call(message, _callstack, _deprecation_horizon, _gem_name) | ||
raise_if_disallowed_deprecation!(message) | ||
emit_error_to_stderr(message) | ||
end | ||
|
||
private | ||
|
||
def emit_error_to_stderr(message) | ||
ActiveSupport::Logger.new($stderr).error(message) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.