Class: Judoscale::Config
- Inherits:
-
Object
- Object
- Judoscale::Config
- Includes:
- Singleton
- Defined in:
- lib/judoscale/config.rb
Defined Under Namespace
Classes: JobAdapterConfig, RuntimeContainer
Class Attribute Summary collapse
-
.adapter_configs ⇒ Object
readonly
Returns the value of attribute adapter_configs.
Instance Attribute Summary collapse
-
#api_base_url ⇒ Object
Returns the value of attribute api_base_url.
-
#current_runtime_container ⇒ Object
Returns the value of attribute current_runtime_container.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#log_tag ⇒ Object
Returns the value of attribute log_tag.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_request_size_bytes ⇒ Object
Returns the value of attribute max_request_size_bytes.
-
#report_interval_seconds ⇒ Object
Returns the value of attribute report_interval_seconds.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #ignore_large_requests? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
96 97 98 |
# File 'lib/judoscale/config.rb', line 96 def initialize reset end |
Class Attribute Details
.adapter_configs ⇒ Object (readonly)
Returns the value of attribute adapter_configs.
67 68 69 |
# File 'lib/judoscale/config.rb', line 67 def adapter_configs @adapter_configs end |
Instance Attribute Details
#api_base_url ⇒ Object
Returns the value of attribute api_base_url.
92 93 94 |
# File 'lib/judoscale/config.rb', line 92 def api_base_url @api_base_url end |
#current_runtime_container ⇒ Object
Returns the value of attribute current_runtime_container.
92 93 94 |
# File 'lib/judoscale/config.rb', line 92 def current_runtime_container @current_runtime_container end |
#log_level ⇒ Object
Returns the value of attribute log_level.
94 95 96 |
# File 'lib/judoscale/config.rb', line 94 def log_level @log_level end |
#log_tag ⇒ Object
Returns the value of attribute log_tag.
92 93 94 |
# File 'lib/judoscale/config.rb', line 92 def log_tag @log_tag end |
#logger ⇒ Object
Returns the value of attribute logger.
92 93 94 |
# File 'lib/judoscale/config.rb', line 92 def logger @logger end |
#max_request_size_bytes ⇒ Object
Returns the value of attribute max_request_size_bytes.
92 93 94 |
# File 'lib/judoscale/config.rb', line 92 def max_request_size_bytes @max_request_size_bytes end |
#report_interval_seconds ⇒ Object
Returns the value of attribute report_interval_seconds.
92 93 94 |
# File 'lib/judoscale/config.rb', line 92 def report_interval_seconds @report_interval_seconds end |
Class Method Details
.coerce_log_level(level) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/judoscale/config.rb', line 78 def self.coerce_log_level(level) if level.is_a?(Integer) level else upcased_level = level.to_s.upcase if ::Logger::Severity.const_defined?(upcased_level) ::Logger::Severity.const_get(upcased_level) else raise ArgumentError, "invalid log level: #{level}" end end end |
.expose_adapter_config(config_instance) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/judoscale/config.rb', line 70 def self.expose_adapter_config(config_instance) adapter_configs << config_instance define_method(config_instance.identifier) do config_instance end end |
Instance Method Details
#as_json ⇒ Object
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/judoscale/config.rb', line 142 def as_json adapter_configs_json = self.class.adapter_configs.reduce({}) { |hash, config| hash.merge!(config.as_json) } { log_level: log_level, logger: logger.class.name, report_interval_seconds: report_interval_seconds, max_request_size_bytes: max_request_size_bytes }.merge!(adapter_configs_json) end |
#ignore_large_requests? ⇒ Boolean
153 154 155 |
# File 'lib/judoscale/config.rb', line 153 def ignore_large_requests? @max_request_size_bytes end |
#reset ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/judoscale/config.rb', line 100 def reset @api_base_url = ENV["JUDOSCALE_URL"] || ENV["RAILS_AUTOSCALE_URL"] @log_tag = "Judoscale" @max_request_size_bytes = 100_000 # ignore request payloads over 100k since they skew the queue times @report_interval_seconds = 10 self.log_level = ENV["JUDOSCALE_LOG_LEVEL"] || ENV["RAILS_AUTOSCALE_LOG_LEVEL"] @logger = ::Logger.new($stdout) self.class.adapter_configs.each(&:reset) @current_runtime_container = if ENV.include?("JUDOSCALE_CONTAINER") RuntimeContainer.new ENV["JUDOSCALE_CONTAINER"] elsif ENV.include?("DYNO") RuntimeContainer.new ENV["DYNO"] elsif ENV.include?("RENDER_INSTANCE_ID") # Deprecated API url using the service ID for legacy render services not using `JUDOSCALE_URL`. @api_base_url ||= "https://adapter.judoscale.com/api/#{ENV["RENDER_SERVICE_ID"]}" instance = ENV["RENDER_INSTANCE_ID"].delete_prefix("#{ENV["RENDER_SERVICE_ID"]}-") RuntimeContainer.new instance elsif ENV.include?("ECS_CONTAINER_METADATA_URI") instance = ENV["ECS_CONTAINER_METADATA_URI"].split("/").last RuntimeContainer.new instance elsif ENV.include?("FLY_MACHINE_ID") RuntimeContainer.new ENV["FLY_MACHINE_ID"] elsif ENV.include?("RAILWAY_REPLICA_ID") RuntimeContainer.new ENV["RAILWAY_REPLICA_ID"] elsif ENV.include?("CONTAINER") # Scalingo exposes the container type and index (e.g. "web-1") via CONTAINER. RuntimeContainer.new ENV["CONTAINER"] else # Unsupported platform... RuntimeContainer.new("") end end |