Skip to content

Commit

Permalink
Replace the term service with resource for abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
hammady committed Feb 27, 2018
1 parent de8c790 commit 61ec6ab
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 6,5 @@
/pkg/
/spec/reports/
/tmp/
Gemfile.lock
Gemfile.lock
.env
10 changes: 5 additions & 5 deletions lib/scaltainer/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 45,14 @@ def save_state(statefile, state)
def iterate_services(services, stack_name, type, state)
begin
metrics = type.get_metrics services
@logger.debug "Retrieved metrics for #{type} services: #{metrics}"
@logger.debug "Retrieved metrics for #{type} resources: #{metrics}"
services.each do |service_name, service_config|
begin
state[service_name] ||= {}
service_state = state[service_name]
@logger.debug "Service #{service_name} in stack #{stack_name} currently has state: #{service_state}"
@logger.debug "Resource #{service_name} in stack #{stack_name} currently has state: #{service_state}"
service_config = @default_service_config.merge service_config
@logger.debug "Service #{service_name} in stack #{stack_name} configuration: #{service_config}"
@logger.debug "Resource #{service_name} in stack #{stack_name} configuration: #{service_config}"
process_service service_name, service_config, service_state, stack_name, type, metrics
rescue RuntimeError => e
# skipping service
Expand Down Expand Up @@ -91,9 91,9 @@ def get_service(service_name, stack_name)
begin
service = DockerService.new service_name, stack_name
rescue => e
raise NetworkError.new "Could not find object with name #{service_name} in stack #{stack_name}: #{e.message}"
raise NetworkError.new "Could not find resource with name #{service_name} in stack #{stack_name}: #{e.message}"
end
raise ConfigurationError.new "Unknown object: #{service_name} in stack #{stack_name}" unless service
raise ConfigurationError.new "Unknown resource: #{service_name} in stack #{stack_name}" unless service
service
end

Expand Down
14 changes: 7 additions & 7 deletions lib/scaltainer/service_types/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 6,12 @@ def initialize(app_endpoint)

def get_metrics(services)
services_count = services.keys.length rescue 0
raise Scaltainer::Warning.new "No services found for #{self.class.name}" if services_count == 0
raise Scaltainer::Warning.new "No resources found for #{self.class.name}" if services_count == 0
end

def determine_desired_replicas(metric, service_config, current_replicas)
raise ConfigurationError.new 'No metric found for requested service' unless metric
raise ConfigurationError.new 'No configuration found for requested service' unless service_config
raise ConfigurationError.new 'No metric found for requested resource' unless metric
raise ConfigurationError.new 'No configuration found for requested resource' unless service_config
end

def adjust_desired_replicas(desired_replicas, config)
Expand All @@ -32,7 32,7 @@ def yield_to_scale(replica_diff, config, state, metric, service_name, logger)
yield
state["upscale_sensitivity"] = 0
else
logger.debug "Scaling up of service #{service_name} blocked by upscale_sensitivity at level "
logger.debug "Scaling up of resource #{service_name} blocked by upscale_sensitivity at level "
"#{state["upscale_sensitivity"]} while level #{config["upscale_sensitivity"]} is required"
end
elsif replica_diff < 0 # TODO force down when above max?
Expand All @@ -45,17 45,17 @@ def yield_to_scale(replica_diff, config, state, metric, service_name, logger)
yield
state["downscale_sensitivity"] = 0
else
logger.debug "Scaling down of service #{service_name} blocked by downscale_sensitivity at level "
logger.debug "Scaling down of resource #{service_name} blocked by downscale_sensitivity at level "
"#{state["downscale_sensitivity"]} while level #{config["downscale_sensitivity"]} is required"
end
else
logger.debug "Scaling down of service #{service_name} to #{metric} replicas blocked by a non-decrementable config"
logger.debug "Scaling down of resource #{service_name} to #{metric} replicas blocked by a non-decrementable config"
end
else
# no breach, change state
state["upscale_sensitivity"] = 0
state["downscale_sensitivity"] = 0
logger.info "No need to scale service #{service_name}"
logger.info "No need to scale resource #{service_name}"
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/scaltainer/service_types/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,7 @@ def get_metrics(services)

services.reduce({}) do |hash, (service_name, service_config)|
app_id = service_config["newrelic_app_id"]
raise ConfigurationError.new "Service #{service_name} does not have a corresponding newrelic_app_id" unless app_id
raise ConfigurationError.new "Resource #{service_name} does not have a corresponding newrelic_app_id" unless app_id

begin
metric = nr.get_avg_response_time app_id, from, to
Expand All @@ -28,8 28,8 @@ def get_metrics(services)

def determine_desired_replicas(metric, service_config, current_replicas)
super
raise ConfigurationError.new "Missing max_response_time in web service configuration" unless service_config["max_response_time"]
raise ConfigurationError.new "Missing min_response_time in web service configuration" unless service_config["min_response_time"]
raise ConfigurationError.new "Missing max_response_time in web resource configuration" unless service_config["max_response_time"]
raise ConfigurationError.new "Missing min_response_time in web resource configuration" unless service_config["min_response_time"]
unless service_config["min_response_time"] <= service_config["max_response_time"]
raise ConfigurationError.new "min_response_time and max_response_time are not in order"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/scaltainer/service_types/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,7 @@ def get_metrics(services)

def determine_desired_replicas(metric, service_config, current_replicas)
super
raise ConfigurationError.new "Missing ratio in worker service configuration" unless service_config["ratio"]
raise ConfigurationError.new "Missing ratio in worker resource configuration" unless service_config["ratio"]
if !metric.is_a?(Integer) || metric < 0
raise ConfigurationError.new "#{metric} is an invalid metric value, must be a non-negative number"
end
Expand Down

0 comments on commit 61ec6ab

Please sign in to comment.