Skip to content

Commit

Permalink
Add MIN_JITTER and MAX_JITTER variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramya Krishnan committed Jun 4, 2019
1 parent 355a9d3 commit 4647119
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
synapse (0.16.8)
synapse (0.16.9)
aws-sdk (~> 1.39)
docker-api (~> 1.7)
dogstatsd-ruby (~> 3.3.0)
Expand Down
4 changes: 3 additions & 1 deletion lib/synapse/service_watcher/zookeeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
class Synapse::ServiceWatcher
class ZookeeperWatcher < BaseWatcher
NUMBERS_RE = /^\d+$/
MIN_JITTER = 0
MAX_JITTER = 120

@@zk_pool = {}
@@zk_pool_count = {}
Expand Down Expand Up @@ -286,7 +288,7 @@ def watcher_callback
# This re-initializes callbacks just before get scan. So we do not miss any updates by sleeping.
#
if @watcher && @discovery['discovery_jitter']
if @discovery['discovery_jitter'] > 0 && @discovery['discovery_jitter'] < 120
if @discovery['discovery_jitter'].between?(MIN_JITTER, MAX_JITTER)
log.info "synapse: sleeping for discovery_jitter=#{@discovery['discovery_jitter']} seconds for service:#{@name}"
sleep @discovery['discovery_jitter']
else
Expand Down
2 changes: 1 addition & 1 deletion lib/synapse/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Synapse
VERSION = "0.16.8"
VERSION = "0.16.9"
end
9 changes: 9 additions & 0 deletions spec/lib/synapse/service_watcher_zookeeper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
subject.send(:watcher_callback).call
end

it 'do not throttle on invalid discovery_jitter' do
discovery['discovery_jitter'] = Synapse::ServiceWatcher::ZookeeperWatcher::MAX_JITTER + 1
expect(subject).to receive(:watch)
expect(subject).to receive(:discover)
expect(subject).not_to receive(:sleep)
subject.instance_variable_set(:@watcher, instance_double(ZK::EventHandlerSubscription))
subject.send(:watcher_callback).call
end

context "generator_config_path" do
let(:discovery) { { 'method' => 'zookeeper', 'hosts' => 'somehost', 'path' => 'some/path', 'generator_config_path' => generator_config_path } }
before :each do
Expand Down

0 comments on commit 4647119

Please sign in to comment.