Skip to content

Commit

Permalink
Remove option ignore_weights so weights will be used by default and c…
Browse files Browse the repository at this point in the history
…hange log level for duplicate weights.
  • Loading branch information
minkovich committed Feb 24, 2016
1 parent d5ea7b0 commit c3bcd29
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ This section is its own hash, which should contain the following keys:
* `listen`: these lines will be parsed and placed in the correct `frontend`/`backend` section as applicable; you can put lines which are the same for the frontend and backend here.
* `backend_order`: optional: how backends should be ordered in the `backend` stanza. (default is shuffling). Setting to `asc` means sorting backends in ascending alphabetical order before generating stanza. `desc` means descending alphabetical order. `no_shuffle` means no shuffling or sorting.
* `shared_frontend`: optional: haproxy configuration directives for a shared http frontend (see below)
* `ignore_weights`: optional: stops haproxy backend 'weight' options being generated, even if the Nerve registrations contain this information. This will cause all backend servers to be treated equally by haproxy. This defaults to true so weights will *NOT* be used by default.

<a name="haproxy"/>
### Configuring HAProxy ###
Expand Down
5 changes: 2 additions & 3 deletions lib/synapse/haproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ def initialize(opts)
@opts['do_writes'] = true unless @opts.key?('do_writes')
@opts['do_socket'] = true unless @opts.key?('do_socket')
@opts['do_reloads'] = true unless @opts.key?('do_reloads')
@opts['ignore_weights'] = true unless @opts.key?('ignore_weights')

# how to restart haproxy
@restart_interval = @opts.fetch('restart_interval', 2).to_i
Expand Down Expand Up @@ -743,10 +742,10 @@ def generate_backend_stanza(watcher, config)
b = "\tserver #{backend_name} #{backend['host']}:#{backend['port']}"
b = "#{b} cookie #{backend_name}" unless config.include?('mode tcp')
b = "#{b} #{watcher.haproxy['server_options']}" if watcher.haproxy['server_options']
if !@opts['ignore_weights'] && backend.has_key?('weight')
if backend.has_key?('weight')
# Check if server_options already contains weight, is so log a warning
if watcher.haproxy['server_options'].include? 'weight'
log.info "synapse: weight is defined by server_options and by nerve"
log.warn "synapse: weight is defined by server_options and by nerve"
end
weight = backend['weight'].to_i
b = "#{b} weight #{weight}"
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/synapse/service_watcher_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def remove_arg(name)
end
end

context 'with ignore_weights set to false' do
context 'with weights defined' do
let(:backends_with_weight) { [
{ 'name' => 'server1', 'host' => 'server1', 'port' => 1111, 'weight' => 11 },
{ 'name' => 'server2', 'host' => 'server2', 'port' => 2222, 'weight' => 22 },
Expand Down
1 change: 0 additions & 1 deletion spec/support/minimum.conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ haproxy:
config_file_path: "/etc/haproxy/haproxy.cfg"
do_writes: false
do_reloads: false
ignore_weights: false
global:
- global_test_option

Expand Down

0 comments on commit c3bcd29

Please sign in to comment.