amplitude-experiment 1.1.3 → 1.1.4

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: 79931b2e41b024a2ae5503ff41321635959bfe3ea12ebdec92d565c03ef75072
4
- data.tar.gz: f7247ded087e26ad540f22e3e306c8870c33c241e408f214c98839020acddccc
3
+ metadata.gz: da33da0e966b08a4172225241b5a89b4d0b8c0b91af484b6ebaf33aa8e27fb21
4
+ data.tar.gz: 22176a1dcf52fcc64035eb2fc914e891718846e93b83d9f8b29faa5437ca759b
5
5
  SHA512:
6
- metadata.gz: be36e288fa8892698c510b810580834445f75959511ea15b38fec4b079ca91235c920a27ed9ce6f69c6e05609d2b31db6c79cd0d888e59dde68eb7c74e849cf1
7
- data.tar.gz: a2d892e60a65bd0f9a4b85d8994aeb26bf9b27d97a7397b8d6999aa408797d84f534d25d9d3a6c967def88c0ee0d313bc349dddd1f5b0a45224e65a656261c9b
6
+ metadata.gz: f41ba9124f0f65dec01fe7223a1ce0ba5337e1e93afc9e73b97a2b73442bd95e71f7c8c3c15afc2ed9aa3fa2c3af758171c7910721dc15a00a299b510810c1e2
7
+ data.tar.gz: 6d3a204bae5dc360865018a0fe0cf3dd5c3cc6add4f3ef925556c05c75668a066aa476f2ef07eb475d999d8bdf7b8ad586fc5e593c9777dc7e618096ce800631
@@ -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.4'.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.4
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-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych