From bb732b68b517b10147f68ef3175611a03f5d77c4 Mon Sep 17 00:00:00 2001 From: Weiwei Shi Date: Tue, 7 Nov 2017 10:20:01 -0700 Subject: [PATCH] to use proxy for rollbar monitoring (#119) --- examples/pushmi_pullyu.yml | 6 ++++- lib/pushmi_pullyu.rb | 2 ++ lib/pushmi_pullyu/cli.rb | 18 ++++++++++--- pushmi_pullyu.gemspec | 2 +- spec/fixtures/config.yml | 5 +++- spec/pushmi_pullyu/cli_spec.rb | 25 +++++++++++++------ .../http_cache/vcr/swift_new_deposit.yml | 3 ++- 7 files changed, 46 insertions(+), 15 deletions(-) diff --git a/examples/pushmi_pullyu.yml b/examples/pushmi_pullyu.yml index c5c029b..eb26411 100644 --- a/examples/pushmi_pullyu.yml +++ b/examples/pushmi_pullyu.yml @@ -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 @@ -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' diff --git a/lib/pushmi_pullyu.rb b/lib/pushmi_pullyu.rb index 53b7305..52914c2 100644 --- a/lib/pushmi_pullyu.rb +++ b/lib/pushmi_pullyu.rb @@ -50,6 +50,8 @@ module PushmiPullyu project_name: 'demo', project_domain_name: 'default', container: 'ERA' + }, + rollbar: { } }.freeze diff --git a/lib/pushmi_pullyu/cli.rb b/lib/pushmi_pullyu/cli.rb index 7f826ec..47b0532 100644 --- a/lib/pushmi_pullyu/cli.rb +++ b/lib/pushmi_pullyu/cli.rb @@ -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 @@ -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| @@ -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 diff --git a/pushmi_pullyu.gemspec b/pushmi_pullyu.gemspec index 20c03bc..6a46e78 100644 --- a/pushmi_pullyu.gemspec +++ b/pushmi_pullyu.gemspec @@ -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' diff --git a/spec/fixtures/config.yml b/spec/fixtures/config.yml index 8b6f192..9021634 100644 --- a/spec/fixtures/config.yml +++ b/spec/fixtures/config.yml @@ -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 diff --git a/spec/pushmi_pullyu/cli_spec.rb b/spec/pushmi_pullyu/cli_spec.rb index df227d4..fee9134 100644 --- a/spec/pushmi_pullyu/cli_spec.rb +++ b/spec/pushmi_pullyu/cli_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/support/http_cache/vcr/swift_new_deposit.yml b/spec/support/http_cache/vcr/swift_new_deposit.yml index f1ded04..f0f012b 100644 --- a/spec/support/http_cache/vcr/swift_new_deposit.yml +++ b/spec/support/http_cache/vcr/swift_new_deposit.yml @@ -196,7 +196,8 @@ http_interactions: process_name: test_pushmi_pullyu minimum_age: 10 queue_name: test:pmpy_queue - rollbar_token: 'abc123xyz' + rollbar: + token: 'abc123xyz' redis: host: localhost