alephant-broker 3.18.0 → 3.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -1
- data/lib/alephant/broker/cache/cached_object.rb +4 -4
- data/lib/alephant/broker/cache/client.rb +14 -6
- data/lib/alephant/broker/component_factory.rb +10 -2
- data/lib/alephant/broker/environment.rb +6 -2
- data/lib/alephant/broker/load_strategy/http.rb +3 -2
- data/lib/alephant/broker/load_strategy/revalidate/fetcher.rb +2 -2
- data/lib/alephant/broker/load_strategy/revalidate/refresher.rb +2 -2
- data/lib/alephant/broker/load_strategy/revalidate/strategy.rb +15 -7
- data/lib/alephant/broker/load_strategy/s3/base.rb +1 -1
- data/lib/alephant/broker/request/asset.rb +4 -1
- data/lib/alephant/broker/request/batch.rb +5 -2
- data/lib/alephant/broker/response/asset.rb +4 -1
- data/lib/alephant/broker/response/batch.rb +11 -5
- data/lib/alephant/broker/version.rb +1 -1
- data/spec/integration/not_modified_response_spec.rb +2 -2
- data/spec/integration/rack_spec.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f210f7897e17ccce5f81abe391c038f1c8ad1ce0
|
4
|
+
data.tar.gz: 9aeac99c27ba61568542e30c6c1fbf1a39861c97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9ae2a9cf2146b7fb9eb32fd2c69c12851b74709d7883492f75fbbbb6f0e786765c1aed45e03a021bbd378fc761ab233db5736b46b3768d32fcb4997114c15e4
|
7
|
+
data.tar.gz: 97d0cb77082e460f93627c21da6ffafa24584227e7701129efe9938c74e16ad4a536c5a11b700da09fbf001e73936d72b04bd5fa6e14da92ca669398c62579a4
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3
|
1
|
+
2.3.0
|
data/.travis.yml
CHANGED
@@ -11,7 +11,7 @@ module Alephant
|
|
11
11
|
DEFAULT_TTL = 10
|
12
12
|
|
13
13
|
def initialize(obj)
|
14
|
-
logger.
|
14
|
+
logger.debug(event: 'SettingCachedObject',
|
15
15
|
content: obj,
|
16
16
|
method: "#{self.class}#initialize")
|
17
17
|
|
@@ -19,7 +19,7 @@ module Alephant
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def update(obj)
|
22
|
-
logger.
|
22
|
+
logger.debug(event: 'UpdatingCachedObject',
|
23
23
|
old_content: @s3_obj,
|
24
24
|
new_content: obj,
|
25
25
|
method: "#{self.class}#update")
|
@@ -31,14 +31,14 @@ module Alephant
|
|
31
31
|
time = metadata[:'head_Last-Modified']
|
32
32
|
Time.parse(time)
|
33
33
|
rescue TypeError, ArgumentError => error
|
34
|
-
logger.
|
34
|
+
logger.error(event: 'CachedObjectLastModifiedError', method: "#{self.class}#updated", error: error)
|
35
35
|
Time.now
|
36
36
|
end
|
37
37
|
|
38
38
|
def ttl
|
39
39
|
Integer(metadata[:ttl] || metadata['ttl'])
|
40
40
|
rescue TypeError => error
|
41
|
-
logger.
|
41
|
+
logger.error(event: 'NonIntegerTTLError', method: "#{self.class}#ttl", error: error)
|
42
42
|
Integer(Broker.config[:revalidate_cache_ttl] || DEFAULT_TTL)
|
43
43
|
end
|
44
44
|
|
@@ -11,7 +11,10 @@ module Alephant
|
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
if config_endpoint.nil?
|
14
|
-
logger.
|
14
|
+
logger.error(
|
15
|
+
method: 'Broker::Cache::Client#initialize',
|
16
|
+
message: 'No config endpoint, NullClient used'
|
17
|
+
)
|
15
18
|
logger.metric 'NoConfigEndpoint'
|
16
19
|
@client = NullClient.new
|
17
20
|
else
|
@@ -23,22 +26,27 @@ module Alephant
|
|
23
26
|
versioned_key = versioned(key)
|
24
27
|
result = @client.get(versioned_key)
|
25
28
|
|
26
|
-
logger.
|
29
|
+
logger.debug(
|
30
|
+
method: 'Broker::Cache::Client#get',
|
31
|
+
key: versioned_key,
|
32
|
+
result: result ? 'hit' : 'miss'
|
33
|
+
)
|
27
34
|
logger.metric('GetKeyMiss') unless result
|
28
35
|
|
29
36
|
return result if result
|
30
37
|
|
31
38
|
set(key, yield) if block_given?
|
32
|
-
rescue StandardError => error
|
33
|
-
logger.info(event: 'ErrorCaught', method: "#{self.class}#get", error: error)
|
34
|
-
yield if block_given?
|
35
39
|
end
|
36
40
|
|
37
41
|
def set(key, value, custom_ttl = nil)
|
38
42
|
versioned_key = versioned(key)
|
39
43
|
set_ttl = custom_ttl || ttl
|
40
44
|
|
41
|
-
logger.
|
45
|
+
logger.debug(
|
46
|
+
method: "#{self.class}#set",
|
47
|
+
key: versioned_key,
|
48
|
+
ttl: set_ttl
|
49
|
+
)
|
42
50
|
|
43
51
|
@client.set(versioned_key, value, set_ttl)
|
44
52
|
|
@@ -19,11 +19,19 @@ module Alephant
|
|
19
19
|
@load_strategy.load(component_meta)
|
20
20
|
)
|
21
21
|
rescue Alephant::Broker::Errors::ContentNotFound => e
|
22
|
-
logger.
|
22
|
+
logger.error(
|
23
|
+
method: 'Broker.ComponentFactory.create',
|
24
|
+
message: 'Exception raised (ContentNotFound)',
|
25
|
+
component_key: component_meta.component_key
|
26
|
+
)
|
23
27
|
logger.metric "ContentNotFound"
|
24
28
|
ErrorComponent.new(component_meta, 404, e)
|
25
29
|
rescue => e
|
26
|
-
logger.
|
30
|
+
logger.error(
|
31
|
+
method: 'Broker.ComponentFactory.create',
|
32
|
+
message: e.message,
|
33
|
+
backtrace: e.backtrace.join('\n')
|
34
|
+
)
|
27
35
|
logger.metric "ExceptionRaised"
|
28
36
|
ErrorComponent.new(component_meta, 500, e)
|
29
37
|
end
|
@@ -60,8 +60,12 @@ module Alephant
|
|
60
60
|
|
61
61
|
def parse(json)
|
62
62
|
::JSON.parse(json)
|
63
|
-
rescue ::JSON::ParserError =>
|
64
|
-
logger.
|
63
|
+
rescue ::JSON::ParserError => error
|
64
|
+
logger.error(
|
65
|
+
method: 'Broker.environment#data',
|
66
|
+
message: 'ParserError',
|
67
|
+
error: error
|
68
|
+
)
|
65
69
|
logger.metric "JSONParserError"
|
66
70
|
nil
|
67
71
|
end
|
@@ -21,8 +21,9 @@ module Alephant
|
|
21
21
|
|
22
22
|
def load(component_meta)
|
23
23
|
fetch_object(component_meta)
|
24
|
-
rescue
|
25
|
-
logger.
|
24
|
+
rescue StandardError => error
|
25
|
+
logger.error(method: "#{self.class}#load", error: error)
|
26
|
+
logger.metric 'HTTPCacheMiss'
|
26
27
|
cache.set(component_meta.component_key, content(component_meta))
|
27
28
|
end
|
28
29
|
|
@@ -16,8 +16,8 @@ module Alephant
|
|
16
16
|
def fetch
|
17
17
|
Alephant::Broker::Cache::CachedObject.new(s3.get(s3_path))
|
18
18
|
rescue Aws::S3::Errors::NoSuchKey, InvalidCacheKey => error
|
19
|
-
logger.
|
20
|
-
logger.metric
|
19
|
+
logger.error(event: 'InvalidCacheKeyErrorCaught', method: "#{self.class}#fetch", error: error)
|
20
|
+
logger.metric 'S3InvalidCacheKey'
|
21
21
|
raise Alephant::Broker::Errors::ContentNotFound
|
22
22
|
end
|
23
23
|
|
@@ -16,11 +16,11 @@ module Alephant
|
|
16
16
|
def refresh
|
17
17
|
inflight = cache.get(inflight_cache_key)
|
18
18
|
|
19
|
-
logger.
|
19
|
+
logger.debug(event: 'Inflight?', cache_val: inflight, method: "#{self.class}#refresh")
|
20
20
|
|
21
21
|
return if inflight
|
22
22
|
|
23
|
-
logger.
|
23
|
+
logger.debug(event: 'QueueMessage', message: message, method: "#{self.class}#refresh")
|
24
24
|
|
25
25
|
client.send_message(
|
26
26
|
queue_url: queue_url,
|
@@ -44,7 +44,10 @@ module Alephant
|
|
44
44
|
|
45
45
|
def cached_object(component_meta)
|
46
46
|
cache.get(component_meta.component_key) do
|
47
|
-
logger.
|
47
|
+
logger.debug(
|
48
|
+
method: "#{self.class}#cached_object",
|
49
|
+
message: 'No cache so loading and adding cache object'
|
50
|
+
)
|
48
51
|
Fetcher.new(component_meta).fetch
|
49
52
|
end
|
50
53
|
end
|
@@ -74,16 +77,21 @@ module Alephant
|
|
74
77
|
end
|
75
78
|
|
76
79
|
def cache_new_content(component_meta, new_content)
|
77
|
-
logger.
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
logger.debug(
|
81
|
+
event: 'NewContentFromS3',
|
82
|
+
key: component_meta.component_key,
|
83
|
+
val: new_content,
|
84
|
+
method: "#{self.class}#refresh_content"
|
85
|
+
)
|
81
86
|
|
82
87
|
cache.set(component_meta.component_key, new_content)
|
83
88
|
end
|
84
89
|
|
85
|
-
def refresh_content(component_meta)
|
86
|
-
logger.
|
90
|
+
def refresh_content(component_meta)
|
91
|
+
logger.debug(
|
92
|
+
method: "#{self.class}#refresh_content",
|
93
|
+
message: 'Loading new content from thread',
|
94
|
+
)
|
87
95
|
|
88
96
|
Refresher.new(component_meta).refresh
|
89
97
|
end
|
@@ -18,7 +18,10 @@ module Alephant
|
|
18
18
|
)
|
19
19
|
rescue InvalidAssetId
|
20
20
|
logger.metric "InvalidAssetId"
|
21
|
-
logger.error
|
21
|
+
logger.error(
|
22
|
+
method: 'Broker.Request.Asset.initialize',
|
23
|
+
message: 'Exception raised (InvalidAssetId)'
|
24
|
+
)
|
22
25
|
end
|
23
26
|
|
24
27
|
private
|
@@ -16,11 +16,14 @@ module Alephant
|
|
16
16
|
env.options.fetch("batch_id", nil)
|
17
17
|
end
|
18
18
|
|
19
|
-
logger.
|
19
|
+
logger.debug(
|
20
|
+
method: "Request::Batch#initialize",
|
21
|
+
id: batch_id,
|
22
|
+
)
|
20
23
|
|
21
24
|
@component_factory = component_factory
|
22
25
|
|
23
|
-
@components
|
26
|
+
@components = env.post? ? components_post(env) : components_get(env)
|
24
27
|
end
|
25
28
|
|
26
29
|
private
|
@@ -10,9 +10,9 @@ module Alephant
|
|
10
10
|
attr_reader :components, :batch_id
|
11
11
|
|
12
12
|
def initialize(components, batch_id, request_env)
|
13
|
-
@components
|
14
|
-
@batch_id
|
15
|
-
@status
|
13
|
+
@components = components
|
14
|
+
@batch_id = batch_id
|
15
|
+
@status = self.class.component_not_modified(batch_response_headers, request_env) ? 304 : 200
|
16
16
|
|
17
17
|
super(@status, "application/json", request_env)
|
18
18
|
|
@@ -27,7 +27,10 @@ module Alephant
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def json
|
30
|
-
logger.
|
30
|
+
logger.debug(
|
31
|
+
message: 'Broker: Batch load started',
|
32
|
+
batch_id: batch_id
|
33
|
+
)
|
31
34
|
components.map do |component|
|
32
35
|
{
|
33
36
|
"component" => component.id,
|
@@ -39,7 +42,10 @@ module Alephant
|
|
39
42
|
headers["sequence_id"] = component.headers["X-Sequence"] if component.headers["X-Sequence"]
|
40
43
|
end
|
41
44
|
end.tap do
|
42
|
-
logger.
|
45
|
+
logger.debug(
|
46
|
+
message: 'Broker: Batch load completed',
|
47
|
+
batch_id: batch_id
|
48
|
+
)
|
43
49
|
logger.metric "BrokerBatchLoadCount"
|
44
50
|
end
|
45
51
|
end
|
@@ -115,7 +115,7 @@ describe Alephant::Broker::Application do
|
|
115
115
|
context "when requesting an unmodified response" do
|
116
116
|
let(:path) { "/components/batch" }
|
117
117
|
let(:content_type) { "application/json" }
|
118
|
-
let(:etag) { '"
|
118
|
+
let(:etag) { '"8d2f79a98b0e0c1fbcca34850f2c7f17"' }
|
119
119
|
|
120
120
|
before do
|
121
121
|
post(path, batch_json,
|
@@ -186,7 +186,7 @@ describe Alephant::Broker::Application do
|
|
186
186
|
context "when requesting an unmodified response with GET" do
|
187
187
|
let(:path) { "/components/batch?batch_id=baz&components[ni_council_results_table][component]=ni_council_results_table&components[ni_council_results_table][options][foo]=bar&components[ni_council_results_table_no_options][component]=ni_council_results_table" }
|
188
188
|
let(:content_type) { "application/json" }
|
189
|
-
let(:etag) { '"
|
189
|
+
let(:etag) { '"8d2f79a98b0e0c1fbcca34850f2c7f17"' }
|
190
190
|
|
191
191
|
before do
|
192
192
|
get(
|
@@ -174,7 +174,7 @@ describe Alephant::Broker::Application do
|
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should have ETag cache header" do
|
177
|
-
expect(last_response.headers["ETag"]).to eq('"
|
177
|
+
expect(last_response.headers["ETag"]).to eq('"8d2f79a98b0e0c1fbcca34850f2c7f17"')
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should have most recent Last-Modified header" do
|
@@ -223,7 +223,7 @@ describe Alephant::Broker::Application do
|
|
223
223
|
end
|
224
224
|
|
225
225
|
it "should have ETag cache header" do
|
226
|
-
expect(last_response.headers["ETag"]).to eq('"
|
226
|
+
expect(last_response.headers["ETag"]).to eq('"8d2f79a98b0e0c1fbcca34850f2c7f17"')
|
227
227
|
end
|
228
228
|
|
229
229
|
it "should have most recent Last-Modified header" do
|
@@ -269,7 +269,7 @@ describe Alephant::Broker::Application do
|
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should have ETag cache header" do
|
272
|
-
expect(last_response.headers["ETag"]).to eq('"
|
272
|
+
expect(last_response.headers["ETag"]).to eq('"8d2f79a98b0e0c1fbcca34850f2c7f17"')
|
273
273
|
end
|
274
274
|
|
275
275
|
it "should have most recent Last-Modified header" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BBC News
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -432,7 +432,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
432
432
|
version: '0'
|
433
433
|
requirements: []
|
434
434
|
rubyforge_project:
|
435
|
-
rubygems_version: 2.
|
435
|
+
rubygems_version: 2.5.1
|
436
436
|
signing_key:
|
437
437
|
specification_version: 4
|
438
438
|
summary: Brokers requests for alephant components
|