[15 min fix] Fix some autoloading deprecation warnings (#13793)
* Fix autoloading for RateLimitChecker * Fix autoloading for ForemStatsClient * Fix autoloading for middlewares * Move things to their proper place * Move middleware usage to the proper place * Re-add rest-client in datadog driver correctly * Already required in config/initializers/middlewares.rb * Bring that back * Fix Honeybadger spec
This commit is contained in:
parent
5832d146de
commit
70e0e9b83a
11 changed files with 77 additions and 66 deletions
|
|
@ -1,28 +1,32 @@
|
|||
require "httpclient"
|
||||
require "rest-client"
|
||||
|
||||
module ForemStatsDrivers
|
||||
class DatadogDriver
|
||||
include ActsAsForemStatsDriver
|
||||
|
||||
setup_driver do
|
||||
Datadog.configure do |c|
|
||||
c.tracer env: Rails.env
|
||||
c.tracer enabled: ENV["DD_API_KEY"].present?
|
||||
c.tracer partial_flush: true
|
||||
c.tracer priority_sampling: true
|
||||
c.use :sidekiq
|
||||
c.use :redis, service_name: "redis", describes: { url: ENV["REDIS_URL"] }
|
||||
c.use :redis, service_name: "redis-sessions", describes: { url: ENV["REDIS_SESSIONS_URL"] }
|
||||
c.use :redis, service_name: "redis-sidekiq", describes: { url: ENV["REDIS_SIDEKIQ_URL"] }
|
||||
c.use :redis, service_name: "redis-rpush", describes: { url: ENV["REDIS_RPUSH_URL"] }
|
||||
c.use :rails
|
||||
c.use :http, split_by_domain: false
|
||||
c.use :faraday, split_by_domain: true
|
||||
|
||||
c.use :concurrent_ruby
|
||||
c.use :excon, split_by_domain: true
|
||||
c.use :faraday, split_by_domain: true
|
||||
c.use :http, split_by_domain: false
|
||||
c.use :httpclient, split_by_domain: false
|
||||
c.use :httprb, split_by_domain: true
|
||||
c.use :rails
|
||||
c.use :redis, service_name: "redis", describes: { url: ENV["REDIS_URL"] }
|
||||
c.use :redis, service_name: "redis-rpush", describes: { url: ENV["REDIS_RPUSH_URL"] }
|
||||
c.use :redis, service_name: "redis-sessions", describes: { url: ENV["REDIS_SESSIONS_URL"] }
|
||||
c.use :redis, service_name: "redis-sidekiq", describes: { url: ENV["REDIS_SIDEKIQ_URL"] }
|
||||
c.use :rest_client
|
||||
c.use :concurrent_ruby
|
||||
c.use :sidekiq
|
||||
end
|
||||
|
||||
Datadog::Statsd.new
|
||||
end
|
||||
end
|
||||
|
|
|
|||
15
app/lib/middlewares/set_cookie_domain.rb
Normal file
15
app/lib/middlewares/set_cookie_domain.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
module Middlewares
|
||||
# Since we must explicitly set the cookie domain in session_store before SiteConfig is available,
|
||||
# this ensures we properly set the cookie to SiteConfig.app_domain at runtime.
|
||||
class SetCookieDomain
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
env["rack.session.options"][:domain] = ".#{SiteConfig.app_domain}"
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
13
app/lib/middlewares/set_time_zone.rb
Normal file
13
app/lib/middlewares/set_time_zone.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
module Middlewares
|
||||
class SetTimeZone
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
Time.zone = ActiveSupport::TimeZone.new(ENV["TZ"]) if ENV["TZ"]
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
# Since we must explicitly set the cookie domain in session_store before SiteConfig is available,
|
||||
# this ensures we properly set the cookie to SiteConfig.app_domain at runtime.
|
||||
|
||||
class SetCookieDomain
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
if Rails.env.production?
|
||||
env["rack.session.options"][:domain] = ".#{SiteConfig.app_domain}"
|
||||
end
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
# NOTE: this middleware is only for test mode
|
||||
class SetTimeZone
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
Time.zone = ActiveSupport::TimeZone.new(ENV["TZ"]) if ENV["TZ"]
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
|
@ -63,8 +63,6 @@ module PracticalDeveloper
|
|||
# Therefore we disable "per_form_csrf_tokens" for the time being.
|
||||
config.action_controller.per_form_csrf_tokens = false
|
||||
|
||||
config.middleware.use SetCookieDomain
|
||||
|
||||
# NOTE: [Rails 6]
|
||||
# To improve security, Rails embeds the purpose and expiry metadata inside encrypted or signed cookies value.
|
||||
config.action_dispatch.use_cookies_with_metadata = false
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ Rails.application.configure do
|
|||
|
||||
config.cache_classes = true
|
||||
|
||||
# Include middleware to ensure timezone for browser requests for Capybara specs
|
||||
# matches the random zonebie timezone set at the beginning of our spec run
|
||||
config.middleware.use SetTimeZone
|
||||
|
||||
# See https://github.com/rails/rails/issues/40613#issuecomment-727283155
|
||||
config.action_view.cache_template_loading = true
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +1,26 @@
|
|||
# Can be used to implement more programatic error handling
|
||||
# https://docs.honeybadger.io/lib/ruby/getting-started/ignoring-errors.html#ignore-programmatically
|
||||
|
||||
MESSAGE_FINGERPRINTS = {
|
||||
"SuspendedError" => "banned",
|
||||
"Rack::Timeout::RequestTimeoutException" => "rack_timeout",
|
||||
"Rack::Timeout::RequestTimeoutError" => "rack_timeout",
|
||||
"PG::QueryCanceled" => "pg_query_canceled"
|
||||
}.freeze
|
||||
|
||||
COMPONENT_FINGERPRINTS = {
|
||||
"internal" => "internal"
|
||||
}.freeze
|
||||
|
||||
HONEYBADGER_EXCEPTIONS_TO_IGNORE = [
|
||||
ActiveRecord::QueryCanceled,
|
||||
ActiveRecord::RecordNotFound,
|
||||
Pundit::NotAuthorizedError,
|
||||
RateLimitChecker::LimitReached,
|
||||
].freeze
|
||||
|
||||
# rubocop:disable Metrics/BlockLength
|
||||
Rails.application.reloader.to_prepare do
|
||||
message_fingerprints = {
|
||||
"SuspendedError" => "banned",
|
||||
"Rack::Timeout::RequestTimeoutException" => "rack_timeout",
|
||||
"Rack::Timeout::RequestTimeoutError" => "rack_timeout",
|
||||
"PG::QueryCanceled" => "pg_query_canceled"
|
||||
}
|
||||
|
||||
component_fingerprints = {
|
||||
"internal" => "internal"
|
||||
}
|
||||
|
||||
honeybadger_exceptions_to_ignore = [
|
||||
ActiveRecord::QueryCanceled,
|
||||
ActiveRecord::RecordNotFound,
|
||||
Pundit::NotAuthorizedError,
|
||||
RateLimitChecker::LimitReached,
|
||||
]
|
||||
|
||||
# https://docs.honeybadger.io/lib/ruby/gem-reference/configuration.html
|
||||
Honeybadger.configure do |config|
|
||||
config.env = "#{ApplicationConfig['APP_DOMAIN']}-#{Rails.env}"
|
||||
|
|
@ -32,7 +33,7 @@ Rails.application.reloader.to_prepare do
|
|||
# Logging allows us to fill in gaps if we need to when errors get discarded.
|
||||
config.send_data_at_exit = false
|
||||
|
||||
config.exceptions.ignore += HONEYBADGER_EXCEPTIONS_TO_IGNORE
|
||||
config.exceptions.ignore += honeybadger_exceptions_to_ignore
|
||||
config.request.filter_keys += %w[authorization]
|
||||
config.sidekiq.attempt_threshold = 10
|
||||
config.breadcrumbs.enabled = true
|
||||
|
|
@ -40,15 +41,16 @@ Rails.application.reloader.to_prepare do
|
|||
config.before_notify do |notice|
|
||||
notice.fingerprint = if notice.error_message&.include?("SIGTERM") && notice.component&.include?("feeds_import")
|
||||
notice.error_message
|
||||
elsif (msg_key = MESSAGE_FINGERPRINTS.keys.detect do |k, _v|
|
||||
elsif (msg_key = message_fingerprints.keys.detect do |k, _v|
|
||||
notice.error_message&.include?(k)
|
||||
end)
|
||||
MESSAGE_FINGERPRINTS[msg_key]
|
||||
elsif (cmp_key = COMPONENT_FINGERPRINTS.keys.detect do |k, _v|
|
||||
message_fingerprints[msg_key]
|
||||
elsif (cmp_key = component_fingerprints.keys.detect do |k, _v|
|
||||
notice.component&.include?(k)
|
||||
end)
|
||||
COMPONENT_FINGERPRINTS[cmp_key]
|
||||
component_fingerprints[cmp_key]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/BlockLength
|
||||
|
|
|
|||
5
config/initializers/middlewares.rb
Normal file
5
config/initializers/middlewares.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Rails.configuration.middleware.use(Middlewares::SetCookieDomain) if Rails.env.production?
|
||||
|
||||
# Include middleware to ensure timezone for browser requests for Capybara specs
|
||||
# matches the random zonebie timezone set at the beginning of our spec run
|
||||
Rails.configuration.middleware.use(Middlewares::SetTimeZone) if Rails.env.test?
|
||||
|
|
@ -1,7 +1,12 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe Honeybadger do
|
||||
MESSAGE_FINGERPRINTS.each do |error_key, fingerprint|
|
||||
{
|
||||
"SuspendedError" => "banned",
|
||||
"Rack::Timeout::RequestTimeoutException" => "rack_timeout",
|
||||
"Rack::Timeout::RequestTimeoutError" => "rack_timeout",
|
||||
"PG::QueryCanceled" => "pg_query_canceled"
|
||||
}.each do |error_key, fingerprint|
|
||||
include_examples "#sets_correct_honeybadger_fingerprint", error_key, fingerprint
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue