Skip to content

Commit

Permalink
Merge pull request #150 from cloudamatic/autoflailing
Browse files Browse the repository at this point in the history
Autoflailing
  • Loading branch information
ryantiger658 authored Feb 21, 2019
2 parents a223ede + 964c945 commit 9673c72
Show file tree
Hide file tree
Showing 10 changed files with 640 additions and 172 deletions.
8 changes: 4 additions & 4 deletions modules/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GEM
specs:
addressable (2.4.0)
ast (2.4.0)
aws-sdk-core (2.11.162)
aws-sdk-core (2.11.167)
aws-sigv4 (~> 1.0)
jmespath (~> 1.0)
aws-sigv4 (1.0.3)
Expand Down Expand Up @@ -96,7 +96,7 @@ GEM
coderay (1.1.2)
color (1.8)
colorize (0.8.1)
concurrent-ruby (1.0.5)
concurrent-ruby (1.1.3)
cucumber-core (4.0.0)
backports (>= 3.8.0)
cucumber-tag_expressions (~> 1.1.0)
Expand Down Expand Up @@ -250,10 +250,10 @@ GEM
polyglot (0.3.5)
powerpack (0.1.2)
proxifier (1.0.3)
pry (0.11.3)
pry (0.12.0)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rack (2.0.5)
rack (2.0.6)
rainbow (3.0.0)
rake (12.3.1)
representable (3.0.4)
Expand Down
46 changes: 46 additions & 0 deletions modules/mu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,52 @@ def self.mySSLDir;
@@mySSLDir
end

# Recursively compare two hashes. Intended to see when cloud API descriptions
# of existing resources differ from proposed changes so we know when to
# bother updating.
# @param hash1 [Hash]: The first hash
# @param hash2 [Hash]: The second hash
# @param missing_is_default [Boolean]: Assume that any element missing from hash2 but present in hash1 is a default value to be ignored
# @return [Boolean]
def self.hashCmp(hash1, hash2, missing_is_default: false)
return false if hash1.nil?
hash2.each_pair { |k, v|
if hash1[k].nil?
return false
end
}
if !missing_is_default
hash1.each_pair { |k, v|
if hash2[k].nil?
return false
end
}
end

hash1.each_pair { |k, v|
if hash1[k].is_a?(Array)
return false if !missing_is_default and hash2[k].nil?
if !hash2[k].nil?
hash2[k].each { |item|
if !hash1[k].include?(item)
return false
end
}
end
elsif hash1[k].is_a?(Hash) and !hash2[k].nil?
result = hashCmp(hash1[k], hash2[k], missing_is_default: missing_is_default)
return false if !result
else
if missing_is_default
return false if !hash2[k].nil? and hash1[k] != hash2[k]
else
return false if hash1[k] != hash2[k]
end
end
}
true
end

# Recursively turn a Ruby OpenStruct into a Hash
# @param struct [OpenStruct]
# @return [Hash]
Expand Down
2 changes: 1 addition & 1 deletion modules/mu/clouds/aws/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def create
Thread.new {
MU.dupGlobals(parent_thread_id)
MU::Cloud::AWS::Server.removeIAMProfile(@mu_name)
MU::Cloud::AWS::Server.cleanup(noop: false, ignoremaster: false, skipsnapshots: true)
MU::Cloud::AWS::Server.cleanup(noop: false, ignoremaster: false, skipsnapshots: true, region: @config['region'])
}
end
end
Expand Down
587 changes: 507 additions & 80 deletions modules/mu/clouds/aws/server_pool.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/mu/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ def adminFirewallRuleset(vpc: nil, admin_ip: nil, region: nil, cloud: nil)

acl = {"name" => name, "rules" => rules, "vpc" => realvpc, "cloud" => cloud, "admin" => true}
acl.delete("vpc") if !acl["vpc"]
acl["region"] == region if !region.nil? and !region.empty?
acl["region"] = region if !region.nil? and !region.empty?
@admin_firewall_rules << acl if !@admin_firewall_rules.include?(acl)
return {"type" => "firewall_rule", "name" => name}
end
Expand Down
1 change: 0 additions & 1 deletion modules/mu/config/alarm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def self.common_properties
"dimensions" => {
"type" => "array",
"description" => "What to monitor",
# "minItems" => 1,
"items" => {
"type" => "object",
"additionalProperties" => false,
Expand Down
84 changes: 0 additions & 84 deletions modules/mu/config/server_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,90 +69,6 @@ def self.schema
If you specify subnets and Availability Zones with this call, ensure that the subnets' Availability Zones match the Availability Zones specified."
},
"scaling_policies" => {
"type" => "array",
"minItems" => 1,
"items" => {
"type" => "object",
"required" => ["name", "type"],
"additionalProperties" => false,
"description" => "A custom AWS Autoscale scaling policy for this pool.",
"properties" => {
"name" => {
"type" => "string"
},
"alarms" => MU::Config::Alarm.inline,
"type" => {
"type" => "string",
"enum" => ["ChangeInCapacity", "ExactCapacity", "PercentChangeInCapacity"],
"description" => "Specifies whether 'adjustment' is an absolute number or a percentage of the current capacity. Valid values are ChangeInCapacity, ExactCapacity, and PercentChangeInCapacity."
},
"adjustment" => {
"type" => "integer",
"description" => "The number of instances by which to scale. 'type' determines the interpretation of this number (e.g., as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity. Used only when policy_type is set to 'SimpleScaling'"
},
"cooldown" => {
"type" => "integer",
"default" => 1,
"description" => "The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start."
},
"min_adjustment_magnitude" => {
"type" => "integer",
"description" => "Used when 'type' is set to 'PercentChangeInCapacity', the scaling policy changes the DesiredCapacity of the Auto Scaling group by at least the number of instances specified in the value."
},
"policy_type" => {
"type" => "string",
"enum" => ["SimpleScaling", "StepScaling"],
"description" => "'StepScaling' will add capacity based on the magnitude of the alarm breach, 'SimpleScaling' will add capacity based on the 'adjustment' value provided. Defaults to 'SimpleScaling'.",
"default" => "SimpleScaling"
},
"metric_aggregation_type" => {
"type" => "string",
"enum" => ["Minimum", "Maximum", "Average"],
"description" => "Defaults to 'Average' if not specified. Required when policy_type is set to 'StepScaling'",
"default" => "Average"
},
"step_adjustments" => {
"type" => "array",
"minItems" => 1,
"items" => {
"type" => "object",
"title" => "admin",
"description" => "Requires policy_type 'StepScaling'",
"required" => ["adjustment"],
"additionalProperties" => false,
"properties" => {
"adjustment" => {
"type" => "integer",
"description" => "The number of instances by which to scale at this specific step. Postive value when adding capacity, negative value when removing capacity"
},
"lower_bound" => {
"type" => "integer",
"description" => "The lower bound value in percentage points above/below the alarm threshold at which to add/remove capacity for this step. Positive value when adding capacity and negative when removing capacity. If this is the first step and capacity is being added this value will most likely be 0"
},
"upper_bound" => {
"type" => "integer",
"description" => "The upper bound value in percentage points above/below the alarm threshold at which to add/remove capacity for this step. Positive value when adding capacity and negative when removing capacity. If this is the first step and capacity is being removed this value will most likely be 0"
}
}
}
},
"estimated_instance_warmup" => {
"type" => "integer",
"description" => "Required when policy_type is set to 'StepScaling'"
}
}
}
},
"termination_policies" => {
"type" => "array",
"minItems" => 1,
"items" => {
"type" => "String",
"default" => "Default",
"enum" => ["Default", "OldestInstance", "NewestInstance", "OldestLaunchConfiguration", "ClosestToNextInstanceHour"]
}
},
#XXX this needs its own primitive and discovery mechanism
"zones" => {
"type" => "array",
Expand Down
71 changes: 71 additions & 0 deletions modules/mu/config/server_pool.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<% if $complexity == 'complex' %>
name: <%= server_pools_name %>
cloud: AWS
alarms:
- comparison_operator: "GreaterThanThreshold"
metric_name: "HTTPCode_Target_5XX_Count"
evaluation_periods: 1
name: "HTTP_Target_500_Count"
period: 60
statistic: "Sum"
threshold: 10
enable_notifications: true
notification_endpoint: '[email protected]'
namespace: "AWS/ApplicationELB"
scale_in_protection: "initial"
scale_with_cpu: 50.0
scaling_policies:
- name: simplediskreads
policy_type: SimpleScaling
adjustment: 1
cooldown: 60
type: ChangeInCapacity
alarms:
- name: simplenetwork
namespace: "AWS/EC2"
metric_name: DiskReadBytes
period: 60
evaluation_periods: 1
comparison_operator: GreaterThanThreshold
statistic: Sum
threshold: 1073741824
- name: trackingnetworkin
policy_type: TargetTrackingScaling
estimated_instance_warmup: 600
target_tracking_configuration:
target_value: 250.0
predefined_metric_specification: ASGAverageNetworkIn
termination_policies:
- "OldestInstance"
wait_for_nodes: 1
min_size: 2
max_size: 2
schedule:
- action_name: scale-down-over-night
recurrence: "30 6 * * *"
min_size: 1
max_size: 1
- action_name: scale-up-during-the-day
recurrence: "30 12 * * *"
min_size: 2
max_size: 2
ingress_rules:
- port: 80
hosts:
- 0.0.0.0/0
- port: 443
hosts:
- 0.0.0.0/0
basis:
launch_config:
name: <%= server_pools_name %>
size: t2.medium
<% else %>
name: <%= server_pools_name %>
min_size: 1
max_size: 1
basis:
launch_config:
name: <%= server_pools_name %>
size: t2.small
<% end %>
5 changes: 5 additions & 0 deletions modules/tests/super_complex_bok.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ parameters:
default: superBoK_logs
- name: queues_name
default: superBoK_queues
- name: server_pools_name
default: superBoK_ServerPool

<% $complexity = 'complex' %>

Expand All @@ -27,6 +29,9 @@ logs:
servers:
-
<%= include("../mu/config/server.yml") %>
server_pools:
-
<%= include("../mu/config/server_pool.yml") %>
search_domains:
-
<%= include("../mu/config/search_domain.yml") %>
Expand Down
6 changes: 5 additions & 1 deletion modules/tests/super_simple_bok.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ parameters:
default: superBoK_logs
- name: queues_name
default: superBoK_queues
- name: server_pools_name
default: superBoK_ServerPool

<% $complexity = 'complex' %>

Expand All @@ -27,10 +29,12 @@ logs:
servers:
-
<%= include("../mu/config/server.yml") %>
server_pools:
-
<%= include("../mu/config/server_pool.yml") %>
search_domains:
-
<%= include("../mu/config/search_domain.yml") %>

databases:
-
<%= include("../mu/config/database.yml") %>

0 comments on commit 9673c72

Please sign in to comment.