Skip to content

Commit

Permalink
Support cloudwatch_metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Genki Sugawara committed Feb 22, 2017
1 parent addd319 commit 53adf70
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ rrset "zzz.info.winebarrel.jp", "A" do
end
```

### Cloudwatch Metric Health Checks

```ruby
rrset "zzz.info.winebarrel.jp", "A" do
set_identifier "Secondary"
failover "SECONDARY"
health_check :cloudwatch_metric => {:region=>"ap-northeast-1", :name=>"MyCheck"}, :inverted => false, :insufficient_data_health_status => "LastKnownStatus"
ttl 456
resource_records(
"127.0.0.3",
"127.0.0.4"
)
end
```

### Dynamic private DNS example

```ruby
Expand Down
3 changes: 3 additions & 0 deletions lib/roadworker/dsl-converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def output_rrset(recrod)

if config[:calculated]
hc_args = ":calculated => #{config[:calculated].inspect}"
elsif config[:cloudwatch_metric]
hc_args = ":cloudwatch_metric => #{config[:cloudwatch_metric].inspect}"
else
hc_args = config[:url].sub(/\A(https?)_str_match:/) { $1 + ':' }.inspect
end
Expand All @@ -49,6 +51,7 @@ def output_rrset(recrod)
:measure_latency,
:inverted,
:enable_sni,
:insufficient_data_health_status,
].each do |key|
unless config[key].nil?
hc_args << ", :#{key} => #{config[key].inspect}"
Expand Down
15 changes: 14 additions & 1 deletion lib/roadworker/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ def health_check(url, options = {})
config[:type] = 'CALCULATED'
config[:child_health_checks] = url.delete(:calculated)
options = url
elsif url.include?(:cloudwatch_metric)
config = Aws::Route53::Types::HealthCheckConfig.new
config[:type] = 'CLOUDWATCH_METRIC'
config[:alarm_identifier] = url.delete(:cloudwatch_metric)
config[:child_health_checks] = []
options = url
else
raise ArgumentError, "wrong arguments: #{url.inspect}"
end
Expand All @@ -196,6 +202,7 @@ def health_check(url, options = {})
:inverted => :inverted,
:enable_sni => :enable_sni,
:regions => :regions,
:insufficient_data_health_status => :insufficient_data_health_status,
}.each do |option_key, config_key|
config[config_key] = options[option_key] unless options[option_key].nil?
end
Expand All @@ -206,7 +213,13 @@ def health_check(url, options = {})
config.type += '_STR_MATCH'
end

if config[:type] != 'CALCULATED'
case config[:type]
when 'CALCULATED'
# nothing to do
when 'CLOUDWATCH_METRIC'
config[:inverted] ||= false
config[:insufficient_data_health_status] ||= 'LastKnownStatus'
else
config[:request_interval] ||= 30
config[:failure_threshold] ||= 3
config[:measure_latency] ||= false
Expand Down
6 changes: 5 additions & 1 deletion lib/roadworker/route53-health-check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ def gc(route53, options = {})
def config_to_hash(config)
type = config[:type].downcase

if type == 'calculated'
case type
when 'calculated'
hash = {:calculated => config[:child_health_checks]}
when 'cloudwatch_metric'
hash = {:cloudwatch_metric => config[:alarm_identifier].to_h}
else
ipaddr = config[:ip_address]
port = config[:port]
Expand Down Expand Up @@ -45,6 +48,7 @@ def config_to_hash(config)
:measure_latency,
:inverted,
:enable_sni,
:insufficient_data_health_status,
].each do |key|
hash[key] = config[key] unless config[key].nil?
end
Expand Down
8 changes: 6 additions & 2 deletions lib/roadworker/route53-wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ def eql?(expected_record)
true
elsif expected and actual
case attribute
when :health_check
if actual[:alarm_identifier]
actual[:alarm_identifier] = actual[:alarm_identifier].to_h
end
when :dns_name
expected[0] = expected[0].downcase.sub(/\.\z/, '')
actual[0] = actual[0].downcase.sub(/\.\z/, '')
Expand Down Expand Up @@ -264,11 +268,11 @@ def update(expected_record)

# XXX: Fix for diff
if attribute == :health_check and actual
if actual[:child_health_checks].empty?
if (actual[:child_health_checks] || []).empty?
actual[:child_health_checks] = []
end

if actual[:regions].empty?
if (actual[:regions] || []).empty?
actual[:regions] = []
end
end
Expand Down

0 comments on commit 53adf70

Please sign in to comment.