-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify RuntimeContainer #178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,28 +5,14 @@ | |
|
||
module Judoscale | ||
class Config | ||
class RuntimeContainer | ||
# E.g.: | ||
# (Heroku) => "worker_fast", "3" | ||
# (Render) => "srv-cfa1es5a49987h4vcvfg", "5497f74465-m5wwr" | ||
def initialize(service_name = nil, instance = nil) | ||
@service_name = service_name | ||
@instance = instance | ||
end | ||
|
||
def to_s | ||
# heroku: 'worker_fast.5' | ||
# render: 'srv-cfa1es5a49987h4vcvfg.5497f74465-m5wwr' | ||
"#{@service_name}.#{@instance}" | ||
end | ||
|
||
class RuntimeContainer < String | ||
# Since Heroku exposes ordinal dyno 'numbers', we can tell if the current | ||
# instance is redundant (and thus skip collecting some metrics sometimes) | ||
# We don't have a means of determining that on Render though — so every | ||
# instance must be considered non-redundant | ||
def redundant_instance? | ||
instance_is_number = Integer(@instance, exception: false) | ||
instance_is_number && instance_is_number != 1 | ||
instance_number = split(".")[1].to_i | ||
instance_number > 1 | ||
end | ||
end | ||
|
||
|
@@ -99,11 +85,10 @@ def reset | |
|
||
if ENV["RENDER_INSTANCE_ID"] | ||
instance = ENV["RENDER_INSTANCE_ID"].delete_prefix(ENV["RENDER_SERVICE_ID"]).delete_prefix("-") | ||
@current_runtime_container = RuntimeContainer.new ENV["RENDER_SERVICE_ID"], instance | ||
@current_runtime_container = RuntimeContainer.new instance | ||
@api_base_url ||= "https://adapter.judoscale.com/api/#{ENV["RENDER_SERVICE_ID"]}" | ||
elsif ENV["DYNO"] | ||
service_name, instance = ENV["DYNO"].split "." | ||
@current_runtime_container = RuntimeContainer.new service_name, instance | ||
@current_runtime_container = RuntimeContainer.new ENV["DYNO"] | ||
else | ||
# unsupported platform? Don't want to leave @current_runtime_container nil though | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to drop this comment now 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it no longer valid? I still found it helpful, assuming we don't want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't, but the "unsupported platform" bit isn't a valid assumption anymore, now that we know there are platforms which the correct functionality is to have the bare |
||
@current_runtime_container = RuntimeContainer.new | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this working off the basis that
nil.to_i
is0
? 😆There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever 😁