Skip to content

Commit

Permalink
to use proxy for rollbar monitoring (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiweishi committed Nov 7, 2017
1 parent d3b3ac7 commit bb732b6
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
6 changes: 5 additions & 1 deletion examples/pushmi_pullyu.yml
Expand Up @@ -16,7 +16,6 @@ workdir: tmp/work
process_name: pushmi_pullyu
queue_name: dev:pmpy_queue
minimum_age: 0
rollbar_token: 'abc123xyz'

redis:
url: redis://localhost:6379
Expand All @@ -39,3 +38,8 @@ swift:
project_name: demo
project_domain_name: default
container: ERA

rollbar:
token: 'abc123xyz'
proxy_host: 'your_proxy_host_url'
proxy_port: '80'
2 changes: 2 additions & 0 deletions lib/pushmi_pullyu.rb
Expand Up @@ -50,6 +50,8 @@ module PushmiPullyu
project_name: 'demo',
project_domain_name: 'default',
container: 'ERA'
},
rollbar: {
}
}.freeze

Expand Down
18 changes: 14 additions & 4 deletions lib/pushmi_pullyu/cli.rb
Expand Up @@ -56,8 +56,15 @@ def start_server

def configure_rollbar
Rollbar.configure do |config|
config.enabled = false unless options[:rollbar_token].present?
config.access_token = options[:rollbar_token]
config.enabled = false unless options[:rollbar][:token].present?
config.access_token = options[:rollbar][:token]
if options[:rollbar][:proxy_host].present?
config.proxy = {}
config.proxy[:host] = options[:rollbar][:proxy_host]
config.proxy[:port] = options[:rollbar][:proxy_port] if options[:rollbar][:proxy_port].present?
config.proxy[:user] = options[:rollbar][:proxy_user] if options[:rollbar][:proxy_user].present?
config.proxy[:password] = options[:rollbar][:proxy_password] if options[:rollbar][:proxy_password].present?
end
end
end

Expand Down Expand Up @@ -93,7 +100,10 @@ def parse_options(argv)
end

o.on('-r', '--rollbar-token TOKEN', 'Enable error reporting to Rollbar') do |token|
opts[:rollbar_token] = token if token.present?
if token.present?
opts[:rollbar] = {}
opts[:rollbar][:token] = token
end
end

o.on '-C', '--config PATH', 'Path for YAML config file' do |config_file|
Expand Down Expand Up @@ -225,7 +235,7 @@ def shutdown
exit!(1)
else
# using stderr instead of logger as it uses an underlying mutex which is not allowed inside trap contexts.
$stderr.puts 'Exiting... Interrupt again to force quit.'
warn 'Exiting... Interrupt again to force quit.'
PushmiPullyu.server_running = false
end
end
Expand Down
2 changes: 1 addition & 1 deletion pushmi_pullyu.gemspec
Expand Up @@ -35,11 +35,11 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 1.14'
spec.add_development_dependency 'coveralls', '~> 0.8'
spec.add_development_dependency 'danger', '~> 5.2'
spec.add_development_dependency 'pry', '~> 0.10', '>= 0.10.4'
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop', '~> 0.45'
spec.add_development_dependency 'rubocop-rspec', '~> 1.10'
spec.add_development_dependency 'pry', '~> 0.10', '>= 0.10.4'
spec.add_development_dependency 'timecop', '~> 0.8'
spec.add_development_dependency 'vcr', '~> 3.0'
spec.add_development_dependency 'webmock', '~> 2.1'
Expand Down
5 changes: 4 additions & 1 deletion spec/fixtures/config.yml
Expand Up @@ -8,7 +8,10 @@ workdir: tmp/spec/work
process_name: test_pushmi_pullyu
minimum_age: 1
queue_name: test:pmpy_queue
rollbar_token: 'abc123xyz'
rollbar:
token: 'abc123xyz'
proxy_host: 'your_proxy_url'
proxy_port: '80'

solr:
url: http://www.example.com:8983/solr/development
Expand Down
25 changes: 18 additions & 7 deletions spec/pushmi_pullyu/cli_spec.rb
Expand Up @@ -30,12 +30,24 @@

context 'Rollbar' do
it 'sets up Rollbar' do
PushmiPullyu.options[:rollbar_token] = 'xyzzy'
PushmiPullyu.options[:rollbar][:token] = 'xyzzy'

cli.run

expect(Rollbar.configuration.access_token).to eq 'xyzzy'
end
it 'sets up Proxy for Rollbar' do
PushmiPullyu.options[:rollbar][:proxy_host] = 'your_proxy_host_url'
PushmiPullyu.options[:rollbar][:proxy_port] = '80'
PushmiPullyu.options[:rollbar][:proxy_user] = 'dummy_admin'
PushmiPullyu.options[:rollbar][:proxy_password] = 'securepassword'
cli.run

expect(Rollbar.configuration.proxy[:host]).to eq 'your_proxy_host_url'
expect(Rollbar.configuration.proxy[:port]).to eq '80'
expect(Rollbar.configuration.proxy[:user]).to eq 'dummy_admin'
expect(Rollbar.configuration.proxy[:password]).to eq 'securepassword'
end
end
end

Expand All @@ -62,16 +74,15 @@

it 'prints a message the first time and exits on second time' do
allow(cli).to receive(:exit!)
allow($stderr).to receive(:puts)
allow(cli).to receive(:warn)

expect { cli.send(:shutdown) }.to change { PushmiPullyu.server_running? }.from(true).to(false)

expect(cli).not_to have_received(:exit!)
expect($stderr).to have_received(:puts).with('Exiting... Interrupt again to force quit.').once
expect(cli).to have_received(:warn).with('Exiting... Interrupt again to force quit.').once

cli.send(:shutdown)

expect($stderr).to have_received(:puts).with('Exiting... Interrupt again to force quit.').once
expect(cli).to have_received(:warn).with('Exiting... Interrupt again to force quit.').once
expect(cli).to have_received(:exit!)
end
end
Expand Down Expand Up @@ -111,7 +122,7 @@

it 'sets up Rollbar integration' do
cli.parse(['-r', 'asdfjkl11234eieio'])
expect(PushmiPullyu.options[:rollbar_token]).to eq 'asdfjkl11234eieio'
expect(PushmiPullyu.options[:rollbar][:token]).to eq 'asdfjkl11234eieio'
end

it 'sets logdir' do
Expand Down Expand Up @@ -200,7 +211,7 @@
expect(PushmiPullyu.options[:minimum_age]).to be 1
expect(PushmiPullyu.options[:queue_name]).to eq 'test:pmpy_queue'
expect(PushmiPullyu.options[:swift][:auth_url]).to eq 'http://example.com:8080/auth/v1.0'
expect(PushmiPullyu.options[:rollbar_token]).to eq 'abc123xyz'
expect(PushmiPullyu.options[:rollbar][:token]).to eq 'abc123xyz'
end

it 'still allows command line arguments to take precedence' do
Expand Down
3 changes: 2 additions & 1 deletion spec/support/http_cache/vcr/swift_new_deposit.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb732b6

Please sign in to comment.