libhoney 1.17.0 → 1.18.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
  SHA256:
3
- metadata.gz: 6719a46aa4b4c931245ac715b38067689a74bde968b7608eab89d893cecb3d5b
4
- data.tar.gz: 599d25bebae44849f68745be004463a7d35d40d82620c625b81c6506bace3787
3
+ metadata.gz: 33a687ebf8ae87e69cf6a53b50c4e2cd926f9938af709635d42a209ec2e6c93e
4
+ data.tar.gz: fd3f558a15f872c9f63fc6451722c3e9e21b7cba5ebe8d7816ec0cb08064318b
5
5
  SHA512:
6
- metadata.gz: 1497b4236a659be4a017c8206fc3ae04bb4f569335bdabd8c492e7429a94eb13943e96313bab302dd89e9011457c9f58cc7f004ee7ceac3c4c3d1ca347651d35
7
- data.tar.gz: 02a9f65930f3be3d3ccb43817eab5a48c8bd0a5869bd65b7bc8de2b865283e575f35fe6fa88717afb197f514cfebe5196e37d1e293a8fa3d59a5fd0e4d0358f2
6
+ metadata.gz: 36efc5d9734e125cd141e21dd60edbc6cf23350334bf431dead264c375dfd11b54bcf286f5509d5e97633ee4ce2d4fc689ebf5033d472237d5b6e7e2f2d0cb81
7
+ data.tar.gz: 5d5147a6e9f3fc1055a94932943c5915c99f43ad550d4dd5f20955d2dad023c41a1939e6f8037b38856375a10dcdc51557b06e3d56b454296a1596c7dd62b74c
@@ -16,6 +16,7 @@ Metrics/BlockLength:
16
16
  Metrics/ClassLength:
17
17
  Max: 200
18
18
  Exclude:
19
+ - lib/libhoney/transmission.rb # Should this remain so large?
19
20
  - test/*
20
21
 
21
22
  Metrics/MethodLength:
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## changes pending release
4
4
 
5
+ ## 1.18.0
6
+
7
+ ### Improvements
8
+
9
+ - replace HTTP client library to reduce external dependencies (#81)
10
+
11
+ ### Deprecations
12
+
13
+ - `Libhoney::Client.new(proxy_config: _)`: the `proxy_config` parameter for client
14
+ creation will no longer accept an Array in the next major version. The recommended
15
+ way to configure the client for operation behind forwarding web proxies is to set
16
+ http/https/no_proxy environment variables appropriately.
17
+
5
18
  ## 1.17.0
6
19
 
7
20
  ### Fixes:
@@ -1,6 +1,6 @@
1
+ require 'addressable/uri'
1
2
  require 'time'
2
3
  require 'json'
3
- require 'http'
4
4
  require 'forwardable'
5
5
 
6
6
  require 'libhoney/null_transmission'
@@ -51,6 +51,13 @@ module Libhoney
51
51
  # @param block_on_responses [Boolean] if true, block if there is no thread reading from the response queue
52
52
  # @param pending_work_capacity [Fixnum] defaults to 1000. If the queue of
53
53
  # pending events exceeds 1000, this client will start dropping events.
54
+ # @param proxy_config [String, Array, nil] proxy connection information
55
+ # nil: (default, recommended) connection proxying will be determined from any http_proxy, https_proxy, and no_proxy environment
56
+ # variables set for the process.
57
+ # String: the value must be the URI for connecting to a forwarding web proxy. Must be parsable by stdlib URI.
58
+ # Array: (deprecated, removal in v2.0) the value must have one and at most four elements: e.g. ['host', port, 'username', 'password'].
59
+ # The assumption is that the TCP connection will be tunneled via HTTP, so the assumed scheme is 'http://'
60
+ # 'host' is required. 'port' is optional (default:80), unless a 'username' is included. 'password' is optional.
54
61
  # rubocop:disable Metrics/ParameterLists
55
62
  def initialize(writekey: nil,
56
63
  dataset: nil,
@@ -102,7 +109,7 @@ module Libhoney
102
109
  @pending_work_capacity = pending_work_capacity
103
110
  @responses = SizedQueue.new(2 * @pending_work_capacity)
104
111
  @lock = Mutex.new
105
- @proxy_config = proxy_config
112
+ @proxy_config = parse_proxy_config(proxy_config)
106
113
  end
107
114
 
108
115
  attr_reader :block_on_send, :block_on_responses, :max_batch_size,
@@ -224,5 +231,35 @@ module Libhoney
224
231
  def should_drop(sample_rate)
225
232
  rand(1..sample_rate) != 1
226
233
  end
234
+
235
+ private
236
+
237
+ # @api private
238
+ def parse_proxy_config(config)
239
+ case config
240
+ when nil then nil
241
+ when String
242
+ URI.parse(config)
243
+ when Array
244
+ warn <<-WARNING
245
+ DEPRECATION WARNING: #{self.class.name} the proxy_config parameter will require a String value, not an Array in libhoney 2.0.
246
+ To resolve:
247
+ + recommended: set http/https_proxy environment variables, which take precedence over any option set here, then remove proxy_config parameter from client initialization
248
+ + set proxy_config to a String containing the forwarding proxy URI (only used if http/https_proxy are not set)
249
+ WARNING
250
+ host, port, user, password = config
251
+
252
+ parsed_config = URI::HTTP.build(host: host, port: port).tap do |uri|
253
+ uri.userinfo = "#{user}:#{password}" if user
254
+ end
255
+ redacted_config = parsed_config.dup.tap do |uri|
256
+ uri.password = 'REDACTED' unless uri.password.nil? || uri.password.empty?
257
+ end
258
+ warn "The array config given has been assumed to mean: #{redacted_config}"
259
+ parsed_config
260
+ end
261
+ rescue URI::Error => e
262
+ warn "#{self.class.name}: unable to parse proxy_config. Detail: #{e.class}: #{e.message}"
263
+ end
227
264
  end
228
265
  end
@@ -1,7 +1,15 @@
1
- require 'http'
1
+ require 'http/response/status'
2
2
 
3
3
  module Libhoney
4
4
  class Response
5
+ # The response status from HTTP calls to a Honeycomb API endpoint.
6
+ #
7
+ # For most of the life of this client, this response object has been
8
+ # a pass-through to the underlying HTTP library's response object.
9
+ # This class in the Libhoney namespace now owns the interface for
10
+ # API responses.
11
+ class Status < HTTP::Response::Status; end
12
+
5
13
  attr_accessor :duration, :status_code, :metadata, :error
6
14
 
7
15
  def initialize(duration: 0,
@@ -9,7 +17,7 @@ module Libhoney
9
17
  metadata: nil,
10
18
  error: nil)
11
19
  @duration = duration
12
- @status_code = HTTP::Response::Status.new(status_code)
20
+ @status_code = Status.new(status_code)
13
21
  @metadata = metadata
14
22
  @error = error
15
23
  end
@@ -1,3 +1,5 @@
1
+ require 'addressable/uri'
2
+ require 'excon'
1
3
  require 'json'
2
4
  require 'timeout'
3
5
  require 'libhoney/response'
@@ -93,7 +95,7 @@ module Libhoney
93
95
  }
94
96
 
95
97
  response = http.post(
96
- "/1/batch/#{Addressable::URI.escape(dataset)}",
98
+ path: "/1/batch/#{Addressable::URI.escape(dataset)}",
97
99
  body: body,
98
100
  headers: headers
99
101
  )
@@ -103,6 +105,8 @@ module Libhoney
103
105
  # because this is effectively the top-level exception handler for the
104
106
  # sender threads, and we don't want those threads to die (leaving
105
107
  # nothing consuming the queue).
108
+ warn "#{self.class.name}: 💥 " + e.message if %w[debug trace].include?(ENV['LOG_LEVEL'])
109
+ warn e.backtrace.join("\n").to_s if ['trace'].include?(ENV['LOG_LEVEL'])
106
110
  begin
107
111
  batch.each do |event|
108
112
  # nil events in the batch should already have had an error
@@ -187,7 +191,7 @@ module Libhoney
187
191
 
188
192
  def process_response(http_response, before, batch)
189
193
  index = 0
190
- http_response.parse.each do |event|
194
+ JSON.parse(http_response.body).each do |event|
191
195
  index += 1 while batch[index].nil? && index < batch.size
192
196
  break unless (batched_event = batch[index])
193
197
 
@@ -256,14 +260,19 @@ module Libhoney
256
260
 
257
261
  def build_http_clients
258
262
  Hash.new do |h, api_host|
259
- client = HTTP.timeout(connect: @send_timeout, write: @send_timeout, read: @send_timeout)
260
- .persistent(api_host)
261
- .headers(
262
- 'User-Agent' => @user_agent,
263
- 'Content-Type' => 'application/json'
264
- )
265
-
266
- client = client.via(*@proxy_config) unless @proxy_config.nil?
263
+ client = ::Excon.new(
264
+ api_host,
265
+ persistent: true,
266
+ read_timeout: @send_timeout,
267
+ write_timeout: @send_timeout,
268
+ connect_timeout: @send_timeout,
269
+ proxy: @proxy_config,
270
+ headers: {
271
+ 'User-Agent' => @user_agent,
272
+ 'Content-Type' => 'application/json'
273
+ }
274
+ )
275
+
267
276
  h[api_host] = client
268
277
  end
269
278
  end
@@ -1,3 +1,3 @@
1
1
  module Libhoney
2
- VERSION = '1.17.0'.freeze
2
+ VERSION = '1.18.0'.freeze
3
3
  end
@@ -34,5 +34,6 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'yard'
35
35
  spec.add_development_dependency 'yardstick', '~> 0.9'
36
36
  spec.add_dependency 'addressable', '~> 2.0'
37
+ spec.add_dependency 'excon'
37
38
  spec.add_dependency 'http', '>= 2.0', '< 5.0'
38
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libhoney
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.0
4
+ version: 1.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Honeycomb.io Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-04 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: '2.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: excon
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: http
183
197
  requirement: !ruby/object:Gem::Requirement