gitlab-experiment 0.4.2 → 0.4.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 +1 -1
- data/lib/generators/gitlab/experiment/install/templates/initializer.rb.tt +3 -3
- data/lib/gitlab/experiment.rb +14 -8
- data/lib/gitlab/experiment/caching.rb +13 -7
- data/lib/gitlab/experiment/configuration.rb +2 -1
- data/lib/gitlab/experiment/cookies.rb +1 -1
- data/lib/gitlab/experiment/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65d5d515cf32a09ec81868e3688576ee7314ae1580a9dde67c5c733174b12604
|
4
|
+
data.tar.gz: 2b8008b7c47812b492355df4715d5aa53195a852e46a1dd1a5e1b427a2bb9560
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ecd4bad77738fbf1c624970c9206c21f72b1c6e4efe59ffba6145959d4e3e1221d0cda709c0d086a849af4063074bbd9e0fa04ddc623589cd623c4dabd50705
|
7
|
+
data.tar.gz: 774e0605346863a8f05a28cedf0bb9884412e0ff1b90fcb359cf02be469e46638dbdeb611e0d8298b6d2e6c21b46f4b772f12e9e092b253e68266fa66ce7ed8e
|
data/README.md
CHANGED
@@ -388,7 +388,7 @@ Each of these approaches could be desirable given the objectives of your experim
|
|
388
388
|
## Development
|
389
389
|
|
390
390
|
After checking out the repo, run `bundle install` to install dependencies.
|
391
|
-
Then, run `bundle exec
|
391
|
+
Then, run `bundle exec rake` to run the tests. You can also run `bundle exec pry` for an
|
392
392
|
interactive prompt that will allow you to experiment.
|
393
393
|
|
394
394
|
## Contributing
|
@@ -25,17 +25,17 @@ Gitlab::Experiment.configure do |config|
|
|
25
25
|
# Logic this project uses to resolve a variant for a given experiment.
|
26
26
|
#
|
27
27
|
# Should return a symbol or string that represents the variant that should
|
28
|
-
# be assigned.
|
28
|
+
# be assigned. Blank or nil values will be defaulted to the control.
|
29
29
|
#
|
30
30
|
# This block is executed within the scope of the experiment and so can access
|
31
31
|
# experiment methods, like `name`, `context`, and `signature`.
|
32
32
|
config.variant_resolver = lambda do |requested_variant|
|
33
33
|
# Run the control, unless a variant was requested in code:
|
34
|
-
requested_variant
|
34
|
+
requested_variant
|
35
35
|
|
36
36
|
# Run the candidate, unless a variant was requested, with a fallback:
|
37
37
|
#
|
38
|
-
# requested_variant || variant_names.first ||
|
38
|
+
# requested_variant || variant_names.first || nil
|
39
39
|
end
|
40
40
|
|
41
41
|
# Tracking behavior can be implemented to link an event to an experiment.
|
data/lib/gitlab/experiment.rb
CHANGED
@@ -76,11 +76,22 @@ module Gitlab
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def variant(value = nil)
|
79
|
+
if value.blank? && @variant_name || @resolving_variant
|
80
|
+
return Variant.new(name: (@variant_name || :unresolved).to_s)
|
81
|
+
end
|
82
|
+
|
79
83
|
@variant_name = value unless value.blank?
|
80
84
|
@variant_name ||= :control if excluded?
|
81
85
|
|
82
|
-
|
83
|
-
|
86
|
+
@resolving_variant = true
|
87
|
+
resolved = :control
|
88
|
+
if (result = cache_variant(@variant_name) { resolve_variant_name }).present?
|
89
|
+
@variant_name = resolved = result.to_sym
|
90
|
+
end
|
91
|
+
|
92
|
+
Variant.new(name: resolved.to_s)
|
93
|
+
ensure
|
94
|
+
@resolving_variant = false
|
84
95
|
end
|
85
96
|
|
86
97
|
def exclude(&block)
|
@@ -150,12 +161,7 @@ module Gitlab
|
|
150
161
|
protected
|
151
162
|
|
152
163
|
def resolve_variant_name
|
153
|
-
|
154
|
-
|
155
|
-
@resolving = true
|
156
|
-
result = instance_exec(@variant_name, &Configuration.variant_resolver)
|
157
|
-
@resolving = false
|
158
|
-
result
|
164
|
+
instance_exec(@variant_name, &Configuration.variant_resolver)
|
159
165
|
end
|
160
166
|
|
161
167
|
def generate_result(variant_name)
|
@@ -3,20 +3,26 @@
|
|
3
3
|
module Gitlab
|
4
4
|
class Experiment
|
5
5
|
module Caching
|
6
|
-
def
|
7
|
-
|
6
|
+
def cache_variant(specified = nil, &block)
|
7
|
+
cache = Configuration.cache
|
8
|
+
return (specified.presence || yield) unless cache
|
8
9
|
|
9
10
|
key, migrations = cache_strategy
|
10
|
-
migrated_cache(cache, migrations || [], key)
|
11
|
+
result = migrated_cache(cache, migrations || [], key) || cache.fetch(key, &block)
|
12
|
+
return result unless specified.present?
|
13
|
+
|
14
|
+
cache.write(cache_key, specified) if result != specified
|
15
|
+
specified
|
16
|
+
end
|
17
|
+
|
18
|
+
def cache_key(key = nil)
|
19
|
+
"#{name}:#{key || context.signature[:key]}"
|
11
20
|
end
|
12
21
|
|
13
22
|
private
|
14
23
|
|
15
24
|
def cache_strategy
|
16
|
-
[
|
17
|
-
"#{name}:#{context.signature[:key]}",
|
18
|
-
context.signature[:migration_keys]&.map { |key| "#{name}:#{key}" }
|
19
|
-
]
|
25
|
+
[cache_key, context.signature[:migration_keys]&.map { |key| cache_key(key) }]
|
20
26
|
end
|
21
27
|
|
22
28
|
def migrated_cache(cache, migrations, new_key)
|
@@ -25,8 +25,9 @@ module Gitlab
|
|
25
25
|
@cookie_domain = :all
|
26
26
|
|
27
27
|
# Logic this project uses to resolve a variant for a given experiment.
|
28
|
+
# If no variant is determined, the control will be used.
|
28
29
|
@variant_resolver = lambda do |requested_variant|
|
29
|
-
requested_variant
|
30
|
+
requested_variant
|
30
31
|
end
|
31
32
|
|
32
33
|
# Tracking behavior can be implemented to link an event to an experiment.
|
@@ -11,7 +11,7 @@ module Gitlab
|
|
11
11
|
return hash if cookie_jar.nil?
|
12
12
|
|
13
13
|
resolver = [hash, :actor, cookie_name, cookie_jar.signed[cookie_name]]
|
14
|
-
resolve_cookie(*resolver)
|
14
|
+
resolve_cookie(*resolver) || generate_cookie(*resolver)
|
15
15
|
end
|
16
16
|
|
17
17
|
def cookie_jar
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-experiment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitLab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11
|
11
|
+
date: 2020-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|