garage_client 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/garage_client/client.rb +12 -11
- data/lib/garage_client/version.rb +1 -1
- data/spec/features/tracing_spec.rb +46 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c9d279f5317c4beb50f7542c228b79e21082741
|
4
|
+
data.tar.gz: e82fee549ef03800c4a17fc10c0c351a9d704fbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57a217f525aed34172d4e08192040d772d5a79a8c7bb396b133c83f4e500ec27729ae9f7bad093565b0a7b66c2486c5a18b138023bd0d1baefa950a40a22ec70
|
7
|
+
data.tar.gz: 0b5d6f3ebdc2149acd28519ae99a67e7b42638b819abadf062729c6573532915ccb1ff8b9b2a8bca9324adf3950640555c721a650cfdd73512935442548d9087
|
data/CHANGELOG.md
CHANGED
data/lib/garage_client/client.rb
CHANGED
@@ -58,17 +58,6 @@ module GarageClient
|
|
58
58
|
|
59
59
|
def connection
|
60
60
|
Faraday.new(headers: headers, url: endpoint) do |builder|
|
61
|
-
if options[:tracing]
|
62
|
-
case options[:tracing][:tracer]
|
63
|
-
when 'aws-xray'
|
64
|
-
service = options[:tracing][:service]
|
65
|
-
raise 'Configure target service name with `tracing.service`' unless service
|
66
|
-
builder.use Aws::Xray::Faraday, service
|
67
|
-
else
|
68
|
-
raise "`tracing` option specified but GarageClient does not support the tracer: #{options[:tracing][:tracer]}"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
61
|
# Response Middlewares
|
73
62
|
builder.use Faraday::Response::Logger if verbose
|
74
63
|
builder.use FaradayMiddleware::Mashify
|
@@ -81,6 +70,18 @@ module GarageClient
|
|
81
70
|
builder.use GarageClient::Request::JsonEncoded
|
82
71
|
builder.use GarageClient::Request::PropagateRequestId
|
83
72
|
|
73
|
+
# Tracing Middlewares
|
74
|
+
if options[:tracing]
|
75
|
+
case options[:tracing][:tracer]
|
76
|
+
when 'aws-xray'
|
77
|
+
service = options[:tracing][:service]
|
78
|
+
raise 'Configure target service name with `tracing.service`' unless service
|
79
|
+
builder.use Aws::Xray::Faraday, service
|
80
|
+
else
|
81
|
+
raise "`tracing` option specified but GarageClient does not support the tracer: #{options[:tracing][:tracer]}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
84
85
|
# Low-level Middlewares
|
85
86
|
apply_auth_middleware builder
|
86
87
|
builder.adapter(*adapter)
|
@@ -21,13 +21,13 @@ RSpec.describe 'Tracing support' do
|
|
21
21
|
end
|
22
22
|
let(:stubs) do
|
23
23
|
Faraday::Adapter::Test::Stubs.new do |stub|
|
24
|
-
stub.get('/
|
24
|
+
stub.get('/campaign') { |env| [200, {'Content-Type' => 'application/json'}, '{"campaign": false}'] }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
specify 'client enables tracing and sends trace data to a local agent' do
|
29
|
-
res = client.get('/
|
30
|
-
expect(res.body.
|
29
|
+
res = client.get('/campaign')
|
30
|
+
expect(res.body.campaign).to eq(false)
|
31
31
|
|
32
32
|
io.rewind
|
33
33
|
sent_jsons = io.read.split("\n")
|
@@ -35,5 +35,48 @@ RSpec.describe 'Tracing support' do
|
|
35
35
|
body = JSON.parse(sent_jsons[1])
|
36
36
|
expect(body['name']).to eq('target-app')
|
37
37
|
end
|
38
|
+
|
39
|
+
context 'API returns client errors' do
|
40
|
+
let(:stubs) do
|
41
|
+
Faraday::Adapter::Test::Stubs.new do |stub|
|
42
|
+
stub.get('/campaign') { |env| [404, {'Content-Type' => 'application/json'}, '{"error": "not_found"}'] }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
specify 'client traces HTTP request and response and records errors' do
|
47
|
+
expect { client.get('/campaign') }.to raise_error(GarageClient::NotFound)
|
48
|
+
|
49
|
+
io.rewind
|
50
|
+
sent_jsons = io.read.split("\n")
|
51
|
+
expect(sent_jsons.size).to eq(2)
|
52
|
+
body = JSON.parse(sent_jsons[1])
|
53
|
+
expect(body['name']).to eq('target-app')
|
54
|
+
expect(body['error']).to eq(true)
|
55
|
+
expect(body['http']['request']['method']).to eq('GET')
|
56
|
+
expect(body['http']['response']['status']).to eq(404)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'API returns server errors' do
|
61
|
+
let(:stubs) do
|
62
|
+
Faraday::Adapter::Test::Stubs.new do |stub|
|
63
|
+
stub.get('/campaign') { |env| [500, {'Content-Type' => 'application/json'}, '{"error": "internal_server_error"}'] }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
specify 'client traces HTTP request and response and marks as fault' do
|
68
|
+
expect { client.get('/campaign') }.to raise_error(GarageClient::InternalServerError)
|
69
|
+
|
70
|
+
io.rewind
|
71
|
+
sent_jsons = io.read.split("\n")
|
72
|
+
expect(sent_jsons.size).to eq(2)
|
73
|
+
body = JSON.parse(sent_jsons[1])
|
74
|
+
expect(body['name']).to eq('target-app')
|
75
|
+
expect(body['error']).to eq(false)
|
76
|
+
expect(body['fault']).to eq(true)
|
77
|
+
expect(body['http']['request']['method']).to eq('GET')
|
78
|
+
expect(body['http']['response']['status']).to eq(500)
|
79
|
+
end
|
80
|
+
end
|
38
81
|
end
|
39
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garage_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cookpad Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|