Skip to content

Commit

Permalink
Add support for Amazon ECS services
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic committed Jul 14, 2023
1 parent be6aeda commit 4f3dc83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion judoscale-ruby/lib/judoscale/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions judoscale-ruby/test/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4f3dc83

Please sign in to comment.