hubstep 2.0.5 → 2.1.0

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: 800bdbd0987e5e9cadf9ece37153d38fc4d01b2e
4
- data.tar.gz: 306d8888b256a21c05f3ef4afedbbd83f06f1946
3
+ metadata.gz: 6daeef652b6059de7c8414e25607406ac11cc1d9
4
+ data.tar.gz: 90cbcab84a1aa56013c5830a9bb2759b8983af9c
5
5
  SHA512:
6
- metadata.gz: 5476d3dc052e07fe3b77744faea0acdbc7abc3f55172a7f64ffdff0ba069f08bcc88ce1536258f05cd69955c7d5935a7efe5414a587f16098e323fbb6f346a32
7
- data.tar.gz: c855f62403d5521ebe2321bb28788ae73603cf76cb316158e19f09fa4f39c5fafa328b5515f535deb8d5fa9e21244b000e121b2442b543e446948f17c197462b
6
+ metadata.gz: b4e9b64109349da07a79569580694a032746e4bc5ecc9a5f3d33f45b14409932e5b9b33385345e2131571d77d875df948561a8190abba22a7b8df3d5a6872233
7
+ data.tar.gz: cbc706f4afa3a8b2dfded9b02723bc0a769e5fc5f8aeb91467baadb52965b96202f45c2a27a6ab09ab30006ef5cb2f53ba12c63526df3041a6721df9903fafcc
data/.rubocop.yml CHANGED
@@ -5,6 +5,9 @@ AllCops:
5
5
  Exclude:
6
6
  - "bin/**/*"
7
7
  - "vendor/**/*"
8
+ Lint/AmbiguousBlockAssociation:
9
+ Exclude:
10
+ - "test/**/*"
8
11
 
9
12
  Metrics/BlockLength:
10
13
  Exclude:
@@ -19,9 +22,13 @@ Metrics/LineLength:
19
22
 
20
23
  Metrics/MethodLength:
21
24
  Max: 15
25
+ Exclude:
26
+ - "test/**/*"
22
27
 
23
28
  Metrics/AbcSize:
24
29
  Max: 17
30
+ Exclude:
31
+ - "test/**/*"
25
32
 
26
33
  Style/DoubleNegation:
27
34
  Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  source "https://rubygems.org"
3
4
 
4
5
  # Specify your gem's dependencies in hubstep.gemspec
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "bundler/gem_tasks"
3
4
  require "rake/testtask"
4
5
 
data/hubstep.gemspec CHANGED
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
+
3
4
  lib = File.expand_path("../lib", __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
  require "hubstep/version"
@@ -28,7 +29,7 @@ Gem::Specification.new do |spec|
28
29
  spec.add_development_dependency "bundler", "~> 1.13"
29
30
  spec.add_development_dependency "rake", "~> 10.0"
30
31
  spec.add_development_dependency "minitest", "~> 5.0"
31
- spec.add_development_dependency "rubocop", "~> 0.46.0"
32
+ spec.add_development_dependency "rubocop", "~> 0.49.0"
32
33
  spec.add_development_dependency "rack-test", "~> 0.6"
33
34
  spec.add_development_dependency "activesupport", "~> 4.0"
34
35
  spec.add_development_dependency "faraday", "~> 0.10"
@@ -78,8 +78,7 @@ module HubStep
78
78
  begin
79
79
  uri = self.class.uri_parser.parse(url.to_s)
80
80
  domain = uri.host
81
- rescue => e
82
- HubStep.instrumenter.instrument("hubstep.faraday.middleware.error", error: e)
81
+ rescue
83
82
  domain = nil
84
83
  end
85
84
 
@@ -132,14 +132,12 @@ module HubStep
132
132
  host = ENV["LIGHTSTEP_COLLECTOR_HOST"]
133
133
  port = ENV["LIGHTSTEP_COLLECTOR_PORT"]
134
134
  encryption = ENV["LIGHTSTEP_COLLECTOR_ENCRYPTION"]
135
- verbosity = Integer(ENV.fetch("LIGHTSTEP_TRANSPORT_VERBOSITY", 0))
136
135
  access_token = ENV["LIGHTSTEP_ACCESS_TOKEN"]
137
136
 
138
137
  if host && port && encryption && access_token
139
138
  HubStep::Transport::HTTPJSON.new(host: host,
140
139
  port: port.to_i,
141
140
  encryption: encryption,
142
- verbose: verbosity,
143
141
  access_token: access_token)
144
142
  else
145
143
  LightStep::Transport::Nil.new
@@ -5,47 +5,83 @@ require "net/http"
5
5
 
6
6
  unless LightStep::VERSION == '0.11.2'
7
7
  raise <<-MSG
8
- This monkey patch needs to be reviewed for LightStep versions other than 0.10.9.
9
- To review, diff the changes between the `LightStep::Transport::HTTPJSON#report`
10
- method and the `HubStep::Transport::HTTPJSON#report` method below and port any
11
- changes that seem necessary.
8
+ This custom transport needs to be reviewed for new LightStep versions.
9
+ To review, compare this implementation with `LightStep::Transport::HTTPJSON#report`
10
+ method and port any changes that seem necessary.
12
11
  MSG
13
12
  end
14
13
 
15
14
  module HubStep
16
15
  module Transport
17
- # HTTPJSON is a transport that sends reports via HTTP in JSON format.
18
- # It is thread-safe, however it is *not* fork-safe. When forking, all items
19
- # in the queue will be copied and sent in duplicate.
16
+ # HTTPJSON is our customized transport which add some additional
17
+ # instrumentation and performance improvements.
20
18
  #
21
- # When forking, you should first `disable` the tracer, then `enable` it from
22
- # within the fork (and in the parent post-fork). See
23
- # `examples/fork_children/main.rb` for an example.
24
- class HTTPJSON < LightStep::Transport::HTTPJSON
25
- # Queue a report for sending
26
- def report(report) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
27
- p report if @verbose >= 3
28
-
29
- HubStep.instrumenter.instrument('lightstep.transport.report', {}) do |payload|
30
- https = Net::HTTP.new(@host, @port)
31
- https.use_ssl = @encryption == ENCRYPTION_TLS
32
- req = Net::HTTP::Post.new('/api/v0/reports')
33
- req['LightStep-Access-Token'] = @access_token
34
- req['Content-Type'] = 'application/json'
35
- req['Connection'] = 'keep-alive'
36
- req.body = report.to_json
37
- res = https.request(req)
38
-
39
- payload[:request_body] = req.body
40
-
41
- puts res.to_s, res.body if @verbose >= 3
42
-
43
- payload[:response] = res
19
+ # Callback Notes: To provide some observability into this transport's
20
+ # operation, we allow a callback `on_report_callback` to be provided. This
21
+ # callback will be called with the signature (report, result, duration_ms)
22
+ # where result can be either the http response or an exception. This
23
+ # callback will be delivered while maintaining this transports mutex which
24
+ # should provide some measure of thread-safety for the caller.
25
+ class HTTPJSON < LightStep::Transport::Base
26
+ ENCRYPTION_TLS = 'tls'
27
+ ENCRYPTION_NONE = 'none'
28
+
29
+ # Initialize the transport
30
+ # @param host [String] host of the domain to the endpoind to push data
31
+ # @param port [Numeric] port on which to connect
32
+ # @param encryption [ENCRYPTION_TLS, ENCRYPTION_NONE] kind of encryption to use
33
+ # @param access_token [String] access token for LightStep server
34
+ # @param on_report_callback [method] Called after reporting has completed
35
+ # @return [HTTPJSON]
36
+ def initialize(host:, port:, encryption: ENCRYPTION_TLS, access_token:, on_report_callback: nil)
37
+ @on_report_callback = on_report_callback
38
+
39
+ raise Tracer::ConfigurationError, "host must be specified" if host.nil? || host.empty?
40
+ raise Tracer::ConfigurationError, "port must be specified" if port.nil?
41
+ raise Tracer::ConfigurationError, "access_token must be a string" unless String === access_token
42
+ raise Tracer::ConfigurationError, "access_token cannot be blank" if access_token.empty?
43
+
44
+ @access_token = access_token
45
+
46
+ # This mutex protects the use of our Net::HTTP instance which we
47
+ # maintain as a long lived connection. While a Lightstep::Transport is
48
+ # typically called only from within the reporting thread, there are
49
+ # some situations where this can be bypassed (directly calling `flush`
50
+ # for example)
51
+ @mutex = Mutex.new
52
+
53
+ @https = Net::HTTP.new(host, port)
54
+ @https.use_ssl = encryption == ENCRYPTION_TLS
55
+ end
56
+
57
+ def report(report)
58
+ start = Time.now
59
+
60
+ req = request report
61
+
62
+ @mutex.synchronize do
63
+ begin
64
+ res = @https.request(req)
65
+ rescue => e
66
+ res = e
67
+ ensure
68
+ @on_report_callback&.call(report, res, start)
69
+ end
44
70
  end
45
71
 
46
72
  nil
47
- rescue => e
48
- HubStep.instrumenter.instrument('lightstep.transport.error', error: e)
73
+ end
74
+
75
+ private
76
+
77
+ def request(report)
78
+ req = Net::HTTP::Post.new('/api/v0/reports')
79
+ req['LightStep-Access-Token'] = @access_token
80
+ req['Content-Type'] = 'application/json'
81
+ req['Connection'] = 'keep-alive'
82
+
83
+ req.body = report.to_json
84
+ req
49
85
  end
50
86
  end
51
87
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module HubStep
3
- VERSION = "2.0.5"
4
+ VERSION = "2.1.0"
4
5
  end
data/lib/hubstep.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "hubstep/tracer"
4
- require "hubstep/internal/instrumenter/noop"
5
4
  require "hubstep/version"
6
5
 
7
6
  require "socket"
@@ -27,23 +26,4 @@ module HubStep
27
26
  {}.freeze
28
27
  end
29
28
  end
30
-
31
- # setter for instrumenter that defaults to the Noop instrumenter
32
- #
33
- # instrumenter - an object that responds to the ActiveSupport::Notifications
34
- # interface, when omitted the Noop instrumenter will be used
35
- #
36
- def self.instrumenter=(instrumenter)
37
- @instrumenter = instrumenter
38
- end
39
-
40
- # getter for the instrumenter ivar. When the ivar isn't set it will
41
- # default to the Noop instrumenter
42
- #
43
- # instrumenter - an object that responds to the ActiveSupport::Notifications
44
- # interface, when omitted the Noop instrumenter will be used
45
- #
46
- def self.instrumenter(instrumenter: nil)
47
- @instrumenter ||= (instrumenter || HubStep::Internal::Instrumenter::Noop.new)
48
- end
49
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubstep
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lightstep
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.46.0
75
+ version: 0.49.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.46.0
82
+ version: 0.49.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rack-test
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -202,8 +202,6 @@ files:
202
202
  - lib/hubstep/failbot.rb
203
203
  - lib/hubstep/faraday/middleware.rb
204
204
  - lib/hubstep/instrumenter.rb
205
- - lib/hubstep/internal/instrumenter/memory.rb
206
- - lib/hubstep/internal/instrumenter/noop.rb
207
205
  - lib/hubstep/rack/middleware.rb
208
206
  - lib/hubstep/tracer.rb
209
207
  - lib/hubstep/transport/http_json.rb
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HubStep
4
- module Internal
5
- module Instrumenter
6
- # A memory instrumenter to be used in to test instrumentation. This class records
7
- # each instrument call in a HubStep::Internal::Instrumenter::Memory::Event instance
8
- # and stores the instance in an events array.
9
- class Memory
10
- class Event # rubocop:disable Style/Documentation
11
- attr_reader :name, :payload, :result
12
-
13
- def initialize(name, payload, result)
14
- @name = name
15
- @payload = payload
16
- @result = result
17
- end
18
- end
19
-
20
- def initialize
21
- @events = []
22
- end
23
-
24
- attr_reader :events
25
-
26
- def instrument(name, payload = {})
27
- payload = payload.dup
28
- result = (yield payload if block_given?)
29
- @events << Event.new(name, payload, result)
30
- result
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HubStep
4
- module Internal
5
- module Instrumenter
6
- # A noop instrumenter that fulfills the interface for ActiveSupport::Notifications
7
- # but does nothing. This is the default instrumenter when the client does not pass
8
- # one in
9
- class Noop
10
- def instrument(_name, payload = {})
11
- yield payload if block_given?
12
- end
13
- end
14
- end
15
- end
16
- end