From ca565d377f6aed430a57a89862262e7bf254e8d1 Mon Sep 17 00:00:00 2001 From: Adam McCrea Date: Thu, 12 Oct 2023 09:41:29 -0400 Subject: [PATCH] fix: Gracefully fail when JUDOSCALE_URL is a blank string --- judoscale-ruby/lib/judoscale/reporter.rb | 2 +- judoscale-ruby/test/reporter_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/judoscale-ruby/lib/judoscale/reporter.rb b/judoscale-ruby/lib/judoscale/reporter.rb index bd61bfd1..232dc6a0 100644 --- a/judoscale-ruby/lib/judoscale/reporter.rb +++ b/judoscale-ruby/lib/judoscale/reporter.rb @@ -19,7 +19,7 @@ def self.start(config = Config.instance, adapters = Judoscale.adapters) def start!(config, adapters) @pid = Process.pid - if !config.api_base_url + if config.api_base_url.nil? || config.api_base_url.strip.empty? logger.debug "Set api_base_url to enable metrics reporting" return end diff --git a/judoscale-ruby/test/reporter_test.rb b/judoscale-ruby/test/reporter_test.rb index 6fc4139c..28efef98 100644 --- a/judoscale-ruby/test/reporter_test.rb +++ b/judoscale-ruby/test/reporter_test.rb @@ -122,6 +122,16 @@ def stub_reporter_loop _(log_string).must_include "Set api_base_url to enable metrics reporting" end + it "does not run the reporter thread when the API url is a blank string" do + Judoscale.configure { |config| config.api_base_url = " " } + + Reporter.instance.stub(:run_loop, ->(*) { raise "SHOULD NOT BE CALLED" }) { + Reporter.instance.start!(Config.instance, Judoscale.adapters) + } + + _(log_string).must_include "Set api_base_url to enable metrics reporting" + 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? })