Skip to content
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

Add support for HTTP checks #143

Merged
merged 1 commit into from
Mar 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ the `consul::ui` recipe in your node's `run_list`.
notifies :reload, 'service[consul]'
end

##### Adding service with check
##### Adding services with checks

consul_service_def 'voice1' do
consul_service_def "voice1' do
port 5060
tags ['_sip._udp']
check(
Expand All @@ -431,6 +431,16 @@ the `consul::ui` recipe in your node's `run_list`.
notifies :reload, 'service[consul]'
end

consul_service_def 'server1' do
port 80
tags ['http']
check(
interval: '10s',
http: 'http://localhost:80'
)
notifies :reload, 'service[consul]'
end

##### Removing service

consul_service_def 'voice1' do
Expand Down
2 changes: 2 additions & 0 deletions resources/check_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
attribute :name, name_attribute: true, required: true, kind_of: String
attribute :id, kind_of: String
attribute :script, kind_of: String
attribute :http, kind_of: String
attribute :ttl, kind_of: String
attribute :interval, kind_of: String
attribute :notes, kind_of: String
Expand All @@ -48,6 +49,7 @@ def to_hash
hash[:check][:id] = id unless id.nil?
hash[:check][:script] = script unless script.nil?
hash[:check][:ttl] = ttl unless ttl.nil?
hash[:check][:http] = http unless http.nil?
hash[:check][:interval] = interval unless interval.nil?
hash[:check][:notes] = notes unless notes.nil?
hash
Expand Down
8 changes: 6 additions & 2 deletions resources/service_def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
attribute :port, kind_of: Integer
attribute :tags, kind_of: Array, default: nil
attribute :check, kind_of: Hash, default: nil, callbacks: {
'Checks must be a hash containing either a `:ttl` key/value or a `:script` and `:interval` key/value' => ->(check) do
'Checks must be a hash containing either a `:ttl` key/value or a `:script/:http` and `:interval` key/value' => ->(check) do
Chef::Resource::ConsulServiceDef.validate_check(check)
end
}
Expand All @@ -35,14 +35,18 @@ def self.validate_check(check)
return false
end

if check.key?(:ttl) && (!check.key?(:interval) && !check.key?(:script))
if check.key?(:ttl) && ( [:interval, :script, :http].none?{|key| check.key?(key)} )
return true
end

if check.key?(:interval) && check.key?(:script)
return true
end

if check.key?(:interval) && check.key?(:http)
return true
end

false
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
script "curl http://localhost:8888/health"
interval "10s"
ttl "50s"
http "http://localhost:8888/health"
notes "Blahblah"
end
9 changes: 7 additions & 2 deletions spec/unit/resources/check_def_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
end

it "register the check" do
['"name": "dummy name"', '"id": "uniqueid"', '"script": "curl http://localhost:8888/health"',
'"interval": "10s"', '"ttl": "50s"', '"notes": "Blahblah"'].each do |content|
['"name": "dummy name"',
'"id": "uniqueid"',
'"script": "curl http://localhost:8888/health"',
'"http": "http://localhost:8888/health"',
'"interval": "10s"',
'"ttl": "50s"',
'"notes": "Blahblah"'].each do |content|
expect(chef_run).to render_file(check_def_path)
.with_content(content)
end
Expand Down