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

Feature/http check #156

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
bdd5cd5
Add HTTP check type
Oct 4, 2017
94bb8c6
Add register_http to access methods
Oct 4, 2017
37046f6
Fix travis errors where applicable
Oct 6, 2017
aa8bbb7
Updated README and Changelog
Oct 6, 2017
08b339f
Use `PUT` as the verb for deregistering a service. (#158)
blanquer Nov 11, 2017
78c8ab8
Suggest using X-Consul-Token for ACLs
sixfeetover Dec 28, 2017
575c866
Move ApiOptions methods into Restclient
Annih Mar 3, 2018
ec3be3a
Allow to pass ::Diplomat::Configuration object to the Rest Client
Annih Mar 3, 2018
243b9af
Specify StandardError on few rescue statements to make rubocop happy
Annih Mar 3, 2018
d6b2975
Support for tokens when registering/unregistering entities on Agent
pierresouchay Sep 6, 2018
70a71b0
Fixed rubocop warnings + Fixed rubocop version
pierresouchay Sep 6, 2018
0b70f62
Depreciate Ruby < 2.3 in travis tests
pierresouchay Sep 6, 2018
b320048
Merge pull request #166 from criteo-forks/token_on_registration_dereg…
pierresouchay Sep 6, 2018
d753006
Added new unit test for service registration with token
pierresouchay Sep 6, 2018
4f39bfb
New version 2.0.3 with token support for agent registration
pierresouchay Sep 6, 2018
28d41db
Merge pull request #163 from criteo-forks/non_static_configuration
pierresouchay Oct 17, 2018
a2b4180
Fixed minor rubocop style warnings after last PR #163
pierresouchay Oct 31, 2018
71c921b
README: Drop defunct badge, use SVG
olleolleolle Dec 15, 2018
985f4b8
CI: Update to current set of Rubies
olleolleolle Dec 15, 2018
621ae1c
Merge pull request #169 from olleolleolle/patch-1
pierresouchay Dec 19, 2018
9acebcb
Merge pull request #160 from sixfeetover/patch-1
pierresouchay Dec 19, 2018
19d9813
Travis: Exempt 2.6.0-rc2 from matrix
olleolleolle Dec 19, 2018
55b7db7
CI: Drop matrix allow_failures - 2.6.0-rc2 passes
olleolleolle Dec 19, 2018
6e1aa66
Merge pull request #170 from olleolleolle/patch-2
pierresouchay Dec 19, 2018
e327f81
Added automatic publication of GEM on a branch
pierresouchay Feb 25, 2019
13dacc0
Use bundle v2.0+
pierresouchay Feb 25, 2019
acd356e
Do not build with ruby 2.2.x in travis build
pierresouchay Feb 25, 2019
e67773f
Bump version to 2.0.4
pierresouchay Feb 25, 2019
688a6c9
Use correct verbs for Check methods.
pierresouchay Feb 25, 2019
e388ef0
Updated changelog
pierresouchay Feb 25, 2019
1617f67
Added new link to https://rubygems.org/gems/diplomat
pierresouchay Feb 25, 2019
f45b152
Use json_pure if ruby < 1.9.3 to avoid using a compiler
pierresouchay Feb 25, 2019
1fb4560
Updated CHANGELOG.md
pierresouchay Feb 25, 2019
9e90b93
Support for Output in TTL checks
kinnalru Feb 26, 2019
9f332f5
Merge pull request #178 from RnD-Soft/master
pierresouchay Feb 26, 2019
2412de1
Diplomat release 2.0.5 Bugfix release
pierresouchay Feb 26, 2019
95bee47
Updated travis versions of Ruby to use stable 2.6.1
pierresouchay Feb 26, 2019
3229669
simpler convert_to_hash function
Feb 11, 2019
ef57278
Merge pull request #176 from robmbrooks/master
pierresouchay Feb 27, 2019
0f80781
Updated changelog
pierresouchay Feb 27, 2019
35c369f
Enable configuration override on each consul api call
tionebsalocin Feb 27, 2019
ff4e2f8
Merge pull request #179 from tionebsalocin/options-everywhere
pierresouchay Mar 11, 2019
588eaf0
Adding support for KV flags during lock acquisition.
dudemcbacon Mar 6, 2019
830f1fe
Merge pull request #180 from dudemcbacon/master
pierresouchay Mar 13, 2019
0880966
Avoid having a HTTP 302 if key requested starts with '/' (#181)
pierresouchay Mar 15, 2019
f931728
Add some options example in the documentation
tionebsalocin Mar 15, 2019
bf5a26b
Changelog for release 2.1.0
pierresouchay Mar 18, 2019
5297bb9
fix syntax error colon instead of =>
Oribracha Mar 19, 2019
d415447
BUGFIX release 2.1.1, fixes #186 using #185
pierresouchay Mar 19, 2019
8458296
Bump version number to 2.1.1
pierresouchay Mar 19, 2019
fc22b27
Fix raw data usage in kv
tionebsalocin Mar 19, 2019
5f57ca9
BUGFIX release 2.1.2
pierresouchay Mar 19, 2019
34c045f
Add HTTP check type
Oct 4, 2017
6c3fc6b
register_http check name parameter is mandatory
Mar 20, 2019
a8df947
Merge branch 'feature/http-check' of https://github.com/lremes/diplom…
Mar 20, 2019
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.3

- 2017-10-06 Lars Remes [[email protected]][1] Support HTTP service checks

## 2.0.2

- 2017-08-23 Trevor Wood [[email protected]][1] Revert the change to single values
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ services = Diplomat::Service.get_all({ :dc => 'My_Datacenter' })
# => #<OpenStruct consul=[], foo=[], bar=[]>
```

#### Checks

Register a check:
```ruby
headers = { "Authorization" => [ "Basic ZGlwbG9tYXQ6cGFzc3dvcmQ=" ] }
Diplomat::Check.register_http('health-check-1', 'Health check', 'Node level HTTP health check', "http://#{addr}:#{port}/health_check", 'GET', headers, '10s')
```

### Datacenters

Getting a list of datacenters is quite simple and gives you the option to extract all services out of
Expand Down
24 changes: 22 additions & 2 deletions lib/diplomat/check.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Diplomat
# Methods for interacting with the Consul check API endpoint
class Check < Diplomat::RestClient
@access_methods = %i[checks register_script register_ttl
@access_methods = %i[checks register_http register_script register_ttl
deregister pass warn fail]

# Get registered checks
Expand All @@ -11,7 +11,27 @@ def checks
JSON.parse(ret.body)
end

# Register a check
# Register a HTTP check
# @param check_id [String] the unique id of the check
# @param name [String] the name
# @param notes [String] notes about the check
# @param script [String] command to be run for check
# @param interval [String] frequency (with units) of the check execution
# @param ttl [String] time (with units) to mark a check down
# @return [Integer] Status code
#
def register_http(check_id, name, notes, url, method, header, interval)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lots of parameters to this function, would you mind using named parameters instead ?

I would rather use this signature:

def register_http(url, interval, id: nil, id:name, notes: nil, method: 'GET', header: nil)
  [...]
end

since both interval and url are mandatory (see https://www.consul.io/api/agent/check.html#register-check )
It would allow to use only the provided parameters.

It also lacks header in ruby documentation as well as calling it headers would probably be more accurate (and specify type)

ret = @conn.put do |req|
req.url '/v1/agent/check/register'
req.body = JSON.generate(
'ID' => check_id, 'Name' => name, 'Notes' => notes, 'HTTP' => url, 'Method' => method,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timeout might be interesting as well

'Header' => header, 'Interval' => interval
)
end
ret.status == 200
end

# Register a script check
# @param check_id [String] the unique id of the check
# @param name [String] the name
# @param notes [String] notes about the check
Expand Down
6 changes: 6 additions & 0 deletions spec/check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
expect(check.register_script('foobar-1', 'Foobar', 'Foobar test', '/script/test', '10s')).to eq(true)
end

it 'register_http' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also test wrong value for parameters:

example:

curl -i --request PUT -d '{"ID":1, "http":"localhost:8500", "interval": "3x"}' http://localhost:8500/v1/agent/check/register
HTTP/1.1 400 Bad Request
Vary: Accept-Encoding
Date: Fri, 25 May 2018 06:52:59 GMT
Content-Length: 78
Content-Type: text/plain; charset=utf-8

faraday.stub(:put).and_return(OpenStruct.new(body: '', status: 200))
check = Diplomat::Check.new(faraday)
expect(check.register_http('foobar-1', 'Foobar', 'Foobar test', 'localhost', 'GET', {}, '10s')).to eq(true)
end

it 'register_ttl' do
faraday.stub(:put).and_return(OpenStruct.new(body: '', status: 200))
check = Diplomat::Check.new(faraday)
Expand Down