Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions judoscale-rails/lib/judoscale/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def in_rake_task?(task_regex)
top_level_tasks.any? { |task| task_regex.match?(task) }
end

def in_one_off_container?
judoscale_config.current_platform.one_off?
end

def judoscale_config
# Disambiguate from Judoscale::Rails::Config
::Judoscale::Config.instance
Expand All @@ -47,8 +43,6 @@ def judoscale_config
config.after_initialize do
if in_rails_console_or_runner?
logger.debug "No reporting since we're in a Rails console or runner process"
elsif in_one_off_container?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed here since Reporter#start! has this logic. We're moving it there for parity with Node/Python libs and so this behavior is not Rails-specific.

logger.debug "No reporting since we're in a one-off container"
elsif in_rake_task?(judoscale_config.rake_task_ignore_regex)
logger.debug "No reporting since we're in a build process"
elsif judoscale_config.start_reporter_after_initialize
Expand Down
18 changes: 10 additions & 8 deletions judoscale-ruby/lib/judoscale/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module Judoscale
# The hosting platform we detected from the environment. The container/instance
# id is just one property of the platform — behavior that only applies to
# certain platforms (whether an instance is a redundant member of a formation,
# or a one-off task) lives on the platform subclasses that actually have those
# concepts, instead of being re-derived from the shape of the container string.
# or an ephemeral process) lives on the platform subclasses that actually have
# those concepts, instead of being re-derived from the shape of the container
# string.
class Platform
attr_reader :container

Expand All @@ -14,13 +15,13 @@ def initialize(container)
end

# Most platforms expose opaque, non-ordinal instance ids (Render, ECS, Fly,
# Railway, custom), so by default no instance is redundant and none is one-off.
# Railway, custom), so by default no instance is redundant or ephemeral.
# Platforms that have those concepts override these.
def redundant_instance?
false
end

def one_off?
def ephemeral_instance?
false
end

Expand Down Expand Up @@ -61,9 +62,10 @@ def redundant_instance?
match ? match[1].to_i > 1 : false
end

# Heroku one-off dynos are named "run.1234".
def one_off?
container.start_with?("run.")
# Heroku release phase and one-off dynos are named "release.1234" and "run.1234".
def ephemeral_instance?
normalized_container = container.downcase
normalized_container.start_with?("release.", "run.")
end
end

Expand All @@ -75,7 +77,7 @@ def redundant_instance?
end

# Scalingo one-off containers are named "one-off-1234".
def one_off?
def ephemeral_instance?
container.start_with?("one-off-")
end
end
Expand Down
5 changes: 5 additions & 0 deletions judoscale-ruby/lib/judoscale/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def self.start(config = Config.instance, adapters = Judoscale.adapters)
def start!(config, adapters)
@pid = Process.pid

if config.current_platform.ephemeral_instance?
logger.debug "Reporter not started: in an ephemeral container"
return
end

if config.api_base_url.nil? || config.api_base_url.strip.empty?
logger.debug "Set api_base_url to enable metrics reporting"
return
Expand Down
29 changes: 17 additions & 12 deletions judoscale-ruby/test/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,27 @@ module Judoscale
_(Platform::Unknown.new("").redundant_instance?).must_equal false
end

it "treats Heroku and Scalingo one-off containers as one-off" do
_(Platform::Heroku.new("run.1234").one_off?).must_equal true
_(Platform::Scalingo.new("one-off-1234").one_off?).must_equal true
it "treats Heroku release phase and one-off dynos as ephemeral instances" do
_(Platform::Heroku.new("release.1").ephemeral_instance?).must_equal true
_(Platform::Heroku.new("run.1234").ephemeral_instance?).must_equal true
end

it "does not treat formation containers as one-off" do
_(Platform::Heroku.new("web.1").one_off?).must_equal false
_(Platform::Scalingo.new("web-1").one_off?).must_equal false
_(Platform::Scalingo.new("worker-2").one_off?).must_equal false
_(Platform::Heroku.new("runner-1").one_off?).must_equal false
it "treats Scalingo one-off containers as ephemeral instances" do
_(Platform::Scalingo.new("one-off-1234").ephemeral_instance?).must_equal true
end

it "never treats opaque-id platforms as one-off" do
_(Platform::Render.new("5497f74465-m5wwr", service_id: "srv-x").one_off?).must_equal false
_(Platform::Fly.new("683d924b322418").one_off?).must_equal false
_(Platform::Unknown.new("").one_off?).must_equal false
it "does not treat formation containers as ephemeral instances" do
_(Platform::Heroku.new("web.1").ephemeral_instance?).must_equal false
_(Platform::Heroku.new("worker.2").ephemeral_instance?).must_equal false
_(Platform::Heroku.new("runner-1").ephemeral_instance?).must_equal false
_(Platform::Scalingo.new("web-1").ephemeral_instance?).must_equal false
_(Platform::Scalingo.new("worker-2").ephemeral_instance?).must_equal false
end

it "never treats opaque-id platforms as ephemeral instances" do
_(Platform::Render.new("5497f74465-m5wwr", service_id: "srv-x").ephemeral_instance?).must_equal false
_(Platform::Fly.new("683d924b322418").ephemeral_instance?).must_equal false
_(Platform::Unknown.new("").ephemeral_instance?).must_equal false
end

it "strips the service id prefix from the Render instance id" do
Expand Down
16 changes: 16 additions & 0 deletions judoscale-ruby/test/reporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ def stub_reporter_loop
_(log_string).must_include "Set api_base_url to enable metrics reporting"
end

[
["Heroku release", Platform::Heroku.new("release.1")],
["Heroku", Platform::Heroku.new("run.1234")],
["Scalingo", Platform::Scalingo.new("one-off-1234")]
].each do |platform_name, platform|
it "does not run the reporter thread in a #{platform_name} ephemeral instance" do
Comment on lines +135 to +140

@carlosantoniodasilva carlosantoniodasilva Jun 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previous comment

Minor suggestion to run a single test for "ephemeral instances" and then if we're testing multiple we loop inside. It's fine though to have individual/separated tests, but generally for single behavior-testing on a few variants, and even slightly perf-gain, I usually lean on that.

Suggested change
[
["Heroku release", Platform::Heroku.new("release.1")],
["Heroku", Platform::Heroku.new("run.1234")],
["Scalingo", Platform::Scalingo.new("one-off-1234")]
].each do |platform_name, platform|
it "does not run the reporter thread in a #{platform_name} ephemeral instance" do
it "does not run the reporter thread in an ephemeral instance" do
[
["Heroku release", Platform::Heroku.new("release.1")],
["Heroku", Platform::Heroku.new("run.1234")],
["Scalingo", Platform::Scalingo.new("one-off-1234")]
].each do |platform_name, platform|

Update: it's a bit of a personal opinion and may be controversial, and I also see the node and python packages are doing a similar test, so it's totally cool to leave as-is for consistency across the board.

Judoscale.configure { |config| config.current_platform = platform }

Reporter.instance.stub(:run_loop, ->(*) { raise "SHOULD NOT BE CALLED" }) {
Reporter.instance.start!(Config.instance, Judoscale.adapters)
}

_(log_string).must_include "Reporter not started: in an ephemeral container"
end
end

it "does not run the reporter thread when there are no metrics collectors" do
Reporter.instance.stub(:run_loop, ->(*) { raise "SHOULD NOT BE CALLED" }) {
Reporter.instance.start!(Config.instance, Judoscale.adapters.select { |a| a.metrics_collector.nil? })
Expand Down