routemaster-drain 3.6.1 → 3.6.6

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
- SHA1:
3
- metadata.gz: 1961fe701af902402b83e7eaa4a76fb54bf06f93
4
- data.tar.gz: ae8913a88b7f1da4379ee03f0900ec0e5b896f65
2
+ SHA256:
3
+ metadata.gz: 95bdc05150729150c9abb45ca3d66689a3669b43e0cedf3621ea5d8dcac9c5f2
4
+ data.tar.gz: cad717d62652b35fc06de4713ef50fccccaed06242dc0d33cec68bf6354d2bcc
5
5
  SHA512:
6
- metadata.gz: d851f45539fc6af2e302ffc9497a0e18f71c6c261254bd0f7681d8a8996da2fd9b96659019f8d3c3012cc79a692c0d903d31d3ed2e50236fdc6fd13405baeba7
7
- data.tar.gz: 44aff14e7d23468f10a3214a31e6ee3920401421629230f2b7d19461b43f93a54573441895d2d3d06d041220cd554c3a1b90074447afa5eec0514d37dd91f297
6
+ metadata.gz: ef95e56e7c88e806e735dbb4cf8fef8233e0b5f64f437c6d33f6b13918d7c8f0bf8e2c3569ef0193b9f6af99024452d579a30f9333a72be79c947ffda489c918
7
+ data.tar.gz: 286ed07d78195d3977e00e3963dc8b2943ac356a7a123e8ac02e666566e1014f01e01c1f2fdd7de81bda0b722c9f295549d5673c023e1a74648741d94a31ba41
@@ -4,340 +4,24 @@
4
4
  version: 2
5
5
  jobs:
6
6
 
7
- build_2.2.7_rails_3:
7
+ build_2.5_rails_5:
8
8
  docker:
9
- - image: deliveroo/multiruby
9
+ - image: circleci/ruby:2.4.1
10
10
  - image: redis:3-alpine
11
11
  steps:
12
12
  - checkout
13
13
 
14
14
  - run:
15
- name: Select build variant (Ruby 2.2.7, rails_3)
15
+ name: Install bundler
16
16
  command: |
17
- rbenv local 2.2.7 ;
18
- gem install bundler ;
19
- bundle config --local gemfile $PWD/gemfiles/rails_3.gemfile
20
-
21
- - restore_cache:
22
- keys:
23
- - v2-bundle-2.2.7-rails_3-{{ .Branch }}
24
- - v2-bundle-2.2.7-rails_3
25
- - v2-bundle-2.2.7
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.2.7-rails_3-{{ .Branch }}
41
- paths:
42
- - ~/project/vendor/bundle
43
- - save_cache:
44
- key: v2-bundle-2.2.7-rails_3
45
- paths:
46
- - ~/project/vendor/bundle
47
- - save_cache:
48
- key: v2-bundle-2.2.7
49
- paths:
50
- - ~/project/vendor/bundle
51
-
52
- build_2.3.4_rails_3:
53
- docker:
54
- - image: deliveroo/multiruby
55
- - image: redis:3-alpine
56
- steps:
57
- - checkout
58
-
59
- - run:
60
- name: Select build variant (Ruby 2.3.4, rails_3)
61
- command: |
62
- rbenv local 2.3.4 ;
63
- gem install bundler ;
64
- bundle config --local gemfile $PWD/gemfiles/rails_3.gemfile
65
-
66
- - restore_cache:
67
- keys:
68
- - v2-bundle-2.3.4-rails_3-{{ .Branch }}
69
- - v2-bundle-2.3.4-rails_3
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_3-{{ .Branch }}
86
- paths:
87
- - ~/project/vendor/bundle
88
- - save_cache:
89
- key: v2-bundle-2.3.4-rails_3
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.2.7_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.2.7, rails_4)
106
- command: |
107
- rbenv local 2.2.7 ;
108
- gem install bundler ;
109
- bundle config --local gemfile $PWD/gemfiles/rails_4.gemfile
110
-
111
- - restore_cache:
112
- keys:
113
- - v2-bundle-2.2.7-rails_4-{{ .Branch }}
114
- - v2-bundle-2.2.7-rails_4
115
- - v2-bundle-2.2.7
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.2.7-rails_4-{{ .Branch }}
131
- paths:
132
- - ~/project/vendor/bundle
133
- - save_cache:
134
- key: v2-bundle-2.2.7-rails_4
135
- paths:
136
- - ~/project/vendor/bundle
137
- - save_cache:
138
- key: v2-bundle-2.2.7
139
- paths:
140
- - ~/project/vendor/bundle
141
-
142
- build_2.3.4_rails_4:
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_4)
151
- command: |
152
- rbenv local 2.3.4 ;
153
- gem install bundler ;
154
- bundle config --local gemfile $PWD/gemfiles/rails_4.gemfile
155
-
156
- - restore_cache:
157
- keys:
158
- - v2-bundle-2.3.4-rails_4-{{ .Branch }}
159
- - v2-bundle-2.3.4-rails_4
160
- - v2-bundle-2.3.4
161
-
162
- - run:
163
- name: Install dependencies
164
- command: |
165
- bundle install --jobs=3 --retry=3 --path=$PWD/vendor/bundle
166
-
167
- - run:
168
- name: Run test suite
169
- command: |
170
- unset RACK_ENV &&
171
- unset RAILS_ENV &&
172
- bundle exec rspec
173
-
174
- - save_cache:
175
- key: v2-bundle-2.3.4-rails_4-{{ .Branch }}
176
- paths:
177
- - ~/project/vendor/bundle
178
- - save_cache:
179
- key: v2-bundle-2.3.4-rails_4
180
- paths:
181
- - ~/project/vendor/bundle
182
- - save_cache:
183
- key: v2-bundle-2.3.4
184
- paths:
185
- - ~/project/vendor/bundle
186
-
187
- build_2.4.1_rails_4:
188
- docker:
189
- - image: deliveroo/multiruby
190
- - image: redis:3-alpine
191
- steps:
192
- - checkout
193
-
194
- - run:
195
- name: Select build variant (Ruby 2.4.1, rails_4)
196
- command: |
197
- rbenv local 2.4.1 ;
198
- gem install bundler ;
199
- bundle config --local gemfile $PWD/gemfiles/rails_4.gemfile
200
-
201
- - restore_cache:
202
- keys:
203
- - v2-bundle-2.4.1-rails_4-{{ .Branch }}
204
- - v2-bundle-2.4.1-rails_4
205
- - v2-bundle-2.4.1
206
-
207
- - run:
208
- name: Install dependencies
209
- command: |
210
- bundle install --jobs=3 --retry=3 --path=$PWD/vendor/bundle
211
-
212
- - run:
213
- name: Run test suite
214
- command: |
215
- unset RACK_ENV &&
216
- unset RAILS_ENV &&
217
- bundle exec rspec
218
-
219
- - save_cache:
220
- key: v2-bundle-2.4.1-rails_4-{{ .Branch }}
221
- paths:
222
- - ~/project/vendor/bundle
223
- - save_cache:
224
- key: v2-bundle-2.4.1-rails_4
225
- paths:
226
- - ~/project/vendor/bundle
227
- - save_cache:
228
- key: v2-bundle-2.4.1
229
- paths:
230
- - ~/project/vendor/bundle
231
-
232
- build_2.2.7_rails_5:
233
- docker:
234
- - image: deliveroo/multiruby
235
- - image: redis:3-alpine
236
- steps:
237
- - checkout
238
-
239
- - run:
240
- name: Select build variant (Ruby 2.2.7, rails_5)
241
- command: |
242
- rbenv local 2.2.7 ;
243
- gem install bundler ;
244
- bundle config --local gemfile $PWD/gemfiles/rails_5.gemfile
245
-
246
- - restore_cache:
247
- keys:
248
- - v2-bundle-2.2.7-rails_5-{{ .Branch }}
249
- - v2-bundle-2.2.7-rails_5
250
- - v2-bundle-2.2.7
251
-
252
- - run:
253
- name: Install dependencies
254
- command: |
255
- bundle install --jobs=3 --retry=3 --path=$PWD/vendor/bundle
256
-
257
- - run:
258
- name: Run test suite
259
- command: |
260
- unset RACK_ENV &&
261
- unset RAILS_ENV &&
262
- bundle exec rspec
263
-
264
- - save_cache:
265
- key: v2-bundle-2.2.7-rails_5-{{ .Branch }}
266
- paths:
267
- - ~/project/vendor/bundle
268
- - save_cache:
269
- key: v2-bundle-2.2.7-rails_5
270
- paths:
271
- - ~/project/vendor/bundle
272
- - save_cache:
273
- key: v2-bundle-2.2.7
274
- paths:
275
- - ~/project/vendor/bundle
276
-
277
- build_2.3.4_rails_5:
278
- docker:
279
- - image: deliveroo/multiruby
280
- - image: redis:3-alpine
281
- steps:
282
- - checkout
283
-
284
- - run:
285
- name: Select build variant (Ruby 2.3.4, rails_5)
286
- command: |
287
- rbenv local 2.3.4 ;
288
- gem install bundler ;
289
- bundle config --local gemfile $PWD/gemfiles/rails_5.gemfile
290
-
291
- - restore_cache:
292
- keys:
293
- - v2-bundle-2.3.4-rails_5-{{ .Branch }}
294
- - v2-bundle-2.3.4-rails_5
295
- - v2-bundle-2.3.4
296
-
297
- - run:
298
- name: Install dependencies
299
- command: |
300
- bundle install --jobs=3 --retry=3 --path=$PWD/vendor/bundle
301
-
302
- - run:
303
- name: Run test suite
304
- command: |
305
- unset RACK_ENV &&
306
- unset RAILS_ENV &&
307
- bundle exec rspec
308
-
309
- - save_cache:
310
- key: v2-bundle-2.3.4-rails_5-{{ .Branch }}
311
- paths:
312
- - ~/project/vendor/bundle
313
- - save_cache:
314
- key: v2-bundle-2.3.4-rails_5
315
- paths:
316
- - ~/project/vendor/bundle
317
- - save_cache:
318
- key: v2-bundle-2.3.4
319
- paths:
320
- - ~/project/vendor/bundle
321
-
322
- build_2.4.1_rails_5:
323
- docker:
324
- - image: deliveroo/multiruby
325
- - image: redis:3-alpine
326
- steps:
327
- - checkout
328
-
329
- - run:
330
- name: Select build variant (Ruby 2.4.1, rails_5)
331
- command: |
332
- rbenv local 2.4.1 ;
333
- gem install bundler ;
17
+ gem install bundler -v '~> 1.17' ;
334
18
  bundle config --local gemfile $PWD/gemfiles/rails_5.gemfile
335
19
 
336
20
  - restore_cache:
337
21
  keys:
338
- - v2-bundle-2.4.1-rails_5-{{ .Branch }}
339
- - v2-bundle-2.4.1-rails_5
340
- - v2-bundle-2.4.1
22
+ - v2-bundle-2.5.0-rails_5-{{ .Branch }}
23
+ - v2-bundle-2.5.0-rails_5
24
+ - v2-bundle-2.5.0
341
25
 
342
26
  - run:
343
27
  name: Install dependencies
@@ -352,15 +36,15 @@ jobs:
352
36
  bundle exec rspec
353
37
 
354
38
  - save_cache:
355
- key: v2-bundle-2.4.1-rails_5-{{ .Branch }}
39
+ key: v2-bundle-2.5.0-rails_5-{{ .Branch }}
356
40
  paths:
357
41
  - ~/project/vendor/bundle
358
42
  - save_cache:
359
- key: v2-bundle-2.4.1-rails_5
43
+ key: v2-bundle-2.5.0-rails_5
360
44
  paths:
361
45
  - ~/project/vendor/bundle
362
46
  - save_cache:
363
- key: v2-bundle-2.4.1
47
+ key: v2-bundle-2.5.0
364
48
  paths:
365
49
  - ~/project/vendor/bundle
366
50
 
@@ -369,20 +53,5 @@ workflows:
369
53
  version: 2
370
54
  test:
371
55
  jobs:
372
-
373
- - build_2.2.7_rails_3
374
-
375
- - build_2.3.4_rails_3
376
-
377
- - build_2.2.7_rails_4
378
-
379
- - build_2.3.4_rails_4
380
-
381
- - build_2.4.1_rails_4
382
-
383
- - build_2.2.7_rails_5
384
-
385
- - build_2.3.4_rails_5
386
-
387
- - build_2.4.1_rails_5
56
+ - build_2.5_rails_5
388
57
 
@@ -2,14 +2,11 @@
2
2
  # erb .circleci/config.yml.erb > .circleci/config.yml
3
3
  <%
4
4
  builds = [
5
- ['2.2.7', 'rails_3'],
6
5
  ['2.3.4', 'rails_3'],
7
- ['2.2.7', 'rails_4'],
8
6
  ['2.3.4', 'rails_4'],
9
7
  ['2.4.1', 'rails_4'],
10
- ['2.2.7', 'rails_5'],
11
8
  ['2.3.4', 'rails_5'],
12
- ['2.4.1', 'rails_5'],
9
+ ['2.4.1', 'rails_5']
13
10
  ]
14
11
  %>
15
12
  version: 2
@@ -26,7 +23,7 @@ jobs:
26
23
  name: Select build variant (Ruby <%= ruby %>, <%= variant %>)
27
24
  command: |
28
25
  rbenv local <%= ruby %> ;
29
- gem install bundler ;
26
+ gem install bundler -v '~> 1.17' ;
30
27
  bundle config --local gemfile $PWD/gemfiles/<%= variant %>.gemfile
31
28
 
32
29
  - restore_cache:
@@ -2,11 +2,41 @@
2
2
 
3
3
  _A description of your awesome changes here!_
4
4
 
5
+ ### 3.6.5 (2019-02-08)
6
+
7
+ Bug fix:
8
+
9
+ - Make sure Faraday adapter is loaded after all middleware for ApiClient
10
+
11
+ Drop:
12
+
13
+ - Builds for Ruby 2.2
14
+
15
+ ### 3.6.4 (2018-10-23)
16
+
17
+ Features:
18
+
19
+ - Allow specification of User-Agent through environment variable
20
+ - Add fallback values for User-Agent header in API client
21
+
22
+ ### 3.6.3 (2018-10-17)
23
+
24
+ Bug fix:
25
+
26
+ - Allow all middleware classes to be initialised in the same format
27
+
28
+ ### 3.6.2 (2018-10-11)
29
+
30
+ Features:
31
+
32
+ - `Routemaster::Cache` can be be given initialisation options to merge into the
33
+ default ones for creating a `Routemaster::APIClient` instance (#82)
34
+
5
35
  ### 3.6.1 (2018-10-09)
6
36
 
7
37
  Features:
8
38
 
9
- - Clients can now set User Agent when placing requests
39
+ - Clients can now set User Agent when placing requests (#80) - details in README
10
40
 
11
41
  ### 3.6.0 (2018-07-23)
12
42
 
data/README.md CHANGED
@@ -139,6 +139,13 @@ map '/events' do
139
139
  end
140
140
  ```
141
141
 
142
+ You can use the `.subscribe` method multiple times to have your event batches
143
+ go through multiple listeners. But bear in the mind any performance cost of
144
+ multiple places of processing the event batches. For example, instead of having
145
+ multiple listener classes that iterate over the events in a batch, you can have
146
+ a single listener class that iterates over the batch only once and reacts to the
147
+ batch's events accordingly.
148
+
142
149
  This relies on the excellent event bus from the [wisper
143
150
  gem](https://github.com/krisleech/wisper#wisper).
144
151
 
@@ -257,6 +264,16 @@ See
257
264
  [rubydoc](http://rubydoc.info/github/deliveroo/routemaster-drain/Routemaster/Cache)
258
265
  for more details on `Cache`.
259
266
 
267
+ If you need to provide configure the `APIClient` used by `Routemaster::Cache`, you can
268
+ configure it using `client_options`:
269
+
270
+ ```ruby
271
+ $cache = Routemaster::Cache.new(client_options: {source_peer: "<your user agent>"})
272
+ ```
273
+
274
+ You can specify your user agent with the `ROUTEMASTER_API_CLIENT_USER_AGENT` environment
275
+ variable as well.
276
+
260
277
  ### Expire Cache data for all notified resources
261
278
 
262
279
  You may wish to maintain a coherent cache, but don't need the cache to be warmed
@@ -282,7 +299,10 @@ Example:
282
299
  require 'routemaster/fetcher'
283
300
  require 'routemaster/responses/hateoas_response'
284
301
 
285
- client = Routemaster::APIClient.new(response_class: Routemaster::Responses::HateoasResponse)
302
+ client = Routemaster::APIClient.new(
303
+ response_class: Routemaster::Responses::HateoasResponse,
304
+ source_peer: "<your user agent>"
305
+ )
286
306
 
287
307
  response = client.discover('https://identity.deliveroo.com.dev')
288
308
  session_create_response = response.sessions.create(email: 'test@test.com', password: 'sup3rs3cr3t')
@@ -30,6 +30,7 @@ require 'hashie/mash'
30
30
 
31
31
  module Routemaster
32
32
  class APIClient
33
+ DEFAULT_USER_AGENT = ENV.fetch('ROUTEMASTER_API_CLIENT_USER_AGENT') { "RoutemasterDrain - Faraday v#{Faraday::VERSION}" }.freeze
33
34
 
34
35
  # Memoize the root resources at Class level so that we don't hit the cache
35
36
  # all the time to fetch the root resource before doing anything else.
@@ -139,12 +140,13 @@ module Routemaster
139
140
  f.use Routemaster::Middleware::ResponseCaching, listener: @listener
140
141
  f.use Routemaster::Middleware::Metrics, client: @metrics_client, source_peer: @source_peer
141
142
  f.use Routemaster::Middleware::ErrorHandling
142
- f.adapter :typhoeus
143
143
 
144
144
  @middlewares.each do |middleware|
145
145
  f.use(*middleware)
146
146
  end
147
147
 
148
+ f.adapter :typhoeus
149
+
148
150
  f.options.timeout = ENV.fetch('ROUTEMASTER_CACHE_TIMEOUT', 1).to_f
149
151
  f.options.open_timeout = ENV.fetch('ROUTEMASTER_CACHE_TIMEOUT', 1).to_f
150
152
  f.ssl.verify = ENV.fetch('ROUTEMASTER_CACHE_VERIFY_SSL', 'false') == 'true'
@@ -157,8 +159,7 @@ module Routemaster
157
159
  end
158
160
 
159
161
  def user_agent_header
160
- agent = @source_peer || "Faraday v#{Faraday::VERSION}"
161
- { 'User-Agent' => agent }
162
+ { 'User-Agent' => @source_peer || DEFAULT_USER_AGENT }
162
163
  end
163
164
 
164
165
  def response_cache_opt_headers(value)
@@ -25,13 +25,14 @@ module Routemaster
25
25
  ENV.fetch('ROUTEMASTER_ENABLE_API_CLIENT_CIRCUIT', 'NO') =~ /\A(YES|TRUE|ON|1)\Z/i
26
26
  end
27
27
 
28
+
28
29
  def circuit
29
30
  Circuitbox.circuit(@circuit_name, {
30
31
  sleep_window: configuration_setting(@circuit_name, 'ROUTEMASTER_CIRCUIT_BREAKER_SLEEP_WINDOW', 60).to_i,
31
32
  time_window: configuration_setting(@circuit_name, 'ROUTEMASTER_CIRCUIT_BREAKER_TIME_WINDOW', 120).to_i,
32
33
  volume_threshold: configuration_setting(@circuit_name, 'ROUTEMASTER_CIRCUIT_BREAKER_VOLUME_THRESHOLD', 50).to_i,
33
34
  error_threshold: configuration_setting(@circuit_name, 'ROUTEMASTER_CIRCUIT_BREAKER_ERROR_THRESHOLD', 50).to_i,
34
- cache: Moneta.new(:Redis, backend: Config.cache_redis),
35
+ cache: Moneta::Adapters::Redis.new(backend: Config.cache_redis),
35
36
  exceptions: [Routemaster::Errors::FatalResource, Faraday::TimeoutError]
36
37
  })
37
38
  end
@@ -18,9 +18,9 @@ module Routemaster
18
18
  class Cache
19
19
  include Wisper::Publisher
20
20
 
21
- def initialize(redis: nil, client: nil)
21
+ def initialize(redis: nil, client: nil, client_options: {})
22
22
  @redis = redis || Config.cache_redis
23
- @client = client || APIClient.new(listener: self)
23
+ @client = client || APIClient.new(client_options.merge(listener: self))
24
24
  end
25
25
 
26
26
  # Bust the cache for a given URL
@@ -1,5 +1,5 @@
1
1
  module Routemaster
2
2
  module Drain
3
- VERSION = '3.6.1'.freeze
3
+ VERSION = '3.6.6'.freeze
4
4
  end
5
5
  end
@@ -16,10 +16,10 @@ module Routemaster
16
16
  class Authenticate
17
17
  include Wisper::Publisher
18
18
 
19
- # @param uuid [Enumerable] a set of accepted authentication tokens
20
- def initialize(app, uuid: nil, **_)
19
+ # options[:uuid] [Enumerable] a set of accepted authentication tokens
20
+ def initialize(app, options = {})
21
21
  @app = app
22
- @uuid = uuid || Config.drain_tokens
22
+ @uuid = options.fetch(:uuid) { Config.drain_tokens }
23
23
 
24
24
  unless @uuid.kind_of?(String) || @uuid.kind_of?(Enumerable)
25
25
  raise ArgumentError, ':uuid must be a String or Enumerable'
@@ -7,11 +7,11 @@ require 'routemaster/event_index'
7
7
  module Routemaster
8
8
  module Middleware
9
9
  class Cache
10
- def initialize(app, cache:nil, client:nil, queue:nil, **_)
10
+ def initialize(app, options = {})
11
11
  @app = app
12
- @cache = cache || Routemaster::Cache.new
13
- @client = client || Routemaster::Jobs::Client.new
14
- @queue = queue || Config.queue_name
12
+ @cache = options.fetch(:cache) { Routemaster::Cache.new }
13
+ @client = options.fetch(:client) { Routemaster::Jobs::Client.new }
14
+ @queue = options.fetch(:queue) { Config.queue_name }
15
15
  end
16
16
 
17
17
  def call(env)
@@ -11,9 +11,9 @@ module Routemaster
11
11
  # The dirty map is passed as `:map` to the constructor and must respond to
12
12
  # `#mark` (like `Routemaster::Dirty::Map`).
13
13
  class Dirty
14
- def initialize(app, dirty_map: nil, **_)
14
+ def initialize(app, options = {})
15
15
  @app = app
16
- @map = dirty_map || Routemaster::Dirty::Map.new
16
+ @map = options.fetch(:dirty_map) { Routemaster::Dirty::Map.new }
17
17
  end
18
18
 
19
19
  def call(env)
@@ -3,9 +3,9 @@ require 'routemaster/cache'
3
3
  module Routemaster
4
4
  module Middleware
5
5
  class ExpireCache
6
- def initialize(app, cache:nil, **_)
6
+ def initialize(app, options = {})
7
7
  @app = app
8
- @cache = cache || Routemaster::Cache.new
8
+ @cache = options.fetch(:cache) { Routemaster::Cache.new }
9
9
  end
10
10
 
11
11
  def call(env)
@@ -7,11 +7,11 @@ module Routemaster
7
7
  #
8
8
  # Will use `Routemaster::Dirty::Filter` by default.
9
9
  class Filter
10
- # @param filter [Routemaster::Dirty::Filter] an event filter (optional;
10
+ # options[:filter] [Routemaster::Dirty::Filter] an event filter (optional;
11
11
  # will be created using the `redis` and `expiry` options if not provided)
12
- def initialize(app, filter:nil, **_)
12
+ def initialize(app, options = {})
13
13
  @app = app
14
- @filter = filter || Routemaster::Dirty::Filter.new
14
+ @filter = options.fetch(:filter) { Routemaster::Dirty::Filter.new }
15
15
  end
16
16
 
17
17
  def call(env)
@@ -3,10 +3,10 @@ module Routemaster
3
3
  class Metrics
4
4
  INTERACTION_KEY = 'api_client'.freeze
5
5
 
6
- def initialize(app, client: nil, source_peer: nil)
6
+ def initialize(app, options = {})
7
7
  @app = app
8
- @client = client
9
- @source_peer = source_peer
8
+ @client = options[:client]
9
+ @source_peer = options[:source_peer]
10
10
  end
11
11
 
12
12
  def call(request_env)
@@ -10,7 +10,7 @@ module Routemaster
10
10
  # Lower middlewares (or the app) can access the parsed payload as a hash
11
11
  # in +env['routemaster.payload']+
12
12
  class Parse
13
- def initialize(app)
13
+ def initialize(app, _options = {})
14
14
  @app = app
15
15
  end
16
16
 
@@ -10,11 +10,11 @@ module Routemaster
10
10
  VERSION_REGEX = /application\/json;v=(?<version>\S*)/
11
11
  RESPONSE_CACHING_OPT_HEADER = 'X-routemaster_drain.opt_cache'.freeze
12
12
 
13
- def initialize(app, cache: Config.cache_redis, listener: nil)
13
+ def initialize(app, options = {})
14
14
  @app = app
15
- @cache = cache
15
+ @cache = options.fetch(:cache) { Config.cache_redis }
16
16
  @expiry = Config.cache_expiry
17
- @listener = listener
17
+ @listener = options[:listener]
18
18
  end
19
19
 
20
20
  def call(env)
@@ -2,7 +2,7 @@ module Routemaster
2
2
  module Middleware
3
3
  # Rejects all requests but POST to the root path
4
4
  class RootPostOnly
5
- def initialize(app)
5
+ def initialize(app, _options = {})
6
6
  @app = app
7
7
  end
8
8
 
@@ -6,9 +6,9 @@ module Routemaster
6
6
  #
7
7
  # Topic handlers are initialized with the full event payload and must respond to `#call`
8
8
  class Siphon
9
- def initialize(app, siphon_events: nil)
9
+ def initialize(app, options = {})
10
10
  @app = app
11
- @processors = siphon_events || {}
11
+ @processors = options.fetch(:siphon_events) { {} }
12
12
  end
13
13
 
14
14
  def call(env)
@@ -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
@@ -52,7 +52,8 @@ describe Routemaster::APIClient do
52
52
  headers['x-custom-header'] = 'why do you even'
53
53
  subject.status
54
54
  assert_requested(:get, /example/) do |req|
55
- expect(req.headers).to include('X-Custom-Header')
55
+ expect(req.headers.keys).to include('X-Custom-Header')
56
+ expect(req.headers['User-Agent']).to eql "RoutemasterDrain - Faraday v#{Faraday::VERSION}"
56
57
  end
57
58
  end
58
59
 
@@ -76,7 +77,7 @@ describe Routemaster::APIClient do
76
77
  it 'should set the user agent header to the faraday version' do
77
78
  subject.status
78
79
  assert_requested(:get, /example/) do |req|
79
- expect(req.headers).to include('User-Agent' => "Faraday v#{Faraday::VERSION}" )
80
+ expect(req.headers).to include('User-Agent' => "RoutemasterDrain - Faraday v#{Faraday::VERSION}" )
80
81
  end
81
82
  end
82
83
  end
@@ -62,6 +62,19 @@ module Routemaster
62
62
  perform.status
63
63
  end
64
64
  end
65
+
66
+ context 'with source_peer client option' do
67
+ let(:options) { {} }
68
+ subject { described_class.new(client_options: {source_peer: 'test-peer'}) }
69
+
70
+ it 'calls get on the api client with given user agent' do
71
+ perform.status
72
+
73
+ assert_requested(:get, url) do |req|
74
+ expect(req.headers).to include('User-Agent' => 'test-peer' )
75
+ end
76
+ end
77
+ end
65
78
  end
66
79
 
67
80
  describe '#get' do
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.1
4
+ version: 3.6.6
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: 2018-10-09 00:00:00.000000000 Z
11
+ date: 2020-10-22 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: []
@@ -271,7 +285,7 @@ homepage: http://github.com/deliveroo/routemaster-drain
271
285
  licenses:
272
286
  - MIT
273
287
  metadata: {}
274
- post_install_message:
288
+ post_install_message:
275
289
  rdoc_options: []
276
290
  require_paths:
277
291
  - lib
@@ -286,9 +300,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
300
  - !ruby/object:Gem::Version
287
301
  version: '0'
288
302
  requirements: []
289
- rubyforge_project:
290
- rubygems_version: 2.6.11
291
- signing_key:
303
+ rubygems_version: 3.1.4
304
+ signing_key:
292
305
  specification_version: 4
293
306
  summary: Event receiver for the Routemaster bus
294
307
  test_files: