garage_client 2.3.3 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01091c33f1717e47d9c9924aafdf5847b365db08
4
- data.tar.gz: ab7c2d9b32b4231d4cb4d94620dc4c0adfc14f7e
3
+ metadata.gz: 67db70f420fa5fc41a2a070c99dbbd37eb70f909
4
+ data.tar.gz: a1caece74b9d92acfc6df7a7e5429e330969401f
5
5
  SHA512:
6
- metadata.gz: 8cbdf835d83bf950e9efa95d38bea94c2df496886fb5495e098e0648fb4092f34faba05acabd7c743e64d0892bcd90f16f9e49119a1115bae926e33091720b25
7
- data.tar.gz: 26a64ed17b4ae544897eea66ca80072ec9ec63760c213a4f05b24cc36ed66de55e57488f39c1224adee73625879fd8c93bf23292dcd297aef9af84af56ed2bf4
6
+ metadata.gz: 323b4e8bab3eca3cafcdffa6c83c5960b745b1ad7827298d79fd59ad7f44df3e29186a0a295766ae5d2864c29c7e593c671302fbc9b06c96a4a1e59ffd0882f7
7
+ data.tar.gz: e7bf77480f8e5f46f511f7d66ecba31fdc5da866570a16c3fd683eb6d72e7046be0d65bcbc2b521960169e621193e45046891d11556f343dc175b34d3492848a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.4.0
2
+ - Support distributed tracing.
3
+
1
4
  ## 2.3.3
2
5
  - Fix a bug to not resolve application name when garage_client-rails is bundled.
3
6
  - Stop to support ruby version < 2.2.2.
data/README.md CHANGED
@@ -93,10 +93,12 @@ There are the following options:
93
93
  - `adapter` - faraday adapter for http client (default: `:net_http`)
94
94
  - `cacher` - take a cacher class in which caching logic is defined (default: nil)
95
95
  - `name` - Client's application name, which is embedded in User-Agent by default (default: nil. For Rails, `Rails.application.class.parent_name.underscore` is set by default.)
96
+ - `name` must be configured globally.
96
97
  - `headers` - default http headers (default: `{ "Accept" => "application/json", "User-Agent" => "garage_client #{VERSION} #{name}" }`)
97
98
  - `endpoint` - Garage application API endpoint (default: nil)
98
99
  - `path_prefix` - API path prefix (default: `'/v1'`)
99
100
  - `verbose` - Enable verbose http log (default: `false`)
101
+ - `tracing` - (client instance only) Enable distributed tracing and set a logical name of the down stream service. See detail in "Tracing" section below.
100
102
 
101
103
  You can configure the global settings:
102
104
 
@@ -115,7 +117,6 @@ client = GarageClient::Client.new(
115
117
  adapter: :test,
116
118
  headers: { "Host" => "garage.example.com" },
117
119
  endpoint: "http://localhost:3000",
118
- name: 'my-awesome-client',
119
120
  path_prefix: "/v2",
120
121
  verbose: true,
121
122
  )
@@ -199,3 +200,17 @@ end
199
200
 
200
201
  GarageClient::Client.new(cacher: MyCacher)
201
202
  ```
203
+
204
+ ## Tracing
205
+ GarageClient supports distributed tracing. To enable tracing, specify `tracing.tracer` option for `GarageClient::Client` instance.
206
+ Choose one of supported tracers from below. If you want to add new tracer, please give us a PR.
207
+
208
+ ### aws-xray
209
+ Bundle [aws-xray](https://github.com/taiki45/aws-xray) gem in your `Gemfile`, then configure `GarageClient::Client` instance with `tracing.service` option:
210
+
211
+ ```ruby
212
+ require 'aws/xray'
213
+ GarageClient::Client.new(..., tracing: { tracer: 'aws-xray', service: 'user' })
214
+ ```
215
+
216
+ `service` will be `name` of the sub segments.
@@ -32,4 +32,5 @@ Gem::Specification.new do |s|
32
32
  s.add_development_dependency "pry"
33
33
  # Until bug fixed: https://github.com/colszowka/simplecov/issues/281
34
34
  s.add_development_dependency "simplecov", "~> 0.7.1"
35
+ s.add_development_dependency "aws-xray"
35
36
  end
@@ -11,7 +11,13 @@ module GarageClient
11
11
  if response
12
12
  # Faraday::Response#marshal_dump is drop request object and url
13
13
  # https://github.com/lostisland/faraday/blob/edacd5eb57ea13accab3097649690ae5f48f421a/lib/faraday/response.rb#L74
14
- response.env.merge!(@env) {|_, self_val, other_val| self_val || other_val }
14
+ #
15
+ # XXX: We can't use #merge! here because Faraday::Env does not implement
16
+ # the method as same as Hash#merge! with Faraday v0.12.1.
17
+ @env.each do |k, v|
18
+ original = response.env[k]
19
+ response.env[k] = v if !original && v
20
+ end
15
21
  else
16
22
  response = yield
17
23
  store.write(key, response, options) if written_to_cache?
@@ -20,6 +20,7 @@ module GarageClient
20
20
  property :path_prefix
21
21
  property :verbose
22
22
 
23
+ # @option opts [Hash] :tracing enable tracing. See README for detail.
23
24
  def initialize(options = {})
24
25
  require_necessaries(options)
25
26
  @options = options
@@ -57,6 +58,17 @@ module GarageClient
57
58
 
58
59
  def connection
59
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
+
60
72
  # Response Middlewares
61
73
  builder.use Faraday::Response::Logger if verbose
62
74
  builder.use FaradayMiddleware::Mashify
@@ -85,9 +97,6 @@ module GarageClient
85
97
  if !options[:endpoint] && !default_options.endpoint
86
98
  raise "Missing endpoint configuration"
87
99
  end
88
- if !options[:name] && !default_options.name
89
- raise "Missing name configuration"
90
- end
91
100
  end
92
101
 
93
102
  def default_options
@@ -1,3 +1,3 @@
1
1
  module GarageClient
2
- VERSION = '2.3.3'
2
+ VERSION = '2.4.0'
3
3
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'aws/xray'
3
+
4
+ RSpec.describe 'Tracing support' do
5
+ context 'when `tracing` option is specified' do
6
+ around do |ex|
7
+ Aws::Xray.config.client_options = { sock: io }
8
+ Aws::Xray.trace(name: 'test-app') { ex.run }
9
+ end
10
+
11
+ let(:io) { Aws::Xray::TestSocket.new }
12
+ let(:client) do
13
+ GarageClient::Client.new(
14
+ adapter: [:test, stubs],
15
+ endpoint: 'http://127.0.0.1',
16
+ tracing: {
17
+ tracer: 'aws-xray',
18
+ service: 'target-app',
19
+ },
20
+ )
21
+ end
22
+ let(:stubs) do
23
+ Faraday::Adapter::Test::Stubs.new do |stub|
24
+ stub.get('/campain') { |env| [200, {'Content-Type' => 'application/json'}, '{"campain": false}'] }
25
+ end
26
+ end
27
+
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)
31
+
32
+ io.rewind
33
+ sent_jsons = io.read.split("\n")
34
+ expect(sent_jsons.size).to eq(2)
35
+ body = JSON.parse(sent_jsons[1])
36
+ expect(body['name']).to eq('target-app')
37
+ end
38
+ end
39
+ 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.3.3
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cookpad Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-18 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: 0.7.1
181
+ - !ruby/object:Gem::Dependency
182
+ name: aws-xray
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  description: Ruby client library for the Garage API
182
196
  email:
183
197
  - kaihatsu@cookpad.com
@@ -210,6 +224,7 @@ files:
210
224
  - lib/garage_client/response/raise_http_exception.rb
211
225
  - lib/garage_client/version.rb
212
226
  - spec/features/configuration_spec.rb
227
+ - spec/features/tracing_spec.rb
213
228
  - spec/fixtures/example.yaml
214
229
  - spec/fixtures/examples.yaml
215
230
  - spec/fixtures/examples_dictionary.yaml
@@ -246,12 +261,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
261
  version: '0'
247
262
  requirements: []
248
263
  rubyforge_project:
249
- rubygems_version: 2.5.1
264
+ rubygems_version: 2.6.11
250
265
  signing_key:
251
266
  specification_version: 4
252
267
  summary: Ruby client library for the Garage API
253
268
  test_files:
254
269
  - spec/features/configuration_spec.rb
270
+ - spec/features/tracing_spec.rb
255
271
  - spec/fixtures/example.yaml
256
272
  - spec/fixtures/examples.yaml
257
273
  - spec/fixtures/examples_dictionary.yaml