amplitude-experiment 1.1.3 → 1.1.5

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: 79931b2e41b024a2ae5503ff41321635959bfe3ea12ebdec92d565c03ef75072
4
- data.tar.gz: f7247ded087e26ad540f22e3e306c8870c33c241e408f214c98839020acddccc
3
+ metadata.gz: d4c7cef3c90843aec26f85cc3706300eb1f6bff3f64c1db9b4162bdf20dc1119
4
+ data.tar.gz: bd937b2d414b7b52b3accf57de14ac556a1789f83dd1e5d1625727ae5c9a0222
5
5
  SHA512:
6
- metadata.gz: be36e288fa8892698c510b810580834445f75959511ea15b38fec4b079ca91235c920a27ed9ce6f69c6e05609d2b31db6c79cd0d888e59dde68eb7c74e849cf1
7
- data.tar.gz: a2d892e60a65bd0f9a4b85d8994aeb26bf9b27d97a7397b8d6999aa408797d84f534d25d9d3a6c967def88c0ee0d313bc349dddd1f5b0a45224e65a656261c9b
6
+ metadata.gz: c927c9bc9808738b641cdf6666e7fa3220dad2d68b275d2d9b4269ebedf5ade2cd421a4e7c77a4283d8c0c0cfd9be2579d209ac9e4430b989dcf6dd864b98b4b
7
+ data.tar.gz: b388bc2f602af8031e5fb01cdd862ea31149a142d0fcf559703cdb2a76554cc051a339be8e8670862a129669a09535342ed3a766411c931c9a1c1ec019dbd082
@@ -64,7 +64,7 @@ module AmplitudeExperiment
64
64
  def parse_results(result, flag_keys)
65
65
  variants = {}
66
66
  result.each do |key, value|
67
- next if value['isDefaultVariant'] || (flag_keys.empty? && flag_keys.include?(key))
67
+ next if value['isDefaultVariant'] || (!flag_keys.empty? && !flag_keys.include?(key))
68
68
 
69
69
  variant_key = value['variant']['key']
70
70
  variant_payload = value['variant']['payload']
@@ -9,7 +9,7 @@ module AmplitudeExperiment
9
9
  @api_key = api_key
10
10
  @server_url = server_url
11
11
  @logger = logger
12
- @http = PersistentHttpClient.get(server_url, { read_timeout: FLAG_CONFIG_TIMEOUT })
12
+ @http = PersistentHttpClient.get(server_url, { read_timeout: FLAG_CONFIG_TIMEOUT }, @api_key)
13
13
  end
14
14
 
15
15
  # Fetch local evaluation mode flag configs from the Experiment API server.
@@ -1,14 +1,20 @@
1
1
  module AmplitudeExperiment
2
- # Persist Http Client to reuse connection and reduce IO
2
+ # Persist Http Client to reuse connection and reduce IO. Connections are
3
+ # shared by api key.
4
+ #
5
+ # WARNING: these connections are not safe for concurrent requests. Callers
6
+ # must synchronize requests per connection.
3
7
  class PersistentHttpClient
4
8
  DEFAULT_OPTIONS = { read_timeout: 80 }.freeze
5
9
 
6
10
  class << self
7
11
  # url: URI / String
8
12
  # options: any options that Net::HTTP.new accepts
9
- def get(url, options = {})
13
+ # api_key: the deployment key for ensuring different deployments don't
14
+ # share connections.
15
+ def get(url, options, api_key)
10
16
  uri = url.is_a?(URI) ? url : URI(url)
11
- connection_manager.get_client(uri, options)
17
+ connection_manager.get_client(uri, options, api_key)
12
18
  end
13
19
 
14
20
  private
@@ -72,7 +78,7 @@ module AmplitudeExperiment
72
78
  self.last_used = Time.now
73
79
  end
74
80
 
75
- def get_client(uri, options)
81
+ def get_client(uri, options, api_key)
76
82
  mutex.synchronize do
77
83
  # refresh the last time a client was used,
78
84
  # this prevents the client from becoming stale
@@ -81,7 +87,7 @@ module AmplitudeExperiment
81
87
  # we use params as a cache key for clients.
82
88
  # 2 connections to the same host but with different
83
89
  # options are going to use different HTTP clients
84
- params = [uri.host, uri.port, options]
90
+ params = [uri.host, uri.port, options, api_key]
85
91
  client = clients_store[params]
86
92
 
87
93
  return client if client
@@ -99,7 +99,7 @@ module AmplitudeExperiment
99
99
  'Content-Type' => 'application/json;charset=utf-8'
100
100
  }
101
101
  read_timeout = timeout_millis / 1000 if (timeout_millis / 1000) > 0
102
- http = PersistentHttpClient.get(@uri, { read_timeout: read_timeout })
102
+ http = PersistentHttpClient.get(@uri, { read_timeout: read_timeout }, @api_key)
103
103
  request = Net::HTTP::Post.new(@uri, headers)
104
104
  request.body = user_context.to_json
105
105
  if request.body.length > 8000
@@ -1,3 +1,3 @@
1
1
  module AmplitudeExperiment
2
- VERSION = '1.1.3'.freeze
2
+ VERSION = '1.1.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amplitude-experiment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amplitude
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-13 00:00:00.000000000 Z
11
+ date: 2023-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych