determinator 0.1.1 → 0.2.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
  SHA1:
3
- metadata.gz: 31a5345bdfccd96ab6365abbf4252b404f04dcad
4
- data.tar.gz: 8ad32254bb12c3ec42c231a004cebc766b81c638
3
+ metadata.gz: d000e613ee7aeaf88c08bf5588ad6e076722e9da
4
+ data.tar.gz: b133723daaea81147a3abb6ca2300717669dced2
5
5
  SHA512:
6
- metadata.gz: 72d958a7aa3f1e4760d786d903e6b26d262d709156dfdeba0969637fd91ccc034db6e716eafba467d687ed9ecccbb0b33ae4bb66ae138f9f16f04fcf6d4506b1
7
- data.tar.gz: 97e2fbf318765d3982afad0a0f8e4766784e3360be8779e1389f8b1515ad16d679429d165f39c92ed232d5963500f6b0c645005bfa8bba2479b4005b3fc9e26e
6
+ metadata.gz: 59a22af903dd9f0cce9a714617efb5b7a38a6933245d2299a50e1d999784fd328361b5ba3f50751f55d8c57e49fac6c76059a9d8900dcfa93d405f0fa4b76917
7
+ data.tar.gz: 7da1374c9d8588b25d3b9dddfb7b407a0a80a614b9c3eb383d9f11f837526d27339364025aa0240c434d8b59f5194f167380e020c5fdeae9816924d65fceeb3f
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_runtime_dependency "routemaster-drain", "~> 2.4"
23
+ spec.add_runtime_dependency "routemaster-drain", "~> 2.5"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.13"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,7 +1,7 @@
1
1
  require 'uri'
2
2
  require 'routemaster/drain/caching'
3
3
  require 'routemaster/responses/hateoas_response'
4
- require 'determinator/retrieve/routemaster_indexing_middleware'
4
+ require 'determinator/retrieve/routemaster_feature_id_cache_warmer'
5
5
 
6
6
  module Determinator
7
7
  module Retrieve
@@ -24,11 +24,12 @@ module Determinator
24
24
  # @param :discovery_url [String] The bootstrap URL of the instance of Florence which defines Features.
25
25
  def initialize(discovery_url:)
26
26
  client = ::Routemaster::APIClient.new(
27
- response_class: ::Routemaster::Responses::HateoasResponse,
28
- middlewares: [RoutemasterIndexingMiddleware]
27
+ response_class: ::Routemaster::Responses::HateoasResponse
29
28
  )
30
29
  @routemaster = client.discover(discovery_url)
31
- @routemaster_app = ::Routemaster::Drain::Caching.new
30
+ @routemaster_app = ::Routemaster::Drain::Caching.new(
31
+ siphon_events: { 'features' => RoutemasterFeatureIdCacheWarmer }
32
+ )
32
33
  end
33
34
 
34
35
  def retrieve(feature_name)
@@ -45,11 +46,11 @@ module Determinator
45
46
  target_groups: obj.body.target_groups.map { |tg|
46
47
  TargetGroup.new(
47
48
  rollout: tg.rollout,
48
- constraints: tg.constraints.to_hash
49
+ constraints: tg.constraints.to_h
49
50
  )
50
51
  },
51
- variants: obj.body.variants.to_hash,
52
- overrides: obj.body.overrides.to_hash
52
+ variants: obj.body.variants.to_h,
53
+ overrides: obj.body.overrides.to_h
53
54
  )
54
55
  rescue ::Routemaster::Errors::ResourceNotFound
55
56
  nil
@@ -0,0 +1,29 @@
1
+ module Determinator
2
+ module Retrieve
3
+ class RoutemasterFeatureIdCacheWarmer
4
+ def initialize(payload)
5
+ @payload = payload
6
+ end
7
+
8
+ def call
9
+ response = client.get(@payload['url']).body
10
+ if valid_feature_response?(response)
11
+ key = Routemaster.index_cache_key(response['name'])
12
+ ::Routemaster::Config.cache_redis.set(key, response['id'])
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def client
19
+ @client ||= ::Routemaster::APIClient.new(
20
+ response_class: ::Routemaster::Responses::HateoasResponse
21
+ )
22
+ end
23
+
24
+ def valid_feature_response?(response)
25
+ response['id'] && response['name'] && response['bucket_type']
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Determinator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: determinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Hastings-Spital
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-21 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: routemaster-drain
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.4'
19
+ version: '2.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.4'
26
+ version: '2.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +178,7 @@ files:
178
178
  - lib/determinator/control.rb
179
179
  - lib/determinator/feature.rb
180
180
  - lib/determinator/retrieve/routemaster.rb
181
- - lib/determinator/retrieve/routemaster_indexing_middleware.rb
181
+ - lib/determinator/retrieve/routemaster_feature_id_cache_warmer.rb
182
182
  - lib/determinator/target_group.rb
183
183
  - lib/determinator/version.rb
184
184
  homepage: https://github.com/deliveroo/determinator
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '0'
202
202
  requirements: []
203
203
  rubyforge_project:
204
- rubygems_version: 2.5.1
204
+ rubygems_version: 2.6.8
205
205
  signing_key:
206
206
  specification_version: 4
207
207
  summary: Determine which experiments and features a specific actor should see.
@@ -1,28 +0,0 @@
1
- module Determinator
2
- module Retrieve
3
- # Middleware which indexes features by their name, so we can look up a feature by name
4
- # and find the details (which are only accessible by ID)
5
- class RoutemasterIndexingMiddleware
6
- def initialize(app)
7
- @app = app
8
- end
9
-
10
- def call(env)
11
- content = JSON.parse(env.body)
12
-
13
- if content_describes_feature?(content)
14
- key = Routemaster.index_cache_key(content['name'])
15
- ::Routemaster::Config.cache_redis.set(key, content['id'])
16
- end
17
-
18
- @app.call(env)
19
- end
20
-
21
- private
22
-
23
- def content_describes_feature?(content)
24
- content['id'] && content['name'] && content['bucket_type']
25
- end
26
- end
27
- end
28
- end