Skip to content

Commit

Permalink
Add config option to suppress automatically starting the reporter
Browse files Browse the repository at this point in the history
This can avoid issues in some applications where additional setup is needed before safely starting the reporter. Specifically, we had a customer who was configuring their Sidekiq Redis connection in `after_initialize`, and our reporter was starting (and attempting to fetch Sidekiq metrics from Redis) before Sidekiq was fully configured.
  • Loading branch information
adamlogic committed Sep 5, 2023
1 parent c62e3c8 commit d46fb59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
16 changes: 16 additions & 0 deletions judoscale-rails/lib/judoscale/rails/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "judoscale/config"

module Judoscale
module Rails
module Config
attr_accessor :start_reporter_after_initialize

def reset
super
@start_reporter_after_initialize = true
end
end

::Judoscale::Config.prepend Config
end
end
6 changes: 3 additions & 3 deletions judoscale-rails/lib/judoscale/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "rails"
require "rails/railtie"
require "judoscale/request_middleware"
require "judoscale/config"
require "judoscale/rails/config"
require "judoscale/logger"
require "judoscale/reporter"

Expand All @@ -21,7 +21,7 @@ def in_rake_task?
end

initializer "Judoscale.logger" do |app|
Config.instance.logger = ::Rails.logger
::Judoscale::Config.instance.logger = ::Rails.logger
end

initializer "Judoscale.request_middleware" do |app|
Expand All @@ -33,7 +33,7 @@ def in_rake_task?

config.after_initialize do
# Don't suppress this in Rake tasks since some job adapters use Rake tasks to run jobs.
Reporter.start unless in_rails_console?
Reporter.start if !in_rails_console? && ::Judoscale::Config.instance.start_reporter_after_initialize
end
end
end
Expand Down
1 change: 1 addition & 0 deletions sample-apps/rails-sample/config/initializers/judoscale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
Judoscale.configure do |config|
# Open https://requestinspector.com/p/judoscale-ruby in a browser to monitor requests
config.api_base_url = ENV["JUDOSCALE_URL"] || "https://requestinspector.com/inspect/judoscale-ruby"
# config.start_reporter_after_initialize = false
end

0 comments on commit d46fb59

Please sign in to comment.