nerve 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +16 -2
- data/Gemfile.lock +1 -1
- data/README.md +20 -8
- data/lib/nerve/reporter/base.rb +19 -6
- data/lib/nerve/service_watcher/http.rb +3 -1
- data/lib/nerve/version.rb +1 -1
- data/spec/example_services_spec.rb +5 -0
- data/spec/lib/nerve/reporter_spec.rb +14 -0
- metadata +25 -43
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 09be8c301fe459dcab4e5aa469f863ebb27c9f51
|
4
|
+
data.tar.gz: f458f7c7d2cbbd3e82f029d3a3488bcd5eff9088
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf15ca3c591c8bac19750d9c3e1ba96ef7af6096492dbd69f76c971563a22fb7948fa1322d11664b819e185f6d51b1e279ba54b08bba062433c6fb06b7b3be5b
|
7
|
+
data.tar.gz: b4b4b89e7eb356611b11aea64f9df687af5c1dc657864d791d799f7b80b2c7e63c16b7fccdc4e502593e03b7f42b6f6f425f2c67dddacaaa99bb0b4778ffd7cf
|
data/CONTRIBUTING.md
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
# Contributing Guidelines #
|
2
2
|
|
3
3
|
Thanks for contributing to SmartStack!
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
If you are opening a new PR, please ask for a merge into the `master` branch.
|
6
|
+
|
7
|
+
## Writing Reporters ##
|
8
|
+
Nerve supports *pluggable* reporters, which means that you can easily add
|
9
|
+
a reporter by making your own gem that contains your reporter available for
|
10
|
+
require at ``nerve/reporter/#{name.downcase}``. If you do this please do
|
11
|
+
submit a PR with a link to your gem/repo and we can reference it from the
|
12
|
+
README.
|
13
|
+
|
14
|
+
In general it is preferred to keep reporters that require specific dependencies
|
15
|
+
out of nerve because that way you can select the version of dependencies that
|
16
|
+
you need (for example if you have a particular version of the docker api or
|
17
|
+
etcd). That being said, if your reporter has no external dependencies
|
18
|
+
(e.g. files) or is extremely common (e.g. zookeeper, etcd), we may choose to
|
19
|
+
support it in the repo itself.
|
6
20
|
|
7
21
|
## Writing Checks ##
|
8
22
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -19,17 +19,27 @@ The information it reports can be used to take action from a centralized automat
|
|
19
19
|
|
20
20
|
## Installation ##
|
21
21
|
|
22
|
-
|
22
|
+
To download and run the nerve binary, first install a version of ruby. Then,
|
23
|
+
install nerve with:
|
23
24
|
|
24
|
-
|
25
|
+
```bash
|
26
|
+
$ mkdir -p /opt/smartstack/nerve
|
25
27
|
|
26
|
-
|
28
|
+
# If you want to install specific versions of dependencies such as an older
|
29
|
+
# version of the aws-sdk, the docker-api, etc, gem install that here *before*
|
30
|
+
# gem installing nerve. This is also where you would gem install
|
31
|
+
# custom reporters.
|
27
32
|
|
28
|
-
|
33
|
+
# If you are on Ruby 2.X use --no-document instead of --no-ri --no-rdoc
|
34
|
+
$ gem install nerve --install-dir /opt/smartstack/nerve --no-ri --no-rdoc
|
35
|
+
```
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
37
|
+
This will download nerve and its dependencies into /opt/smartstack/nerve. You
|
38
|
+
might wish to omit the `--install-dir` flag to use your system's default gem
|
39
|
+
path, however this will require you to run `gem install nerve` with root
|
40
|
+
permissions. You can also install via bundler, but keep in mind you'll pick up
|
41
|
+
Nerve's version of library dependencies and possibly not the ones you need
|
42
|
+
for your infra/apps.
|
33
43
|
|
34
44
|
## Configuration ##
|
35
45
|
|
@@ -54,7 +64,9 @@ The configuration contains the following options:
|
|
54
64
|
* `reporter_type`: the mechanism used to report up/down information; depending on the reporter you choose, additional parameters may be required. Defaults to `zookeeper`
|
55
65
|
* `check_interval`: the frequency with which service checks will be initiated; defaults to `500ms`
|
56
66
|
* `checks`: a list of checks that nerve will perform; if all of the pass, the service will be registered; otherwise, it will be un-registered
|
57
|
-
* `weight
|
67
|
+
* `weight` (optional): a positive integer weight value which can be used to affect the haproxy backend weighting in synapse.
|
68
|
+
* `haproxy_server_options` (optional): a string containing any special haproxy server options for this service instance. For example if you wanted to set a service instance as a backup.
|
69
|
+
* `labels` (optional): an object containing user-defined key-value pairs that describe this service instance. For example, you could label service instances with datacenter information.
|
58
70
|
|
59
71
|
#### Zookeeper Reporter ####
|
60
72
|
|
data/lib/nerve/reporter/base.rb
CHANGED
@@ -26,14 +26,27 @@ class Nerve::Reporter
|
|
26
26
|
%w{instance_id host port}.each do |required|
|
27
27
|
raise ArgumentError, "missing required argument #{required} for new service watcher" unless service[required]
|
28
28
|
end
|
29
|
-
d = {
|
30
|
-
|
29
|
+
d = {
|
30
|
+
'host' => service['host'],
|
31
|
+
'port' => service['port'],
|
32
|
+
'name' => service['instance_id']
|
33
|
+
}
|
31
34
|
|
32
35
|
# Weight is optional, but it should be well formed if supplied
|
33
|
-
if service
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
if service.has_key?('weight')
|
37
|
+
if service['weight'].to_i >= 0 and "#{service['weight']}".match /^\d+$/
|
38
|
+
d['weight'] = service['weight'].to_i
|
39
|
+
else
|
40
|
+
raise ArgumentError, "invalid 'weight' argument in service data: #{service.inspect}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if service.has_key?('haproxy_server_options')
|
45
|
+
d['haproxy_server_options'] = service['haproxy_server_options']
|
46
|
+
end
|
47
|
+
|
48
|
+
if service.has_key?('labels')
|
49
|
+
d['labels'] = service['labels']
|
37
50
|
end
|
38
51
|
d
|
39
52
|
end
|
@@ -36,7 +36,9 @@ module Nerve
|
|
36
36
|
code = response.code.to_i
|
37
37
|
body = response.body
|
38
38
|
|
39
|
-
|
39
|
+
# Any 2xx or 3xx code should be considered healthy. This is standard
|
40
|
+
# practice in HAProxy, nginx, etc ...
|
41
|
+
if code >= 200 and code < 400 and (@expect == nil || body.include?(@expect))
|
40
42
|
log.debug "nerve: check #{@name} got response code #{code} with body \"#{body}\""
|
41
43
|
return true
|
42
44
|
else
|
data/lib/nerve/version.rb
CHANGED
@@ -23,6 +23,11 @@ describe "example services are valid" do
|
|
23
23
|
it 'saves the weight data' do
|
24
24
|
expect(JSON.parse(Nerve::Reporter.new_from_service(service_data).data)['weight']).to eql(2)
|
25
25
|
end
|
26
|
+
it 'saves the labels data' do
|
27
|
+
labels = {'az' => 'us-west-1'}
|
28
|
+
service_data['labels'] = labels
|
29
|
+
expect(JSON.parse(Nerve::Reporter.new_from_service(service_data).data)['labels']).to eq(labels)
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
33
|
context "when #{item} can be initialized as a valid service watcher" do
|
@@ -67,6 +67,20 @@ describe Nerve::Reporter::Test do
|
|
67
67
|
it 'works if the weight is a string' do
|
68
68
|
expect(subject.get_service_data({'host' => '127.0.0.1', 'port' => 6666, 'instance_id' => 'foobar', 'weight' => '3'})['weight']).to eql(3)
|
69
69
|
end
|
70
|
+
|
71
|
+
it 'correctly passes haproxy_server_options' do
|
72
|
+
expect(subject.get_service_data({
|
73
|
+
'host' => '127.0.0.1', 'port' => 6666, 'instance_id' => 'foobar',
|
74
|
+
'haproxy_server_options' => 'backup'
|
75
|
+
})['haproxy_server_options']).to eql('backup')
|
76
|
+
end
|
77
|
+
it 'correctly passes labels' do
|
78
|
+
labels = {'az' => 'us-west-1', 'custom_key' => 'custom_value'}
|
79
|
+
expect(subject.get_service_data({
|
80
|
+
'host' => '127.0.0.1', 'port' => 6666, 'instance_id' => 'foobar',
|
81
|
+
'labels' => labels
|
82
|
+
})['labels']).to eql(labels)
|
83
|
+
end
|
70
84
|
end
|
71
85
|
end
|
72
86
|
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nerve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Martin Rhoads
|
@@ -11,44 +10,39 @@ authors:
|
|
11
10
|
autorequire:
|
12
11
|
bindir: bin
|
13
12
|
cert_chain: []
|
14
|
-
date:
|
13
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: json
|
18
17
|
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
18
|
requirements:
|
21
|
-
- -
|
19
|
+
- - ">="
|
22
20
|
- !ruby/object:Gem::Version
|
23
21
|
version: '0'
|
24
22
|
type: :runtime
|
25
23
|
prerelease: false
|
26
24
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
none: false
|
28
25
|
requirements:
|
29
|
-
- -
|
26
|
+
- - ">="
|
30
27
|
- !ruby/object:Gem::Version
|
31
28
|
version: '0'
|
32
29
|
- !ruby/object:Gem::Dependency
|
33
30
|
name: zk
|
34
31
|
requirement: !ruby/object:Gem::Requirement
|
35
|
-
none: false
|
36
32
|
requirements:
|
37
|
-
- - ~>
|
33
|
+
- - "~>"
|
38
34
|
- !ruby/object:Gem::Version
|
39
35
|
version: 1.9.2
|
40
36
|
type: :runtime
|
41
37
|
prerelease: false
|
42
38
|
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
none: false
|
44
39
|
requirements:
|
45
|
-
- - ~>
|
40
|
+
- - "~>"
|
46
41
|
- !ruby/object:Gem::Version
|
47
42
|
version: 1.9.2
|
48
43
|
- !ruby/object:Gem::Dependency
|
49
44
|
name: bunny
|
50
45
|
requirement: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
46
|
requirements:
|
53
47
|
- - '='
|
54
48
|
- !ruby/object:Gem::Version
|
@@ -56,7 +50,6 @@ dependencies:
|
|
56
50
|
type: :runtime
|
57
51
|
prerelease: false
|
58
52
|
version_requirements: !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
53
|
requirements:
|
61
54
|
- - '='
|
62
55
|
- !ruby/object:Gem::Version
|
@@ -64,81 +57,71 @@ dependencies:
|
|
64
57
|
- !ruby/object:Gem::Dependency
|
65
58
|
name: etcd
|
66
59
|
requirement: !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
60
|
requirements:
|
69
|
-
- - ~>
|
61
|
+
- - "~>"
|
70
62
|
- !ruby/object:Gem::Version
|
71
63
|
version: 0.2.3
|
72
64
|
type: :runtime
|
73
65
|
prerelease: false
|
74
66
|
version_requirements: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
67
|
requirements:
|
77
|
-
- - ~>
|
68
|
+
- - "~>"
|
78
69
|
- !ruby/object:Gem::Version
|
79
70
|
version: 0.2.3
|
80
71
|
- !ruby/object:Gem::Dependency
|
81
72
|
name: rake
|
82
73
|
requirement: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
74
|
requirements:
|
85
|
-
- -
|
75
|
+
- - ">="
|
86
76
|
- !ruby/object:Gem::Version
|
87
77
|
version: '0'
|
88
78
|
type: :development
|
89
79
|
prerelease: false
|
90
80
|
version_requirements: !ruby/object:Gem::Requirement
|
91
|
-
none: false
|
92
81
|
requirements:
|
93
|
-
- -
|
82
|
+
- - ">="
|
94
83
|
- !ruby/object:Gem::Version
|
95
84
|
version: '0'
|
96
85
|
- !ruby/object:Gem::Dependency
|
97
86
|
name: rspec
|
98
87
|
requirement: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
88
|
requirements:
|
101
|
-
- - ~>
|
89
|
+
- - "~>"
|
102
90
|
- !ruby/object:Gem::Version
|
103
91
|
version: 3.1.0
|
104
92
|
type: :development
|
105
93
|
prerelease: false
|
106
94
|
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
95
|
requirements:
|
109
|
-
- - ~>
|
96
|
+
- - "~>"
|
110
97
|
- !ruby/object:Gem::Version
|
111
98
|
version: 3.1.0
|
112
99
|
- !ruby/object:Gem::Dependency
|
113
100
|
name: factory_girl
|
114
101
|
requirement: !ruby/object:Gem::Requirement
|
115
|
-
none: false
|
116
102
|
requirements:
|
117
|
-
- -
|
103
|
+
- - ">="
|
118
104
|
- !ruby/object:Gem::Version
|
119
105
|
version: '0'
|
120
106
|
type: :development
|
121
107
|
prerelease: false
|
122
108
|
version_requirements: !ruby/object:Gem::Requirement
|
123
|
-
none: false
|
124
109
|
requirements:
|
125
|
-
- -
|
110
|
+
- - ">="
|
126
111
|
- !ruby/object:Gem::Version
|
127
112
|
version: '0'
|
128
113
|
- !ruby/object:Gem::Dependency
|
129
114
|
name: pry
|
130
115
|
requirement: !ruby/object:Gem::Requirement
|
131
|
-
none: false
|
132
116
|
requirements:
|
133
|
-
- -
|
117
|
+
- - ">="
|
134
118
|
- !ruby/object:Gem::Version
|
135
119
|
version: '0'
|
136
120
|
type: :development
|
137
121
|
prerelease: false
|
138
122
|
version_requirements: !ruby/object:Gem::Requirement
|
139
|
-
none: false
|
140
123
|
requirements:
|
141
|
-
- -
|
124
|
+
- - ">="
|
142
125
|
- !ruby/object:Gem::Version
|
143
126
|
version: '0'
|
144
127
|
description: Nerve is a service registration daemon. It performs health checks on
|
@@ -153,10 +136,10 @@ executables:
|
|
153
136
|
extensions: []
|
154
137
|
extra_rdoc_files: []
|
155
138
|
files:
|
156
|
-
- .gitignore
|
157
|
-
- .mailmap
|
158
|
-
- .nerve.rc
|
159
|
-
- .travis.yml
|
139
|
+
- ".gitignore"
|
140
|
+
- ".mailmap"
|
141
|
+
- ".nerve.rc"
|
142
|
+
- ".travis.yml"
|
160
143
|
- CONTRIBUTING.md
|
161
144
|
- Gemfile
|
162
145
|
- Gemfile.lock
|
@@ -194,27 +177,26 @@ files:
|
|
194
177
|
- spec/spec_helper.rb
|
195
178
|
homepage: https://github.com/airbnb/nerve
|
196
179
|
licenses: []
|
180
|
+
metadata: {}
|
197
181
|
post_install_message:
|
198
182
|
rdoc_options: []
|
199
183
|
require_paths:
|
200
184
|
- lib
|
201
185
|
required_ruby_version: !ruby/object:Gem::Requirement
|
202
|
-
none: false
|
203
186
|
requirements:
|
204
|
-
- -
|
187
|
+
- - ">="
|
205
188
|
- !ruby/object:Gem::Version
|
206
189
|
version: '0'
|
207
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
-
none: false
|
209
191
|
requirements:
|
210
|
-
- -
|
192
|
+
- - ">="
|
211
193
|
- !ruby/object:Gem::Version
|
212
194
|
version: '0'
|
213
195
|
requirements: []
|
214
196
|
rubyforge_project:
|
215
|
-
rubygems_version:
|
197
|
+
rubygems_version: 2.4.5
|
216
198
|
signing_key:
|
217
|
-
specification_version:
|
199
|
+
specification_version: 4
|
218
200
|
summary: A service registration daemon
|
219
201
|
test_files:
|
220
202
|
- spec/.gitkeep
|