promoted-ruby-client 0.1.6 → 0.1.7

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
  SHA256:
3
- metadata.gz: 30ba0e172809a6aa76284b4b88980fa45dea5b2bf28cdda4fbe8e672b7510a83
4
- data.tar.gz: e28586ed23f7db16b959bb9819072e502fc7af3805e68938f2bbf421fdc9e4d8
3
+ metadata.gz: 38925e54b884c3e36db632faa2481cd99621846848c21c80def989e1539a87d7
4
+ data.tar.gz: 6c0b3caedbef47b9ed6a5c5c1c9e58368031521c6f36181ae1a4938bd9f796fd
5
5
  SHA512:
6
- metadata.gz: 4e6b42f73ff30726aa81af1c08b97a0cd0e0307685dec1f90dcce5d0d61d4009c3a2e6179af77a600038531101db187a83dc52f46a7c0ad4a99f7c6c2530b43e
7
- data.tar.gz: f3d304f0a2aad7acc15229750f97b021da4c0bfe8deae40c6ac1110bc7c1621ab0db19635464ba835e4e9a9ec07b9cfa0c231a9163fa0e1dcffeeebfdc1e51fc
6
+ metadata.gz: eae233ce5d572a6e581a57572292edf212205ab15764ff41db98116506c548b0746a94be236d44dda1bb43d758005a25bef8bbcfb8816295f4de9f30efb75481
7
+ data.tar.gz: 5085fa33d2e4d040d134a69cc8af872b4c209bda2ddee1be1f51f3d7c3b948ac8300152a790fbcdadaa5dbb75902b94727d1b20575398d563b5aa6757cfc3ea4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- promoted-ruby-client (0.1.6)
4
+ promoted-ruby-client (0.1.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -28,10 +28,10 @@ This client will suffice for building log requests. To send actually send traffi
28
28
 
29
29
  ```rb
30
30
  client = Promoted::Ruby::Client::PromotedClient.new({
31
- :metrics_endpoint = "https://<get this from Promoted>",
32
- :delivery_endpoint = "https://<get this from Promoted>",
33
- :metrics_api_key = "<get this from Promoted>",
34
- :delivery_api_key = "<get this from Promoted>"
31
+ :metrics_endpoint => "https://<get this from Promoted>",
32
+ :delivery_endpoint => "https://<get this from Promoted>",
33
+ :metrics_api_key => "<get this from Promoted>",
34
+ :delivery_api_key => "<get this from Promoted>"
35
35
  })
36
36
  ```
37
37
 
data/dev.md CHANGED
@@ -4,5 +4,5 @@
4
4
  2. Get credentials for deployment from 1password.
5
5
  3. Modify `promoted-ruby-client.gemspec`'s push block.
6
6
  4. Run `gem build promoted-ruby-client.gemspec` to generate `gem`.
7
- 5. Run (using new output) `gem push promoted-ruby-client-0.1.6.gem`
7
+ 5. Run (using new output) `gem push promoted-ruby-client-0.1.7.gem`
8
8
  6. Update README with new version.
@@ -19,7 +19,9 @@ module Promoted
19
19
  class Error < StandardError; end
20
20
 
21
21
  attr_reader :perform_checks, :default_only_log, :delivery_timeout_millis, :metrics_timeout_millis, :should_apply_treatment_func,
22
- :default_request_headers, :http_client
22
+ :default_request_headers, :http_client, :logger, :shadow_traffic_delivery_percent, :async_shadow_traffic
23
+
24
+ attr_accessor :request_logging_on
23
25
 
24
26
  ##
25
27
  # A common compact method implementation.
@@ -39,7 +41,8 @@ module Promoted
39
41
  @perform_checks = params[:perform_checks]
40
42
  end
41
43
 
42
- @logger = params[:logger] # Example: Logger.new(STDERR, :progname => "promotedai")
44
+ @logger = params[:logger] # Example: Logger.new(STDERR, :progname => "promotedai")
45
+ @request_logging_on = params[:request_logging_on] || false
43
46
 
44
47
  @default_request_headers = params[:default_request_headers] || {}
45
48
  @metrics_api_key = params[:metrics_api_key] || ''
@@ -66,21 +69,31 @@ module Promoted
66
69
  @http_client = FaradayHTTPClient.new
67
70
  @validator = Promoted::Ruby::Client::Validator.new
68
71
 
69
- # Thread pool to process delivery of shadow traffic. Will silently drop excess requests beyond the queue
70
- # size, and silently eat errors on the background threads.
71
- @pool = Concurrent::ThreadPoolExecutor.new(
72
- min_threads: 0,
73
- max_threads: 10,
74
- max_queue: 100,
75
- fallback_policy: :discard
76
- )
72
+ @async_shadow_traffic = true
73
+ if params[:async_shadow_traffic] != nil
74
+ @async_shadow_traffic = params[:async_shadow_traffic] || false
75
+ end
76
+
77
+ @pool = nil
78
+ if @async_shadow_traffic
79
+ # Thread pool to process delivery of shadow traffic. Will silently drop excess requests beyond the queue
80
+ # size, and silently eat errors on the background threads.
81
+ @pool = Concurrent::ThreadPoolExecutor.new(
82
+ min_threads: 0,
83
+ max_threads: 10,
84
+ max_queue: 100,
85
+ fallback_policy: :discard
86
+ )
87
+ end
77
88
  end
78
89
 
79
90
  ##
80
91
  # Politely shut down a Promoted client.
81
92
  def close
82
- @pool.shutdown
83
- @pool.wait_for_termination
93
+ if @pool
94
+ @pool.shutdown
95
+ @pool.wait_for_termination
96
+ end
84
97
  end
85
98
 
86
99
  ##
@@ -211,20 +224,38 @@ module Promoted
211
224
  private
212
225
 
213
226
  def send_request payload, endpoint, timeout_millis, api_key, headers={}, send_async=false
227
+ resp = nil
228
+
214
229
  headers["x-api-key"] = api_key
215
230
  use_headers = @default_request_headers.merge headers
216
231
 
217
- if send_async
232
+ if @request_logging_on && @logger
233
+ @logger.info("promotedai") {
234
+ "Sending #{payload.to_json} to #{endpoint}"
235
+ }
236
+ end
237
+
238
+ if send_async && @pool
218
239
  @pool.post do
219
- @http_client.send(endpoint, timeout_millis, payload, use_headers)
240
+ start_time = Time.now.to_i
241
+ begin
242
+ resp = @http_client.send(endpoint, timeout_millis, payload, use_headers)
243
+ rescue Faraday::Error => err
244
+ @logger.warn("Deliver call failed with #{err}") if @logger
245
+ return
246
+ end
247
+ ellapsed_time = Time.now.to_i - start_time
248
+ @logger.info("Deliver call completed in #{ellapsed_time} ms") if @logger
220
249
  end
221
250
  else
222
251
  begin
223
- @http_client.send(endpoint, timeout_millis, payload, use_headers)
252
+ resp = @http_client.send(endpoint, timeout_millis, payload, use_headers)
224
253
  rescue Faraday::Error => err
225
254
  raise EndpointError.new(err)
226
255
  end
227
256
  end
257
+
258
+ return resp
228
259
  end
229
260
 
230
261
 
@@ -290,4 +321,5 @@ require "promoted/ruby/client/request_builder"
290
321
  require "promoted/ruby/client/sampler"
291
322
  require "promoted/ruby/client/util"
292
323
  require "promoted/ruby/client/validator"
293
- require 'securerandom'
324
+ require 'securerandom'
325
+ require 'time'
@@ -1,7 +1,7 @@
1
1
  module Promoted
2
2
  module Ruby
3
3
  module Client
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promoted-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - scottmcmaster
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-07 00:00:00.000000000 Z
11
+ date: 2021-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler