synapse 0.14.3 → 0.14.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/synapse/config_generator/README.md +9 -0
- data/lib/synapse/config_generator/file_output.rb +9 -1
- data/lib/synapse/config_generator/haproxy.rb +16 -2
- data/lib/synapse/service_watcher/base.rb +3 -1
- data/lib/synapse/version.rb +1 -1
- data/spec/lib/synapse/file_output_spec.rb +14 -0
- data/spec/lib/synapse/haproxy_spec.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4276b34a00e100441c2183b1ed89f743bb4b262
|
4
|
+
data.tar.gz: d746a4b04cf9295c66d1616968511f8d5bca3c49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ec01cc2150af99b69d5e438d1da515224cdce9926b978b6b09665269240daed1828501f75b93f0cd92852cf7f55227207b897ff7082b07e9437704f2de574ce
|
7
|
+
data.tar.gz: b9676bc3d4bb7a6647b8502c8edf7d2e02cba979e304a329ec3c99714a5de0f7f01ce00743364864848fa7a51f132f2da5a7bcb26432163b5324967a78ee629f
|
data/README.md
CHANGED
@@ -163,6 +163,7 @@ level as well, e.g.:
|
|
163
163
|
configuration for how to configure and interact with NGINX.
|
164
164
|
|
165
165
|
<a name="services"/>
|
166
|
+
|
166
167
|
### Configuring a Service ###
|
167
168
|
|
168
169
|
The `services` section is a hash, where the keys are the `name` of the service to be configured.
|
@@ -194,6 +195,7 @@ The services hash may contain the following additional keys:
|
|
194
195
|
* `backend_port_override`: the port that discovered servers listen on; you should specify this if your discovery mechanism only discovers names or addresses (like the DNS watcher or the Ec2TagWatcher). If the discovery method discovers a port along with hostnames (like the zookeeper watcher) this option may be left out, but will be used in preference if given.
|
195
196
|
|
196
197
|
<a name="discovery"/>
|
198
|
+
|
197
199
|
#### Service Discovery ####
|
198
200
|
|
199
201
|
We've included a number of `watchers` which provide service discovery.
|
@@ -292,6 +294,7 @@ It takes the following options:
|
|
292
294
|
* `port_index`: Index of the backend port in the task's "ports" array. (default: 0)
|
293
295
|
|
294
296
|
<a name="defaultservers"/>
|
297
|
+
|
295
298
|
#### Listing Default Servers ####
|
296
299
|
|
297
300
|
You may list a number of default servers providing a service.
|
@@ -312,6 +315,7 @@ disappear then the previous known backends will be used. Disable this behavior
|
|
312
315
|
by unsetting `use_previous_backends`.
|
313
316
|
|
314
317
|
<a name="haproxysvc"/>
|
318
|
+
|
315
319
|
#### The `haproxy` Section ####
|
316
320
|
|
317
321
|
This section is its own hash, which should contain the following keys:
|
@@ -343,6 +347,7 @@ listen on 127.0.0.3:443) allows /etc/hosts entries to point to services.
|
|
343
347
|
* `cookie_value_method`: optional: default value is `name`, it defines the way your backends receive a cookie value in http mode. If equal to `hash`, synapse hashes backend names on cookie value assignation of your discovered backends, useful when you want to use haproxy cookie feature but you do not want that your end users receive a Set-Cookie with your server name and ip readable in clear.
|
344
348
|
|
345
349
|
<a name="haproxy"/>
|
350
|
+
|
346
351
|
### Configuring HAProxy ###
|
347
352
|
|
348
353
|
The top level `haproxy` section of the config file has the following options:
|
@@ -376,6 +381,7 @@ Note that a non-default `bind_address` can be dangerous.
|
|
376
381
|
If you configure an `address:port` combination that is already in use on the system, haproxy will fail to start.
|
377
382
|
|
378
383
|
<a name="file"/>
|
384
|
+
|
379
385
|
### Configuring `file_output` ###
|
380
386
|
|
381
387
|
This section controls whether or not synapse will write out service state
|
@@ -476,18 +482,21 @@ please do contribute a [link](#plugins).
|
|
476
482
|
5. Create new Pull Request
|
477
483
|
|
478
484
|
<a name="createsw"/>
|
485
|
+
|
479
486
|
### Creating a Service Watcher ###
|
480
487
|
|
481
488
|
See the Service Watcher [README](lib/synapse/service_watcher/README.md) for
|
482
489
|
how to add new Service Watchers.
|
483
490
|
|
484
491
|
<a name="createconfig"/>
|
492
|
+
|
485
493
|
### Creating a Config Generator ###
|
486
494
|
|
487
495
|
See the Config Generator [README](lib/synapse/config_generator/README.md) for
|
488
496
|
how to add new Config Generators
|
489
497
|
|
490
498
|
<a name="plugins"/>
|
499
|
+
|
491
500
|
## Links to Synapse Plugins ##
|
492
501
|
* [`synapse-nginx`](https://github.com/jolynch/synapse-nginx) Is a `config_generator`
|
493
502
|
which allows Synapse to automatically configure and administer a local NGINX
|
@@ -7,6 +7,15 @@ when your generator has received an update from synapse via `update_config` it
|
|
7
7
|
should sync the watcher state with the external configuration (e.g. HAProxy
|
8
8
|
state)
|
9
9
|
|
10
|
+
Note that you have access to the following **read only** methods on the
|
11
|
+
watchers:
|
12
|
+
|
13
|
+
* `config_for_generator[name]` -> Hash: A method for retrieving the watcher config
|
14
|
+
relevant to this particular config watcher.
|
15
|
+
* `revision` -> int: A logical, monotonically increasing clock indicating which
|
16
|
+
revision of the watcher this is. You can use this to ignore config updates
|
17
|
+
from watchers that haven't changed
|
18
|
+
|
10
19
|
```ruby
|
11
20
|
require "synapse/config_generator/base"
|
12
21
|
|
@@ -21,6 +21,9 @@ class Synapse::ConfigGenerator
|
|
21
21
|
rescue SystemCallError => err
|
22
22
|
raise ArgumentError, "provided output directory #{opts['output_directory']} is not present or creatable"
|
23
23
|
end
|
24
|
+
|
25
|
+
# For tracking backends that we don't need to update
|
26
|
+
@watcher_revisions = {}
|
24
27
|
end
|
25
28
|
|
26
29
|
def tick(watchers)
|
@@ -28,7 +31,12 @@ class Synapse::ConfigGenerator
|
|
28
31
|
|
29
32
|
def update_config(watchers)
|
30
33
|
watchers.each do |watcher|
|
31
|
-
|
34
|
+
next if watcher.config_for_generator[name]['disabled']
|
35
|
+
|
36
|
+
unless @watcher_revisions[watcher.name] == watcher.revision
|
37
|
+
@watcher_revisions[watcher.name] = watcher.revision
|
38
|
+
write_backends_to_file(watcher.name, watcher.backends)
|
39
|
+
end
|
32
40
|
end
|
33
41
|
clean_old_watchers(watchers)
|
34
42
|
end
|
@@ -837,6 +837,11 @@ class Synapse::ConfigGenerator
|
|
837
837
|
# a place to store the parsed haproxy config from each watcher
|
838
838
|
@watcher_configs = {}
|
839
839
|
|
840
|
+
# a place to store generated frontend and backend stanzas
|
841
|
+
@frontends_cache = {}
|
842
|
+
@backends_cache = {}
|
843
|
+
@watcher_revisions = {}
|
844
|
+
|
840
845
|
@state_file_path = @opts['state_file_path']
|
841
846
|
@state_file_ttl = @opts.fetch('state_file_ttl', DEFAULT_STATE_FILE_TTL).to_i
|
842
847
|
end
|
@@ -897,8 +902,17 @@ class Synapse::ConfigGenerator
|
|
897
902
|
watcher_config = watcher.config_for_generator[name]
|
898
903
|
@watcher_configs[watcher.name] ||= parse_watcher_config(watcher)
|
899
904
|
next if watcher_config['disabled']
|
900
|
-
|
901
|
-
|
905
|
+
|
906
|
+
regenerate = watcher.revision != @watcher_revisions[watcher.name] ||
|
907
|
+
@frontends_cache[watcher.name].nil? ||
|
908
|
+
@backends_cache[watcher.name].nil?
|
909
|
+
if regenerate
|
910
|
+
@frontends_cache[watcher.name] = generate_frontend_stanza(watcher, @watcher_configs[watcher.name]['frontend'])
|
911
|
+
@backends_cache[watcher.name] = generate_backend_stanza(watcher, @watcher_configs[watcher.name]['backend'])
|
912
|
+
@watcher_revisions[watcher.name] = watcher.revision
|
913
|
+
end
|
914
|
+
new_config << @frontends_cache[watcher.name] << @backends_cache[watcher.name]
|
915
|
+
|
902
916
|
if watcher_config.include?('shared_frontend')
|
903
917
|
if opts['shared_frontend'] == nil
|
904
918
|
log.warn "synapse: service #{watcher.name} contains a shared frontend section but the base config does not! skipping."
|
@@ -7,12 +7,13 @@ class Synapse::ServiceWatcher
|
|
7
7
|
|
8
8
|
LEADER_WARN_INTERVAL = 30
|
9
9
|
|
10
|
-
attr_reader :name, :config_for_generator
|
10
|
+
attr_reader :name, :config_for_generator, :revision
|
11
11
|
|
12
12
|
def initialize(opts={}, synapse)
|
13
13
|
super()
|
14
14
|
|
15
15
|
@synapse = synapse
|
16
|
+
@revision = 0
|
16
17
|
|
17
18
|
# set required service parameters
|
18
19
|
%w{name discovery}.each do |req|
|
@@ -199,6 +200,7 @@ class Synapse::ServiceWatcher
|
|
199
200
|
# Subclasses should not invoke this directly; it's only exposed so that it
|
200
201
|
# can be overridden in subclasses.
|
201
202
|
def reconfigure!
|
203
|
+
@revision += 1
|
202
204
|
@synapse.reconfigure!
|
203
205
|
end
|
204
206
|
end
|
data/lib/synapse/version.rb
CHANGED
@@ -18,6 +18,10 @@ describe Synapse::ConfigGenerator::FileOutput do
|
|
18
18
|
allow(mockWatcher).to receive(:name).and_return('example_service')
|
19
19
|
backends = [{ 'host' => 'somehost', 'port' => 5555}]
|
20
20
|
allow(mockWatcher).to receive(:backends).and_return(backends)
|
21
|
+
allow(mockWatcher).to receive(:config_for_generator).and_return(
|
22
|
+
{'file_output' => {}}
|
23
|
+
)
|
24
|
+
allow(mockWatcher).to receive(:revision).and_return(0)
|
21
25
|
mockWatcher
|
22
26
|
end
|
23
27
|
let(:mockwatcher_2) do
|
@@ -25,6 +29,10 @@ describe Synapse::ConfigGenerator::FileOutput do
|
|
25
29
|
allow(mockWatcher).to receive(:name).and_return('foobar_service')
|
26
30
|
backends = [{ 'host' => 'somehost', 'port' => 1234}]
|
27
31
|
allow(mockWatcher).to receive(:backends).and_return(backends)
|
32
|
+
allow(mockWatcher).to receive(:config_for_generator).and_return(
|
33
|
+
{'file_output' => {}}
|
34
|
+
)
|
35
|
+
allow(mockWatcher).to receive(:revision).and_return(0)
|
28
36
|
mockWatcher
|
29
37
|
end
|
30
38
|
|
@@ -33,6 +41,12 @@ describe Synapse::ConfigGenerator::FileOutput do
|
|
33
41
|
subject.update_config([mockwatcher_1])
|
34
42
|
end
|
35
43
|
|
44
|
+
it 'ignores repeat configs' do
|
45
|
+
expect(subject).to receive(:write_backends_to_file).once
|
46
|
+
subject.update_config([mockwatcher_1])
|
47
|
+
subject.update_config([mockwatcher_1])
|
48
|
+
end
|
49
|
+
|
36
50
|
it 'manages correct files' do
|
37
51
|
subject.update_config([mockwatcher_1, mockwatcher_2])
|
38
52
|
FileUtils.cd(config['file_output']['output_directory']) do
|
@@ -14,6 +14,7 @@ describe Synapse::ConfigGenerator::Haproxy do
|
|
14
14
|
allow(mockWatcher).to receive(:config_for_generator).and_return({
|
15
15
|
'haproxy' => {'server_options' => "check inter 2000 rise 3 fall 2"}
|
16
16
|
})
|
17
|
+
allow(mockWatcher).to receive(:revision).and_return(1)
|
17
18
|
mockWatcher
|
18
19
|
end
|
19
20
|
|
@@ -86,6 +87,7 @@ describe Synapse::ConfigGenerator::Haproxy do
|
|
86
87
|
allow(mockWatcher).to receive(:config_for_generator).and_return({
|
87
88
|
'haproxy' => {'port' => 2200, 'disabled' => true}
|
88
89
|
})
|
90
|
+
allow(mockWatcher).to receive(:revision).and_return(1)
|
89
91
|
mockWatcher
|
90
92
|
end
|
91
93
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synapse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Rhoads
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-03
|
13
|
+
date: 2017-04-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws-sdk
|