vault-tools 0.6.2 → 0.6.3
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 +4 -4
- data/Gemfile.lock +9 -1
- data/lib/vault-tools.rb +2 -0
- data/lib/vault-tools/tracing.rb +79 -2
- data/lib/vault-tools/tracing/sidekiq_client.rb +37 -0
- data/lib/vault-tools/tracing/sidekiq_server.rb +54 -0
- data/lib/vault-tools/version.rb +1 -1
- data/test/tracing_test.rb +35 -0
- data/vault-tools.gemspec +1 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 003733a1fd2fb3c6924f3e69236f295bc838f5b2
|
4
|
+
data.tar.gz: 818aaedd087e4b62fab37ff04565b79ed2bb6731
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 424c9254b97085ec0c34f91d360e664ac7c0df66a77a7428db89acaf8277700db0a33c267ffb98f8e12d87b53766b8b2117b93e08dfda2a7aab040df4054c970
|
7
|
+
data.tar.gz: d21141eed390e9785e789e9dccf1c29bf77c2b52302240c04b61980af5dbc8d7631fe93387276396b8192087f07394676ddfe749aff9d469a2ae1574d2748ef0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vault-tools (0.6.
|
4
|
+
vault-tools (0.6.3)
|
5
5
|
aws-sdk (~> 1.0)
|
6
6
|
coderay
|
7
7
|
excon
|
@@ -26,6 +26,7 @@ GEM
|
|
26
26
|
nokogiri (~> 1)
|
27
27
|
coderay (1.1.2)
|
28
28
|
concurrent-ruby (1.0.5)
|
29
|
+
connection_pool (2.2.1)
|
29
30
|
dotenv (2.0.0)
|
30
31
|
excon (0.60.0)
|
31
32
|
faraday (0.14.0)
|
@@ -61,12 +62,18 @@ GEM
|
|
61
62
|
rack (>= 1.0)
|
62
63
|
rake (10.4.2)
|
63
64
|
rdoc (6.0.1)
|
65
|
+
redis (4.0.1)
|
64
66
|
rollbar (2.7.1)
|
65
67
|
multi_json
|
66
68
|
rr (1.1.2)
|
67
69
|
scrolls (0.9.0)
|
68
70
|
shotgun (0.9.1)
|
69
71
|
rack (>= 1.0)
|
72
|
+
sidekiq (5.1.1)
|
73
|
+
concurrent-ruby (~> 1.0)
|
74
|
+
connection_pool (~> 2.2, >= 2.2.0)
|
75
|
+
rack-protection (>= 1.5.0)
|
76
|
+
redis (>= 3.3.5, < 5)
|
70
77
|
sinatra (1.4.8)
|
71
78
|
rack (~> 1.5)
|
72
79
|
rack-protection (~> 1.4)
|
@@ -108,6 +115,7 @@ DEPENDENCIES
|
|
108
115
|
rake
|
109
116
|
rdoc
|
110
117
|
shotgun
|
118
|
+
sidekiq
|
111
119
|
vault-test-tools
|
112
120
|
vault-tools!
|
113
121
|
yard
|
data/lib/vault-tools.rb
CHANGED
@@ -101,4 +101,6 @@ require 'vault-tools/time'
|
|
101
101
|
require 'vault-tools/s3'
|
102
102
|
require 'vault-tools/statement_store'
|
103
103
|
require 'vault-tools/rollbar_helper'
|
104
|
+
require 'vault-tools/tracing/sidekiq_client'
|
105
|
+
require 'vault-tools/tracing/sidekiq_server'
|
104
106
|
require 'vault-tools/tracing'
|
data/lib/vault-tools/tracing.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
require 'zipkin-tracer'
|
2
|
+
|
1
3
|
module Vault
|
2
4
|
module Tracing
|
3
5
|
ZIPKIN_API_HOST_STAGING = 'https://zipkin-staging.heroku.tools'.freeze
|
4
6
|
|
5
|
-
# Injects the zipkin middleware into the Web class
|
7
|
+
# Injects the zipkin middleware into the Web class, add Zipkin middleware to
|
8
|
+
# Excon, and adds Zipkin middleware to Sidekiq.
|
6
9
|
#
|
7
10
|
# @example
|
8
11
|
# Vault::Tracing.configure
|
@@ -13,6 +16,31 @@ module Vault
|
|
13
16
|
|
14
17
|
Vault::Web.instance_eval { require 'zipkin-tracer' }
|
15
18
|
Vault::Web.use ZipkinTracer::RackHandler, config
|
19
|
+
setup_excon
|
20
|
+
setup_sidekiq
|
21
|
+
end
|
22
|
+
|
23
|
+
# Traces a local component. Useful to track down long running implementation
|
24
|
+
# methods within an app, instead of only tracing external calls.
|
25
|
+
#
|
26
|
+
# @param name [String] the name of the span to record in Zipkin.
|
27
|
+
# @param tracer [Constant] the const that should respond to :local_component_span
|
28
|
+
# @param options [Hash] the options to create a message with.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# Vault::Tracing.trace_local 'cashier_middleware_x', internal: true do
|
32
|
+
# # some expensive task
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# @yield [the_block_passed_in]
|
36
|
+
def self.trace_local(name, tracer = ZipkinTracer::TraceClient, **options)
|
37
|
+
return yield unless Vault::Tracing.enabled?
|
38
|
+
|
39
|
+
tracer.local_component_span(name) do |span|
|
40
|
+
span.name = name
|
41
|
+
span.record_tag('options', options.to_s) unless options.empty?
|
42
|
+
yield
|
43
|
+
end
|
16
44
|
end
|
17
45
|
|
18
46
|
# Configuration options for the Zipkin RackHandler.
|
@@ -20,7 +48,7 @@ module Vault
|
|
20
48
|
# @return [Hash] config options for Zipkin tracer
|
21
49
|
def self.config
|
22
50
|
{
|
23
|
-
service_name: Config.app_name,
|
51
|
+
service_name: "#{Config.app_name}.herokuapp.com",
|
24
52
|
service_port: 443,
|
25
53
|
json_api_host: Config[:zipkin_api_host],
|
26
54
|
sample_rate: (Config[:zipkin_sample_rate] || 0.1).to_f,
|
@@ -36,5 +64,54 @@ module Vault
|
|
36
64
|
Config[:zipkin_enabled] == 'true' &&
|
37
65
|
Config[:zipkin_api_host]
|
38
66
|
end
|
67
|
+
|
68
|
+
# Adds ZipkinTracer::ExconHandler to Excon's default middlewares if Excon is
|
69
|
+
# defined
|
70
|
+
#
|
71
|
+
# @private
|
72
|
+
#
|
73
|
+
# @return nil
|
74
|
+
def self.setup_excon
|
75
|
+
if add_to_excon_middlewares?
|
76
|
+
Excon.defaults[:middlewares].push(ZipkinTracer::ExconHandler)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
private_class_method :setup_excon
|
80
|
+
|
81
|
+
# Adds our SidekiqClient and SidekiqServer middlware to Sidekiq
|
82
|
+
#
|
83
|
+
# @private
|
84
|
+
#
|
85
|
+
# @return nil
|
86
|
+
def self.setup_sidekiq(sidekiq = Sidekiq)
|
87
|
+
return unless defined?(sidekiq)
|
88
|
+
sidekiq.configure_client do |config|
|
89
|
+
config.client_middleware do |chain|
|
90
|
+
chain.add Vault::Tracing::SidekiqClient
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
sidekiq.configure_server do |config|
|
95
|
+
config.client_middleware do |chain|
|
96
|
+
chain.add Vault::Tracing::SidekiqClient
|
97
|
+
end
|
98
|
+
config.server_middleware do |chain|
|
99
|
+
chain.add Vault::Tracing::SidekiqServer, Vault::Tracing.config
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
private_class_method :setup_excon
|
104
|
+
|
105
|
+
# Checks to see if Excon is defined and if the Zipkin middleware has already
|
106
|
+
# been inserted.
|
107
|
+
#
|
108
|
+
# @private
|
109
|
+
#
|
110
|
+
# @return [true] if Excon is defined and the middleware is not already
|
111
|
+
# inserted
|
112
|
+
def self.add_to_excon_middlewares?
|
113
|
+
defined?(Excon) && !Excon.defaults[:middlewares].include?(ZipkinTracer::ExconHandler)
|
114
|
+
end
|
115
|
+
private_class_method :add_to_excon_middlewares?
|
39
116
|
end
|
40
117
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Vault
|
2
|
+
module Tracing
|
3
|
+
# Tracing info for sidekiq, adding them as params
|
4
|
+
# This was lifted straight out of heroku/coal_car
|
5
|
+
class SidekiqClient
|
6
|
+
def trace_information(trace_id)
|
7
|
+
{
|
8
|
+
"trace_id" => trace_id.trace_id,
|
9
|
+
"parent_id" => trace_id.parent_id,
|
10
|
+
"span_id" => trace_id.span_id,
|
11
|
+
"sampled" => trace_id.sampled,
|
12
|
+
"flags" => trace_id.flags
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(worker_class, job, _queue)
|
17
|
+
trace_id = ::ZipkinTracer::TraceGenerator.new.next_trace_id
|
18
|
+
::ZipkinTracer::TraceContainer.with_trace_id(trace_id) do
|
19
|
+
job["zipkin_trace_information"] = trace_information(trace_id)
|
20
|
+
if trace_id.sampled?
|
21
|
+
::Trace.tracer.with_new_span(trace_id, "sidekiq") do |span|
|
22
|
+
local_endpoint = Trace.default_endpoint
|
23
|
+
klass = job["wrapped".freeze] || worker_class
|
24
|
+
span.record_tag("job_class",
|
25
|
+
klass,
|
26
|
+
::Trace::BinaryAnnotation::Type::STRING,
|
27
|
+
local_endpoint)
|
28
|
+
yield
|
29
|
+
end
|
30
|
+
else
|
31
|
+
yield
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Vault
|
2
|
+
module Tracing
|
3
|
+
# Tracing info for sidekiq
|
4
|
+
# This was lifted straight out of heroku/coal_car
|
5
|
+
class SidekiqServer
|
6
|
+
def initialize(config = nil)
|
7
|
+
@config = ZipkinTracer::Config.new(nil, config).freeze
|
8
|
+
@tracer = ZipkinTracer::TracerFactory.new.tracer(@config)
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(worker, job, _queue)
|
12
|
+
result = nil
|
13
|
+
id = trace_id(job)
|
14
|
+
klass = job["wrapped".freeze] || worker.class.to_s
|
15
|
+
::ZipkinTracer::TraceContainer.with_trace_id(id) do
|
16
|
+
if id.sampled?
|
17
|
+
@tracer.with_new_span(id, klass) do |span|
|
18
|
+
span.record("sidekiq.start")
|
19
|
+
result = yield
|
20
|
+
span.record("sidekiq.end")
|
21
|
+
end
|
22
|
+
else
|
23
|
+
yield
|
24
|
+
end
|
25
|
+
end
|
26
|
+
::Trace.tracer.flush! if ::Trace.tracer.respond_to?(:flush!)
|
27
|
+
result
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def trace_id(job)
|
33
|
+
info = job["zipkin_trace_information"]
|
34
|
+
if info
|
35
|
+
trace_id = info["trace_id"]
|
36
|
+
span_id = info["span_id"]
|
37
|
+
parent_span_id = info["parent_id"]
|
38
|
+
sampled = info["sampled"]
|
39
|
+
flags = info["flags"].to_i
|
40
|
+
else
|
41
|
+
trace_id = span_id = ::Trace.generate_id
|
42
|
+
parent_span_id = nil
|
43
|
+
sampled = sample?
|
44
|
+
flags = ::Trace::Flags::EMPTY
|
45
|
+
end
|
46
|
+
::Trace::TraceId.new(trace_id, parent_span_id, span_id, sampled, flags)
|
47
|
+
end
|
48
|
+
|
49
|
+
def sample?
|
50
|
+
rand < @config.sample_rate
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/vault-tools/version.rb
CHANGED
data/test/tracing_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'sidekiq'
|
2
3
|
|
3
4
|
class TracingTest < Vault::TestCase
|
4
5
|
# Anonymous Web Frontend
|
@@ -37,6 +38,10 @@ class TracingTest < Vault::TestCase
|
|
37
38
|
set_env('ZIPKIN_ENABLED', nil)
|
38
39
|
end
|
39
40
|
|
41
|
+
def test_service_name_gets_herokuapp
|
42
|
+
assert_equal 'test_app.herokuapp.com', Vault::Tracing.config[:service_name]
|
43
|
+
end
|
44
|
+
|
40
45
|
def test_configure_enabled
|
41
46
|
Vault::Tracing.configure
|
42
47
|
middleware_constants = app.middleware.map(&:first)
|
@@ -50,6 +55,23 @@ class TracingTest < Vault::TestCase
|
|
50
55
|
'Vault::Tracing.configure should return nil when not enabled'
|
51
56
|
end
|
52
57
|
|
58
|
+
def test_excon
|
59
|
+
enable
|
60
|
+
Vault::Tracing.configure
|
61
|
+
assert Excon.defaults[:middlewares].include?(ZipkinTracer::ExconHandler),
|
62
|
+
"Vault::Tracing.setup_excon should add ZipkinTracer::ExconHandler to excon's middleware"
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_sidekiq
|
66
|
+
enable
|
67
|
+
sidekiq_mock = Minitest::Mock.new
|
68
|
+
sidekiq_mock.expect :configure_server, true
|
69
|
+
sidekiq_mock.expect :configure_client, true
|
70
|
+
Vault::Tracing.setup_sidekiq(sidekiq_mock)
|
71
|
+
assert sidekiq_mock.verify,
|
72
|
+
'Vault::Tracing.setup_sidekiq should call ::configure_server, and ::configure_client on Sidekiq'
|
73
|
+
end
|
74
|
+
|
53
75
|
def test_enabled_true
|
54
76
|
assert Vault::Tracing.enabled?,
|
55
77
|
'Vault::Tracing.enabled? should return true when enabled'
|
@@ -60,4 +82,17 @@ class TracingTest < Vault::TestCase
|
|
60
82
|
refute Vault::Tracing.enabled?,
|
61
83
|
'Vault::Tracing.enabled? should return false when not enabled'
|
62
84
|
end
|
85
|
+
|
86
|
+
def test_trace_local_yield
|
87
|
+
result = Vault::Tracing.trace_local('testing', opt: 'foo') { 1 + 1 }
|
88
|
+
assert_equal 2, result, 'trace_local should yield the result of the block given'
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_trace_local_calls_tracer
|
92
|
+
tracer_mock = Minitest::Mock.new
|
93
|
+
tracer_mock.expect :local_component_span, true, ['testing']
|
94
|
+
Vault::Tracing.trace_local('testing', tracer_mock, opt: 'foo') { 1 + 1 }
|
95
|
+
assert tracer_mock.verify,
|
96
|
+
'trace_local should call :local_component_span on the tracer'
|
97
|
+
end
|
63
98
|
end
|
data/vault-tools.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vault-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Continanza
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-03-
|
12
|
+
date: 2018-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: scrolls
|
@@ -221,6 +221,20 @@ dependencies:
|
|
221
221
|
- - ">="
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
|
+
- !ruby/object:Gem::Dependency
|
225
|
+
name: sidekiq
|
226
|
+
requirement: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: '0'
|
231
|
+
type: :development
|
232
|
+
prerelease: false
|
233
|
+
version_requirements: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
235
|
+
- - ">="
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
224
238
|
- !ruby/object:Gem::Dependency
|
225
239
|
name: yard
|
226
240
|
requirement: !ruby/object:Gem::Requirement
|
@@ -273,6 +287,8 @@ files:
|
|
273
287
|
- lib/vault-tools/text_processor.rb
|
274
288
|
- lib/vault-tools/time.rb
|
275
289
|
- lib/vault-tools/tracing.rb
|
290
|
+
- lib/vault-tools/tracing/sidekiq_client.rb
|
291
|
+
- lib/vault-tools/tracing/sidekiq_server.rb
|
276
292
|
- lib/vault-tools/usage_db_tasks.rb
|
277
293
|
- lib/vault-tools/user.rb
|
278
294
|
- lib/vault-tools/vault_db_tasks.rb
|
@@ -313,7 +329,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
313
329
|
version: '0'
|
314
330
|
requirements: []
|
315
331
|
rubyforge_project:
|
316
|
-
rubygems_version: 2.
|
332
|
+
rubygems_version: 2.5.2.1
|
317
333
|
signing_key:
|
318
334
|
specification_version: 4
|
319
335
|
summary: Test classes, base web classes, and helpers - oh my!
|