amplitude-experiment 1.1.1 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/amplitude-experiment.gemspec +2 -2
- data/lib/experiment/factory.rb +4 -9
- data/lib/experiment/local/client.rb +4 -5
- data/lib/experiment/local/evaluation/evaluation.rb +9 -2
- data/lib/experiment/local/evaluation/lib/linuxArm64/libevaluation_interop.so +0 -0
- data/lib/experiment/local/evaluation/lib/linuxX64/libevaluation_interop.so +0 -0
- data/lib/experiment/local/evaluation/lib/macosArm64/libevaluation_interop.dylib +0 -0
- data/lib/experiment/local/evaluation/lib/macosX64/libevaluation_interop.dylib +0 -0
- data/lib/experiment/version.rb +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79931b2e41b024a2ae5503ff41321635959bfe3ea12ebdec92d565c03ef75072
|
4
|
+
data.tar.gz: f7247ded087e26ad540f22e3e306c8870c33c241e408f214c98839020acddccc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be36e288fa8892698c510b810580834445f75959511ea15b38fec4b079ca91235c920a27ed9ce6f69c6e05609d2b31db6c79cd0d888e59dde68eb7c74e849cf1
|
7
|
+
data.tar.gz: a2d892e60a65bd0f9a4b85d8994aeb26bf9b27d97a7397b8d6999aa408797d84f534d25d9d3a6c967def88c0ee0d313bc349dddd1f5b0a45224e65a656261c9b
|
data/README.md
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
# Experiment Ruby SDK
|
11
11
|
Amplitude Ruby Server SDK for Experiment.
|
12
12
|
|
13
|
+
> ⚠️ **Local evaluation process fork safety:** When using a `LocalEvaluationClient` and forking the process, you must call `#start` _after forking_ to update the flag configuration state on the new process. For example, in Puma, this means calling `#start` in the [`on_worker_boot` hook](https://www.rubydoc.info/gems/puma/Puma%2FDSL:on_worker_boot).
|
14
|
+
|
13
15
|
## Installation
|
14
16
|
Into Gemfile from rubygems.org:
|
15
17
|
```ruby
|
@@ -24,7 +26,6 @@ To install beta versions:
|
|
24
26
|
gem install amplitude-experiment --pre
|
25
27
|
```
|
26
28
|
|
27
|
-
|
28
29
|
## Remote Evaluation Quick Start
|
29
30
|
```ruby
|
30
31
|
require 'amplitude-experiment'
|
@@ -16,9 +16,10 @@ Gem::Specification.new do |spec|
|
|
16
16
|
'amplitude-experiment.gemspec',
|
17
17
|
'Gemfile',
|
18
18
|
'lib/experiment/local/evaluation/lib/**/*']
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
spec.extra_rdoc_files = ['README.md']
|
21
21
|
|
22
|
+
spec.add_development_dependency 'psych', '~> 4.0'
|
22
23
|
spec.add_development_dependency 'rake', '~> 13.0'
|
23
24
|
spec.add_development_dependency 'rdoc', '= 6.4'
|
24
25
|
spec.add_development_dependency 'rspec', '~> 3.6'
|
@@ -26,7 +27,6 @@ Gem::Specification.new do |spec|
|
|
26
27
|
spec.add_development_dependency 'simplecov', '~> 0.21'
|
27
28
|
spec.add_development_dependency 'webmock', '~> 3.14'
|
28
29
|
spec.add_development_dependency 'yard', '~> 0.9'
|
29
|
-
spec.add_development_dependency 'psych', '~> 4.0'
|
30
30
|
spec.metadata['rubygems_mfa_required'] = 'false'
|
31
31
|
spec.add_runtime_dependency 'ffi', '~> 1.15.5'
|
32
32
|
end
|
data/lib/experiment/factory.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
module AmplitudeExperiment
|
3
3
|
@local_instance = {}
|
4
4
|
@remote_instance = {}
|
5
|
-
@default_instance = '$default_instance'
|
6
5
|
|
7
6
|
# Initializes a singleton Client. This method returns a default singleton instance, subsequent calls to
|
8
7
|
# init will return the initial instance regardless of input.
|
@@ -10,10 +9,8 @@ module AmplitudeExperiment
|
|
10
9
|
# @param [String] api_key The environment API Key
|
11
10
|
# @param [Config] config Optional Config.
|
12
11
|
def self.initialize_remote(api_key, config = nil)
|
13
|
-
unless @
|
14
|
-
|
15
|
-
end
|
16
|
-
@local_instance.fetch(@default_instance)
|
12
|
+
@remote_instance.store(api_key, RemoteEvaluationClient.new(api_key, config)) unless @remote_instance.key?(api_key)
|
13
|
+
@remote_instance.fetch(api_key)
|
17
14
|
end
|
18
15
|
|
19
16
|
# Initializes a local evaluation Client. A local evaluation client can evaluate local flags or experiments for a
|
@@ -23,9 +20,7 @@ module AmplitudeExperiment
|
|
23
20
|
# @param [String] api_key The environment API Key
|
24
21
|
# @param [Config] config Optional Config.
|
25
22
|
def self.initialize_local(api_key, config = nil)
|
26
|
-
unless @
|
27
|
-
|
28
|
-
end
|
29
|
-
@remote_instance.fetch(@default_instance)
|
23
|
+
@local_instance.store(api_key, LocalEvaluationClient.new(api_key, config)) unless @local_instance.key?(api_key)
|
24
|
+
@local_instance.fetch(api_key)
|
30
25
|
end
|
31
26
|
end
|
@@ -38,9 +38,9 @@ module AmplitudeExperiment
|
|
38
38
|
|
39
39
|
user_str = user.to_json
|
40
40
|
@logger.debug("[Experiment] Evaluate: User: #{user_str} - Rules: #{flags}") if @config.debug
|
41
|
-
|
42
|
-
@logger.debug("[Experiment] evaluate - result: #{
|
43
|
-
|
41
|
+
result = evaluation(flags, user_str)
|
42
|
+
@logger.debug("[Experiment] evaluate - result: #{result}") if @config.debug
|
43
|
+
parse_results(result, flag_keys)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Fetch initial flag configurations and start polling for updates.
|
@@ -61,8 +61,7 @@ module AmplitudeExperiment
|
|
61
61
|
|
62
62
|
private
|
63
63
|
|
64
|
-
def
|
65
|
-
result = JSON.parse(results_json)
|
64
|
+
def parse_results(result, flag_keys)
|
66
65
|
variants = {}
|
67
66
|
result.each do |key, value|
|
68
67
|
next if value['isDefaultVariant'] || (flag_keys.empty? && flag_keys.include?(key))
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# rubocop:disable all
|
2
2
|
require 'ffi'
|
3
|
+
require 'json'
|
3
4
|
|
4
5
|
# The evaluation wrapper
|
5
6
|
module EvaluationInterop
|
@@ -59,7 +60,13 @@ end
|
|
59
60
|
def evaluation(rule_json, user_json)
|
60
61
|
lib = EvaluationInterop.libevaluation_interop_symbols()
|
61
62
|
fn = lib[:kotlin][:root][:evaluate]
|
62
|
-
|
63
|
-
|
63
|
+
result_json = fn.call(rule_json, user_json).read_string
|
64
|
+
result = JSON.parse(result_json)
|
65
|
+
if result["error"] != nil
|
66
|
+
raise "#{result["error"]}"
|
67
|
+
elsif result["result"] == nil
|
68
|
+
raise "Evaluation result is nil."
|
69
|
+
end
|
70
|
+
result["result"]
|
64
71
|
end
|
65
72
|
# rubocop:disable all
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/experiment/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amplitude-experiment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amplitude
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: psych
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,20 +122,6 @@ dependencies:
|
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0.9'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: psych
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '4.0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '4.0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: ffi
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|