diff --git a/judoscale-ruby/lib/judoscale/config.rb b/judoscale-ruby/lib/judoscale/config.rb index 0da928f5..c3951c4b 100644 --- a/judoscale-ruby/lib/judoscale/config.rb +++ b/judoscale-ruby/lib/judoscale/config.rb @@ -89,9 +89,11 @@ def reset @api_base_url ||= "https://adapter.judoscale.com/api/#{ENV["RENDER_SERVICE_ID"]}" elsif ENV["DYNO"] @current_runtime_container = RuntimeContainer.new ENV["DYNO"] + elsif (metadata_uri = ENV["ECS_CONTAINER_METADATA_URI"]) + @current_runtime_container = RuntimeContainer.new(metadata_uri.split("/").last) else # unsupported platform? Don't want to leave @current_runtime_container nil though - @current_runtime_container = RuntimeContainer.new + @current_runtime_container = RuntimeContainer.new("") end end diff --git a/judoscale-ruby/test/config_test.rb b/judoscale-ruby/test/config_test.rb index 45c0e4a9..ad4c34ba 100644 --- a/judoscale-ruby/test/config_test.rb +++ b/judoscale-ruby/test/config_test.rb @@ -60,6 +60,20 @@ module Judoscale end end + it "initializes the config from default Amazon ECS ENV vars" do + # Users must set JUDOSCALE_URL manually when using Amazon ECS. + env = { + "ECS_CONTAINER_METADATA_URI" => "http://169.254.170.2/v3/a8880ee042bc4db3ba878dce65b769b6-2750272591", + "JUDOSCALE_URL" => "https://adapter.judoscale.com/api/1234567890" + } + + use_env env do + config = Config.instance + _(config.api_base_url).must_equal "https://adapter.judoscale.com/api/1234567890" + _(config.current_runtime_container).must_equal "a8880ee042bc4db3ba878dce65b769b6-2750272591" + end + end + it "allows ENV vars config overrides for the debug and URL" do env = { "DYNO" => "web.2",