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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67db70f420fa5fc41a2a070c99dbbd37eb70f909
4
- data.tar.gz: a1caece74b9d92acfc6df7a7e5429e330969401f
3
+ metadata.gz: 8c9d279f5317c4beb50f7542c228b79e21082741
4
+ data.tar.gz: e82fee549ef03800c4a17fc10c0c351a9d704fbe
5
5
  SHA512:
6
- metadata.gz: 323b4e8bab3eca3cafcdffa6c83c5960b745b1ad7827298d79fd59ad7f44df3e29186a0a295766ae5d2864c29c7e593c671302fbc9b06c96a4a1e59ffd0882f7
7
- data.tar.gz: e7bf77480f8e5f46f511f7d66ecba31fdc5da866570a16c3fd683eb6d72e7046be0d65bcbc2b521960169e621193e45046891d11556f343dc175b34d3492848a
6
+ metadata.gz: 57a217f525aed34172d4e08192040d772d5a79a8c7bb396b133c83f4e500ec27729ae9f7bad093565b0a7b66c2486c5a18b138023bd0d1baefa950a40a22ec70
7
+ data.tar.gz: 0b5d6f3ebdc2149acd28519ae99a67e7b42638b819abadf062729c6573532915ccb1ff8b9b2a8bca9324adf3950640555c721a650cfdd73512935442548d9087
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.4.1
2
+ - Record http request/response even if API returns errors.
3
+
1
4
  ## 2.4.0
2
5
  - Support distributed tracing.
3
6
 
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module GarageClient
2
- VERSION = '2.4.0'
2
+ VERSION = '2.4.1'
3
3
  end
@@ -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('/campain') { |env| [200, {'Content-Type' => 'application/json'}, '{"campain": false}'] }
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('/campain')
30
- expect(res.body.campain).to eq(false)
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.0
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-29 00:00:00.000000000 Z
11
+ date: 2017-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport