routemaster-drain 3.6.5 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 574a92a97a0ae12a367d2aa0021852c9d721f8a542754eb6d038441cf411c38a
4
- data.tar.gz: 74fc0e9be7b142971eb6d800e4e77faf88a9a00303490dfb0f2405cd0174f1c6
3
+ metadata.gz: 91d53145809f5384fe911262c83306264381e1915ce6b6aef4a7de3299fd8eee
4
+ data.tar.gz: 2a7860c5a46d018aa7e10d82aad853066e5daf5851b6deba44e900985c7218c3
5
5
  SHA512:
6
- metadata.gz: 599155767c3d938d91c68e81e773b5940a35960fbf9c42ce802a8700c1a049391960afacbe1e4b22945ef199df19569a2627fd68e9bd899fa35d3ddaac78b5d6
7
- data.tar.gz: aabdfac82f389474c62856923bbcc87633a44aca389f3bb1ac8e120225f77946c36972d25b46e1ed7b8b40891d8c28f8fddffbfac7e26d72ea4e5a71ce0a9612
6
+ metadata.gz: 4119a30f7b34f48fcca01432718968523f71ebc9b298c78b6aa1d162c48108db631622ce94ec1859c5715642aa554f009b216cdf016b5391945722302a45ae42
7
+ data.tar.gz: fa0f8e231efdc36f2bf1f88e0a6a8f9cc14ae3b494761756317cc1924b8f8e505f2e6ca3651132a2e3e2bcddc313071b66523d4626308c324fa8722556ab6ebc
data/.circleci/config.yml CHANGED
@@ -3,161 +3,24 @@
3
3
 
4
4
  version: 2
5
5
  jobs:
6
-
7
- build_2.3.4_rails_3:
8
- docker:
9
- - image: deliveroo/multiruby
10
- - image: redis:3-alpine
11
- steps:
12
- - checkout
13
-
14
- - run:
15
- name: Select build variant (Ruby 2.3.4, rails_3)
16
- command: |
17
- rbenv local 2.3.4 ;
18
- gem install bundler -v '~> 1.17' ;
19
- bundle config --local gemfile $PWD/gemfiles/rails_3.gemfile
20
-
21
- - restore_cache:
22
- keys:
23
- - v2-bundle-2.3.4-rails_3-{{ .Branch }}
24
- - v2-bundle-2.3.4-rails_3
25
- - v2-bundle-2.3.4
26
-
27
- - run:
28
- name: Install dependencies
29
- command: |
30
- bundle install --jobs=3 --retry=3 --path=$PWD/vendor/bundle
31
-
32
- - run:
33
- name: Run test suite
34
- command: |
35
- unset RACK_ENV &&
36
- unset RAILS_ENV &&
37
- bundle exec rspec
38
-
39
- - save_cache:
40
- key: v2-bundle-2.3.4-rails_3-{{ .Branch }}
41
- paths:
42
- - ~/project/vendor/bundle
43
- - save_cache:
44
- key: v2-bundle-2.3.4-rails_3
45
- paths:
46
- - ~/project/vendor/bundle
47
- - save_cache:
48
- key: v2-bundle-2.3.4
49
- paths:
50
- - ~/project/vendor/bundle
51
-
52
- build_2.3.4_rails_4:
6
+ build_2.5_rails_5:
53
7
  docker:
54
- - image: deliveroo/multiruby
8
+ - image: circleci/ruby:2.4.1
55
9
  - image: redis:3-alpine
56
10
  steps:
57
11
  - checkout
58
12
 
59
13
  - run:
60
- name: Select build variant (Ruby 2.3.4, rails_4)
14
+ name: Install bundler
61
15
  command: |
62
- rbenv local 2.3.4 ;
63
- gem install bundler -v '~> 1.17' ;
64
- bundle config --local gemfile $PWD/gemfiles/rails_4.gemfile
65
-
66
- - restore_cache:
67
- keys:
68
- - v2-bundle-2.3.4-rails_4-{{ .Branch }}
69
- - v2-bundle-2.3.4-rails_4
70
- - v2-bundle-2.3.4
71
-
72
- - run:
73
- name: Install dependencies
74
- command: |
75
- bundle install --jobs=3 --retry=3 --path=$PWD/vendor/bundle
76
-
77
- - run:
78
- name: Run test suite
79
- command: |
80
- unset RACK_ENV &&
81
- unset RAILS_ENV &&
82
- bundle exec rspec
83
-
84
- - save_cache:
85
- key: v2-bundle-2.3.4-rails_4-{{ .Branch }}
86
- paths:
87
- - ~/project/vendor/bundle
88
- - save_cache:
89
- key: v2-bundle-2.3.4-rails_4
90
- paths:
91
- - ~/project/vendor/bundle
92
- - save_cache:
93
- key: v2-bundle-2.3.4
94
- paths:
95
- - ~/project/vendor/bundle
96
-
97
- build_2.4.1_rails_4:
98
- docker:
99
- - image: deliveroo/multiruby
100
- - image: redis:3-alpine
101
- steps:
102
- - checkout
103
-
104
- - run:
105
- name: Select build variant (Ruby 2.4.1, rails_4)
106
- command: |
107
- rbenv local 2.4.1 ;
108
- gem install bundler -v '~> 1.17' ;
109
- bundle config --local gemfile $PWD/gemfiles/rails_4.gemfile
110
-
111
- - restore_cache:
112
- keys:
113
- - v2-bundle-2.4.1-rails_4-{{ .Branch }}
114
- - v2-bundle-2.4.1-rails_4
115
- - v2-bundle-2.4.1
116
-
117
- - run:
118
- name: Install dependencies
119
- command: |
120
- bundle install --jobs=3 --retry=3 --path=$PWD/vendor/bundle
121
-
122
- - run:
123
- name: Run test suite
124
- command: |
125
- unset RACK_ENV &&
126
- unset RAILS_ENV &&
127
- bundle exec rspec
128
-
129
- - save_cache:
130
- key: v2-bundle-2.4.1-rails_4-{{ .Branch }}
131
- paths:
132
- - ~/project/vendor/bundle
133
- - save_cache:
134
- key: v2-bundle-2.4.1-rails_4
135
- paths:
136
- - ~/project/vendor/bundle
137
- - save_cache:
138
- key: v2-bundle-2.4.1
139
- paths:
140
- - ~/project/vendor/bundle
141
-
142
- build_2.3.4_rails_5:
143
- docker:
144
- - image: deliveroo/multiruby
145
- - image: redis:3-alpine
146
- steps:
147
- - checkout
148
-
149
- - run:
150
- name: Select build variant (Ruby 2.3.4, rails_5)
151
- command: |
152
- rbenv local 2.3.4 ;
153
16
  gem install bundler -v '~> 1.17' ;
154
17
  bundle config --local gemfile $PWD/gemfiles/rails_5.gemfile
155
18
 
156
19
  - restore_cache:
157
20
  keys:
158
- - v2-bundle-2.3.4-rails_5-{{ .Branch }}
159
- - v2-bundle-2.3.4-rails_5
160
- - v2-bundle-2.3.4
21
+ - v3-bundle-2.5.0-rails_5-{{ .Branch }}
22
+ - v3-bundle-2.5.0-rails_5
23
+ - v3-bundle-2.5.0
161
24
 
162
25
  - run:
163
26
  name: Install dependencies
@@ -172,37 +35,36 @@ jobs:
172
35
  bundle exec rspec
173
36
 
174
37
  - save_cache:
175
- key: v2-bundle-2.3.4-rails_5-{{ .Branch }}
38
+ key: v3-bundle-2.5.0-rails_5-{{ .Branch }}
176
39
  paths:
177
40
  - ~/project/vendor/bundle
178
41
  - save_cache:
179
- key: v2-bundle-2.3.4-rails_5
42
+ key: v3-bundle-2.5.0-rails_5
180
43
  paths:
181
44
  - ~/project/vendor/bundle
182
45
  - save_cache:
183
- key: v2-bundle-2.3.4
46
+ key: v3-bundle-2.5.0
184
47
  paths:
185
48
  - ~/project/vendor/bundle
186
49
 
187
- build_2.4.1_rails_5:
50
+ build_2.7_rails_6:
188
51
  docker:
189
- - image: deliveroo/multiruby
190
- - image: redis:3-alpine
52
+ - image: circleci/ruby:2.7.4
53
+ - image: redis:6-alpine
191
54
  steps:
192
55
  - checkout
193
56
 
194
57
  - run:
195
- name: Select build variant (Ruby 2.4.1, rails_5)
58
+ name: Install bundler
196
59
  command: |
197
- rbenv local 2.4.1 ;
198
- gem install bundler -v '~> 1.17' ;
199
- bundle config --local gemfile $PWD/gemfiles/rails_5.gemfile
60
+ gem install bundler -v '~> 2' ;
61
+ bundle config --local gemfile $PWD/gemfiles/rails_6.gemfile
200
62
 
201
63
  - restore_cache:
202
64
  keys:
203
- - v2-bundle-2.4.1-rails_5-{{ .Branch }}
204
- - v2-bundle-2.4.1-rails_5
205
- - v2-bundle-2.4.1
65
+ - bundle-2.7.4-rails_6-{{ .Branch }}
66
+ - bundle-2.7.4-rails_6
67
+ - bundle-2.7.4
206
68
 
207
69
  - run:
208
70
  name: Install dependencies
@@ -217,31 +79,21 @@ jobs:
217
79
  bundle exec rspec
218
80
 
219
81
  - save_cache:
220
- key: v2-bundle-2.4.1-rails_5-{{ .Branch }}
82
+ key: bundle-2.7.4-rails_6-{{ .Branch }}
221
83
  paths:
222
84
  - ~/project/vendor/bundle
223
85
  - save_cache:
224
- key: v2-bundle-2.4.1-rails_5
86
+ key: bundle-2.7.4-rails_6
225
87
  paths:
226
88
  - ~/project/vendor/bundle
227
89
  - save_cache:
228
- key: v2-bundle-2.4.1
90
+ key: bundle-2.7.4
229
91
  paths:
230
92
  - ~/project/vendor/bundle
231
93
 
232
-
233
94
  workflows:
234
95
  version: 2
235
96
  test:
236
97
  jobs:
237
-
238
- - build_2.3.4_rails_3
239
-
240
- - build_2.3.4_rails_4
241
-
242
- - build_2.4.1_rails_4
243
-
244
- - build_2.3.4_rails_5
245
-
246
- - build_2.4.1_rails_5
247
-
98
+ - build_2.5_rails_5
99
+ - build_2.7_rails_6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  _A description of your awesome changes here!_
4
4
 
5
+ ### 3.7.0
6
+
7
+ Features:
8
+
9
+ - Adds circuit breaker to PATCH PUT POST requests (#66)
10
+
11
+ ### 3.6.8
12
+
13
+ Features:
14
+
15
+ - Raises error on `502 Bad Gateway` [#94](https://github.com/deliveroo/routemaster-drain/pull/94)
16
+
17
+ ### 3.6.7 (2021-02-11)
18
+
19
+ Features:
20
+
21
+ - APIClient accepts timeout and open_timeout options
22
+
5
23
  ### 3.6.5 (2019-02-08)
6
24
 
7
25
  Bug fix:
@@ -0,0 +1,24 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "psych", :require => false
6
+ gem "bundler", :require => false
7
+ gem "rake", :require => false
8
+ gem "webmock", :require => false
9
+ gem "rack-test", :require => false
10
+ gem "dotenv", :require => false
11
+ gem "simplecov", :require => false
12
+ gem "codecov", :require => false
13
+ gem "resque", :require => false
14
+ gem "sidekiq", :require => false
15
+ gem "guard-rspec", :require => false
16
+ gem "pry", :require => false
17
+ gem "byebug", :require => false
18
+ gem "rspec", :require => false
19
+ gem "appraisal", :require => false
20
+ gem "dogstatsd", :require => false
21
+ gem "fork_break", :require => false
22
+ gem "rails", "~> 6.0"
23
+
24
+ gemspec :path => "../"
@@ -45,6 +45,8 @@ module Routemaster
45
45
  @retry_attempts = options.fetch :retry_attempts, 2
46
46
  @retry_methods = options.fetch :retry_methods, Faraday::Request::Retry::IDEMPOTENT_METHODS
47
47
  @retry_exceptions = options.fetch :retry_exceptions, Faraday::Request::Retry::Options.new.exceptions
48
+ @timeout = options.fetch :timeout, nil
49
+ @open_timeout = options.fetch :open_timeout, nil
48
50
 
49
51
  connection # warm up connection so Faraday does all it's magical file loading in the main thread
50
52
  end
@@ -97,11 +99,13 @@ module Routemaster
97
99
  private
98
100
 
99
101
  def patch_post_or_put(type, url, body, headers)
100
- _wrapped_response _request(
101
- type,
102
- url: url,
103
- body: body,
104
- headers: headers)
102
+ APIClientCircuit.new(url).call do
103
+ _wrapped_response _request(
104
+ type,
105
+ url: url,
106
+ body: body,
107
+ headers: headers)
108
+ end
105
109
  end
106
110
 
107
111
  def _assert_uri(url)
@@ -147,8 +151,8 @@ module Routemaster
147
151
 
148
152
  f.adapter :typhoeus
149
153
 
150
- f.options.timeout = ENV.fetch('ROUTEMASTER_CACHE_TIMEOUT', 1).to_f
151
- f.options.open_timeout = ENV.fetch('ROUTEMASTER_CACHE_TIMEOUT', 1).to_f
154
+ f.options.timeout = (@timeout || ENV.fetch('ROUTEMASTER_CACHE_TIMEOUT', 1)).to_f
155
+ f.options.open_timeout = (@open_timeout || ENV.fetch('ROUTEMASTER_CACHE_TIMEOUT', 1)).to_f
152
156
  f.ssl.verify = ENV.fetch('ROUTEMASTER_CACHE_VERIFY_SSL', 'false') == 'true'
153
157
  end
154
158
  end
@@ -31,7 +31,7 @@ module Routemaster
31
31
  time_window: configuration_setting(@circuit_name, 'ROUTEMASTER_CIRCUIT_BREAKER_TIME_WINDOW', 120).to_i,
32
32
  volume_threshold: configuration_setting(@circuit_name, 'ROUTEMASTER_CIRCUIT_BREAKER_VOLUME_THRESHOLD', 50).to_i,
33
33
  error_threshold: configuration_setting(@circuit_name, 'ROUTEMASTER_CIRCUIT_BREAKER_ERROR_THRESHOLD', 50).to_i,
34
- cache: Moneta.new(:Redis, backend: Config.cache_redis),
34
+ cache: Moneta::Adapters::Redis.new(backend: Config.cache_redis),
35
35
  exceptions: [Routemaster::Errors::FatalResource, Faraday::TimeoutError]
36
36
  })
37
37
  end
@@ -1,5 +1,5 @@
1
1
  module Routemaster
2
2
  module Drain
3
- VERSION = '3.6.5'.freeze
3
+ VERSION = '3.7.0'.freeze
4
4
  end
5
5
  end
@@ -82,6 +82,12 @@ module Routemaster
82
82
  end
83
83
  end
84
84
 
85
+ class BadGateway < BaseError
86
+ def message
87
+ "Bad Gateway"
88
+ end
89
+ end
90
+
85
91
  class ServiceNotAvailable < BaseError
86
92
  def message
87
93
  "Service Not Available"
@@ -16,6 +16,7 @@ module Routemaster
16
16
  (413..413) => Errors::InvalidResource,
17
17
  (429..429) => Errors::ResourceThrottling,
18
18
  (407..500) => Errors::FatalResource,
19
+ (502..502) => Errors::BadGateway,
19
20
  (503..503) => Errors::ServiceNotAvailable
20
21
  }.freeze
21
22
 
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency 'redis-namespace'
27
27
  spec.add_runtime_dependency 'concurrent-ruby'
28
28
  spec.add_runtime_dependency 'circuitbox'
29
+ spec.add_runtime_dependency 'moneta', '1.0.0'
29
30
  end
@@ -1,17 +1,19 @@
1
1
  require 'core_ext/forwardable'
2
2
 
3
- describe Forwardable do
4
- class Foo
5
- extend Forwardable
3
+ if RUBY_VERSION == '2.4.0'
4
+ describe Forwardable do
5
+ class Foo
6
+ extend Forwardable
6
7
 
7
- def initialize
8
- @bar = :bar
9
- end
8
+ def initialize
9
+ @bar = :bar
10
+ end
10
11
 
11
- def_delegator :@bar, :to_s, :qux
12
- end
12
+ def_delegator :@bar, :to_s, :qux
13
+ end
13
14
 
14
- it 'expect delegation to work' do
15
- expect(Foo.new.qux).to eq 'bar'
15
+ it 'expect delegation to work' do
16
+ expect(Foo.new.qux).to eq 'bar'
17
+ end
16
18
  end
17
19
  end
@@ -12,7 +12,10 @@ describe Routemaster::APIClientCircuit do
12
12
  context "when enabled" do
13
13
  before do
14
14
  sb_req
15
- allow_any_instance_of(described_class).to receive(:enabled?){ true }
15
+ allow(ENV).to receive(:fetch).and_call_original
16
+ allow(ENV)
17
+ .to receive(:fetch)
18
+ .with('ROUTEMASTER_ENABLE_API_CLIENT_CIRCUIT', 'NO').and_return('YES')
16
19
  end
17
20
 
18
21
  let(:url){ 'http://example.com/foobar' }
@@ -109,10 +109,38 @@ describe Routemaster::APIClient do
109
109
  end
110
110
  end
111
111
 
112
+ shared_examples 'a circuit breaker wrapped request' do
113
+ let(:fetcher) { described_class.new(retry_attempts: 0) }
114
+ let(:url) { 'https://circuit.example.com/circuit/132' }
115
+ let(:method) { :get }
116
+
117
+ before do
118
+ allow(ENV).to receive(:fetch).and_call_original
119
+ allow(ENV)
120
+ .to receive(:fetch)
121
+ .with('ROUTEMASTER_ENABLE_API_CLIENT_CIRCUIT', 'NO').and_return('YES')
122
+ allow(ENV)
123
+ .to receive(:fetch)
124
+ .with('ROUTEMASTER_CIRCUIT_BREAKER_ERROR_THRESHOLD', 50).and_return('1')
125
+ allow(ENV)
126
+ .to receive(:fetch)
127
+ .with('ROUTEMASTER_CIRCUIT_BREAKER_VOLUME_THRESHOLD', 50).and_return('1')
128
+
129
+ stub_request(method, url).to_timeout
130
+ end
131
+
132
+ it 'trips after the second request' do
133
+ 5.times { expect { subject }.to raise_error StandardError }
134
+ expect(a_request(method, url)).to have_been_made.at_most_times(2)
135
+ end
136
+ end
137
+
112
138
  describe '#get' do
113
139
  subject { fetcher.get(url, headers: headers) }
140
+
114
141
  it_behaves_like 'a GET requester'
115
142
  it_behaves_like 'a wrappable response'
143
+ it_behaves_like 'a circuit breaker wrapped request'
116
144
  end
117
145
 
118
146
  describe '#fget' do
@@ -183,6 +211,9 @@ describe Routemaster::APIClient do
183
211
  end
184
212
 
185
213
  it_behaves_like 'a wrappable response'
214
+ it_behaves_like 'a circuit breaker wrapped request' do
215
+ let(:method) { :post }
216
+ end
186
217
  end
187
218
 
188
219
  describe '#put' do
@@ -206,6 +237,9 @@ describe Routemaster::APIClient do
206
237
  end
207
238
 
208
239
  it_behaves_like 'a wrappable response'
240
+ it_behaves_like 'a circuit breaker wrapped request' do
241
+ let(:method) { :put }
242
+ end
209
243
  end
210
244
 
211
245
  context 'when request times out' do
@@ -282,6 +316,9 @@ describe Routemaster::APIClient do
282
316
  end
283
317
 
284
318
  it_behaves_like 'a wrappable response'
319
+ it_behaves_like 'a circuit breaker wrapped request' do
320
+ let(:method) { :patch }
321
+ end
285
322
  end
286
323
 
287
324
  context 'when request times out' do
@@ -21,7 +21,7 @@ describe Routemaster::APIClient do
21
21
  let(:port) { 8080 }
22
22
  let(:service) do
23
23
  TestServer.new(port) do |server|
24
- [400, 401, 403, 404, 405, 409, 412, 413, 429, 500, 503].each do |status_code|
24
+ [400, 401, 403, 404, 405, 409, 412, 413, 429, 500, 502, 503].each do |status_code|
25
25
  server.mount_proc "/#{status_code}" do |req, res|
26
26
  res.status = status_code
27
27
  res.body = { field: 'test' }.to_json
@@ -163,6 +163,10 @@ describe Routemaster::APIClient do
163
163
  expect { perform.(host + '/500') }.to raise_error(Routemaster::Errors::FatalResource)
164
164
  end
165
165
 
166
+ it 'raises a BadGateway on 502' do
167
+ expect { perform.(host + '/502') }.to raise_error(Routemaster::Errors::BadGateway)
168
+ end
169
+
166
170
  it 'raises a ServiceNotAvailable on 503' do
167
171
  expect { perform.(host + '/503') }.to raise_error(Routemaster::Errors::ServiceNotAvailable)
168
172
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routemaster-drain
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.5
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Letessier
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-08 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -150,7 +150,21 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
- description:
153
+ - !ruby/object:Gem::Dependency
154
+ name: moneta
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 1.0.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 1.0.0
167
+ description:
154
168
  email:
155
169
  - julien.letessier@gmail.com
156
170
  executables: []
@@ -179,6 +193,7 @@ files:
179
193
  - gemfiles/rails_3.gemfile
180
194
  - gemfiles/rails_4.gemfile
181
195
  - gemfiles/rails_5.gemfile
196
+ - gemfiles/rails_6.gemfile
182
197
  - lib/core_ext/forwardable.rb
183
198
  - lib/routemaster/api_client.rb
184
199
  - lib/routemaster/api_client_circuit.rb
@@ -271,7 +286,7 @@ homepage: http://github.com/deliveroo/routemaster-drain
271
286
  licenses:
272
287
  - MIT
273
288
  metadata: {}
274
- post_install_message:
289
+ post_install_message:
275
290
  rdoc_options: []
276
291
  require_paths:
277
292
  - lib
@@ -286,8 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
301
  - !ruby/object:Gem::Version
287
302
  version: '0'
288
303
  requirements: []
289
- rubygems_version: 3.0.1
290
- signing_key:
304
+ rubygems_version: 3.0.9
305
+ signing_key:
291
306
  specification_version: 4
292
307
  summary: Event receiver for the Routemaster bus
293
308
  test_files: