synapse 0.14.1 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f4b4d3c79352195ba849dcbe72ae849a65f355b
4
- data.tar.gz: 9270bec56704c96e37fc37862ee3bb3d4b2501a2
3
+ metadata.gz: 57e70e79531b09abe194f6aa92dfb616347cb241
4
+ data.tar.gz: 60192ea4643d87890dbf808125d624454a3214f6
5
5
  SHA512:
6
- metadata.gz: 7df9f4fec05f203f66d1b5113df94e35e08d3f3ce5864ae1ba543829640a752d1938e4f9b04530782f7897427b0bbd6e6e07bc88f1ec6f7b003783ba154ed565
7
- data.tar.gz: 2bde1c280db160799a9f52cfdedfdf28ce9060d78462a90538849984a9cffd60dad45d304562553bcc44453d440c81ada8c711e7edab97e9493bcf3594e87851
6
+ metadata.gz: 4d98b6414c0d26d6544c08ca7298c72df89919dac0e9ea565e3f7a85bb8b8ca562da3ba2c77a375105f40859938d0b801118a63dc49fb2ded97f26ff4cbc9171
7
+ data.tar.gz: 2740d9ef115e3d9551df141a4df4ca5d79e810ec2cdd2d0922fc55a2163f4f0d28eb842b691ce98a2337ffc071226a2d42c3fa135e92b49dbfeafbadf45d1b77
@@ -4,6 +4,7 @@ require 'fileutils'
4
4
  require 'json'
5
5
  require 'socket'
6
6
  require 'digest/sha1'
7
+ require 'set'
7
8
 
8
9
  class Synapse::ConfigGenerator
9
10
  class Haproxy < BaseGenerator
@@ -11,6 +12,8 @@ class Synapse::ConfigGenerator
11
12
 
12
13
  NAME = 'haproxy'.freeze
13
14
 
15
+ HAPROXY_CMD_BATCH_SIZE = 4
16
+
14
17
  # these come from the documentation for haproxy (1.5 and 1.6)
15
18
  # http://haproxy.1wt.eu/download/1.5/doc/configuration.txt
16
19
  # http://haproxy.1wt.eu/download/1.6/doc/configuration.txt
@@ -1102,20 +1105,23 @@ class Synapse::ConfigGenerator
1102
1105
 
1103
1106
  # parse the stats output to get current backends
1104
1107
  cur_backends = {}
1108
+ re = Regexp.new('^(.+?),(.+?),(?:.*?,){15}(.+?),')
1109
+
1105
1110
  info.split("\n").each do |line|
1106
1111
  next if line[0] == '#'
1107
1112
 
1108
- parts = line.split(',')
1109
- next if ['FRONTEND', 'BACKEND'].include?(parts[1])
1113
+ name, addr, state = re.match(line)[1..3]
1114
+
1115
+ next if ['FRONTEND', 'BACKEND'].include?(addr)
1110
1116
 
1111
- cur_backends[parts[0]] ||= []
1112
- cur_backends[parts[0]] << parts[1]
1117
+ cur_backends[name] ||= {}
1118
+ cur_backends[name][addr] = state
1113
1119
  end
1114
1120
 
1115
1121
  # build a list of backends that should be enabled
1116
1122
  enabled_backends = {}
1117
1123
  watchers.each do |watcher|
1118
- enabled_backends[watcher.name] = []
1124
+ enabled_backends[watcher.name] = Set.new
1119
1125
  next if watcher.backends.empty?
1120
1126
  next if watcher.config_for_generator[name]['disabled']
1121
1127
 
@@ -1136,28 +1142,36 @@ class Synapse::ConfigGenerator
1136
1142
  end
1137
1143
  end
1138
1144
 
1145
+ commands = []
1146
+
1139
1147
  # actually enable the enabled backends, and disable the disabled ones
1140
1148
  cur_backends.each do |section, backends|
1141
- backends.each do |backend|
1142
- if enabled_backends.fetch(section, []).include? backend
1143
- command = "enable server #{section}/#{backend}\n"
1149
+ backends.each do |backend, state|
1150
+ if enabled_backends.fetch(section, Set.new).include? backend
1151
+ next if state =~ /^UP/
1152
+ command = "enable server #{section}/#{backend}"
1144
1153
  else
1145
- command = "disable server #{section}/#{backend}\n"
1154
+ command = "disable server #{section}/#{backend}"
1146
1155
  end
1156
+ # Batch commands so that we don't need to re-open the connection
1157
+ # for every command.
1158
+ commands << command
1159
+ end
1160
+ end
1147
1161
 
1148
- # actually write the command to the socket
1149
- begin
1150
- output = talk_to_socket(socket_file_path, command)
1151
- rescue StandardError => e
1152
- log.warn "synapse: restart required because socket command #{command} failed with "\
1153
- "error #{e.inspect}"
1162
+ commands.each_slice(HAPROXY_CMD_BATCH_SIZE) do |batch|
1163
+ # actually write the command to the socket
1164
+ begin
1165
+ output = talk_to_socket(socket_file_path, batch.join(';') + "\n")
1166
+ rescue StandardError => e
1167
+ log.warn "synapse: restart required because socket command #{batch.join(';')} failed with "\
1168
+ "error #{e.inspect}"
1169
+ @restart_required = true
1170
+ else
1171
+ unless output == "\n" * batch.size
1172
+ log.warn "synapse: restart required because socket command #{batch.join(';')} failed with "\
1173
+ "output #{output}"
1154
1174
  @restart_required = true
1155
- else
1156
- unless output == "\n"
1157
- log.warn "synapse: restart required because socket command #{command} failed with "\
1158
- "output #{output}"
1159
- @restart_required = true
1160
- end
1161
1175
  end
1162
1176
  end
1163
1177
  end
@@ -1,3 +1,3 @@
1
1
  module Synapse
2
- VERSION = "0.14.1"
2
+ VERSION = "0.14.2"
3
3
  end
@@ -179,7 +179,7 @@ describe Synapse::ConfigGenerator::Haproxy do
179
179
  end
180
180
 
181
181
  it 'does not cause a restart due to the socket' do
182
- mock_socket_output = "example_service,somehost:5555"
182
+ mock_socket_output = "example_service,somehost:5555,0,0,0,0,200,0,0,0,0,0,,0,0,0,0,DOWN,0,"
183
183
  allow(subject).to receive(:talk_to_socket).with(socket_file_path, "show stat\n").and_return mock_socket_output
184
184
 
185
185
  expect(subject).to receive(:talk_to_socket).exactly(:once).with(
@@ -192,9 +192,9 @@ describe Synapse::ConfigGenerator::Haproxy do
192
192
  end
193
193
 
194
194
  it 'disables existing servers on the socket' do
195
- mock_socket_output = "example_service,somehost:5555\ndisabled_watcher,somehost:5555"
195
+ mock_socket_output = "example_service,somehost:5555,0,0,0,0,200,0,0,0,0,0,,0,0,0,0,DOWN,0,\ndisabled_watcher,somehost:5555,0,0,0,0,200,0,0,0,0,0,,0,0,0,0,UP,0,"
196
196
  allow(subject).to receive(:talk_to_socket).with(socket_file_path, "show stat\n").and_return mock_socket_output
197
-
197
+ stub_const('Synapse::ConfigGenerator::Haproxy::HAPROXY_CMD_BATCH_SIZE', 1)
198
198
 
199
199
  expect(subject).to receive(:talk_to_socket).exactly(:once).with(
200
200
  socket_file_path, "enable server example_service/somehost:5555\n"
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.1
4
+ version: 0.14.2
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-11 00:00:00.000000000 Z
13
+ date: 2017-03-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  version: '0'
246
246
  requirements: []
247
247
  rubyforge_project:
248
- rubygems_version: 2.2.2
248
+ rubygems_version: 2.4.5
249
249
  signing_key:
250
250
  specification_version: 4
251
251
  summary: Dynamic HAProxy configuration daemon