-
Notifications
You must be signed in to change notification settings - Fork 251
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
Weights in generated config #131
base: master
Are you sure you want to change the base?
Changes from 2 commits
234a8b7
dccb0e8
f29c5e5
bc76050
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,6 +533,7 @@ 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 if @opts.key?('ignore_weights') and @opts['ignore_weights'] | ||
|
||
# how to restart haproxy | ||
@restart_interval = @opts.fetch('restart_interval', 2).to_i | ||
|
@@ -719,6 +720,7 @@ def generate_backend_stanza(watcher, config) | |
backend = backends[backend_name] | ||
b = "\tserver #{backend_name} #{backend['host']}:#{backend['port']}" | ||
b = "#{b} cookie #{backend_name}" unless config.include?('mode tcp') | ||
b = "#{b} weight #{backend['weight']}" if backend['weight'] && backend['weight'].is_a?(Fixnum) and backend['weight'] > 0 and !@opts['ignore_weights'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want to ignore 0 weight backends because that seems like a reasonable use case? (I believe that nerve supplies nil if there is no weight). What do you think? |
||
b = "#{b} #{watcher.haproxy['server_options']}" | ||
b = "#{b} disabled" unless backend['enabled'] | ||
b } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,18 @@ class MockWatcher; end; | |
describe Synapse::Haproxy do | ||
subject { Synapse::Haproxy.new(config['haproxy']) } | ||
|
||
let(:mockwatcher) do | ||
def createmockwatcher(backends) | ||
mockWatcher = double(Synapse::ServiceWatcher) | ||
allow(mockWatcher).to receive(:name).and_return('example_service') | ||
backends = [{ 'host' => 'somehost', 'port' => '5555'}] | ||
allow(mockWatcher).to receive(:backends).and_return(backends) | ||
allow(mockWatcher).to receive(:haproxy).and_return({'server_options' => "check inter 2000 rise 3 fall 2"}) | ||
mockWatcher | ||
end | ||
|
||
let(:mockwatcher) do | ||
createmockwatcher [{ 'host' => 'somehost', 'port' => '5555'}] | ||
end | ||
|
||
it 'updating the config' do | ||
expect(subject).to receive(:generate_config) | ||
subject.update_config([mockwatcher]) | ||
|
@@ -29,4 +32,14 @@ class MockWatcher; end; | |
expect(subject.generate_backend_stanza(mockwatcher, mockConfig)).to eql(["\nbackend example_service", ["\tmode tcp"], ["\tserver somehost:5555 somehost:5555 check inter 2000 rise 3 fall 2"]]) | ||
end | ||
|
||
it 'generates backend stanza with weight' do | ||
mockConfig = [] | ||
expect(subject.generate_backend_stanza(createmockwatcher([{ 'weight' => 1, 'host' => 'somehost', 'port' => '5555'}]), mockConfig)).to eql(["\nbackend example_service", [], ["\tserver somehost:5555 somehost:5555 cookie somehost:5555 weight 1 check inter 2000 rise 3 fall 2"]]) | ||
end | ||
|
||
it 'generates backend stanza withour bad weight' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor typo here. |
||
mockConfig = [] | ||
expect(subject.generate_backend_stanza(createmockwatcher([{ 'weight' => 'hi', 'host' => 'somehost', 'port' => '5555'}]), mockConfig)).to eql(["\nbackend example_service", [], ["\tserver somehost:5555 somehost:5555 cookie somehost:5555 check inter 2000 rise 3 fall 2"]]) | ||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mention what the default is?