gitlab-experiment 1.0.0 → 1.1.0
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 +4 -4
- data/README.md +41 -7
- data/lib/generators/gitlab/experiment/install/templates/initializer.rb.tt +8 -0
- data/lib/generators/rspec/experiment/templates/experiment_spec.rb.tt +1 -1
- data/lib/gitlab/experiment/configuration.rb +10 -0
- 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: 3305c24f350ec02a3ef81da742a6d108c7aef00623f8b2534f989f06ec4a2ba6
|
|
4
|
+
data.tar.gz: 5f9113235e1623a2012ea5e4c451ed41baeb847e5883951b95b44fd6d7fd40fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d7120d36eb59039dbe36eb728990b951b96b7aa118a0a73af32e18809eaed265d03dec4689b55c3118e14a252418c9c84c4e25f7c25573205c6ef5269e5f456f
|
|
7
|
+
data.tar.gz: 9233969833c74c432b187721a2b35a38e521fce3679bccf64f879b87c899e6202b0f60b047c5aa57aef10665816f3fd7b3d21f7e403b30424b1227017c9991b2
|
data/README.md
CHANGED
|
@@ -195,7 +195,9 @@ experiment(:pill_color, actor: User.first).run # => "red"
|
|
|
195
195
|
|
|
196
196
|
### Exclusion rules
|
|
197
197
|
|
|
198
|
-
Exclusion rules let us determine if a context should even be considered as something to include in an experiment. If
|
|
198
|
+
Exclusion rules let us determine if a context should even be considered as something to include in an experiment. If
|
|
199
|
+
we're excluding something, it means that we don't want to run the experiment in that case. This can be useful if you
|
|
200
|
+
only want to run experiments on new users for instance.
|
|
199
201
|
|
|
200
202
|
```ruby
|
|
201
203
|
class PillColorExperiment < Gitlab::Experiment # OR ApplicationExperiment
|
|
@@ -205,15 +207,40 @@ class PillColorExperiment < Gitlab::Experiment # OR ApplicationExperiment
|
|
|
205
207
|
end
|
|
206
208
|
```
|
|
207
209
|
|
|
208
|
-
In the previous example, we'll exclude all users named `'Richard'` as well as any account older than 2 weeks old. Not
|
|
210
|
+
In the previous example, we'll exclude all users named `'Richard'` as well as any account older than 2 weeks old. Not
|
|
211
|
+
only will they be immediately given the control behavior, but no events will be tracked in these cases either.
|
|
209
212
|
|
|
210
|
-
Exclusion rules are executed in the order they're defined. The first exclusion rule to produce a truthy result will halt
|
|
213
|
+
Exclusion rules are executed in the order they're defined. The first exclusion rule to produce a truthy result will halt
|
|
214
|
+
execution of further exclusion checks.
|
|
211
215
|
|
|
212
|
-
|
|
216
|
+
#### Excluding from within the experiment block
|
|
213
217
|
|
|
214
|
-
|
|
218
|
+
You can also exclude contexts dynamically from within the experiment block using the `exclude!` method. This provides a
|
|
219
|
+
convenient way to include exclusion logic directly within the experiment call:
|
|
215
220
|
|
|
216
|
-
|
|
221
|
+
```ruby
|
|
222
|
+
experiment(:pill_color, actor: current_user) do |e|
|
|
223
|
+
e.exclude! unless can?(current_user, :manage, project)
|
|
224
|
+
|
|
225
|
+
e.control { 'blue' }
|
|
226
|
+
e.candidate { 'red' }
|
|
227
|
+
end
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
This approach keeps the experiment logic wrapped nicely within the experiment block, rather than requiring you to wrap
|
|
231
|
+
the entire experiment call in conditional logic. When `exclude!` is called, the experiment will be excluded and return
|
|
232
|
+
the control behavior without tracking any events.
|
|
233
|
+
|
|
234
|
+
Note: Although tracking calls will be ignored on all exclusions, you may want to check exclusion yourself in expensive
|
|
235
|
+
custom logic by calling the `should_track?` or `excluded?` methods.
|
|
236
|
+
|
|
237
|
+
Note: When using exclusion rules it's important to understand that the control assignment is cached, which improves
|
|
238
|
+
future experiment run performance but can be a gotcha around caching.
|
|
239
|
+
|
|
240
|
+
Note: Exclusion rules aren't the best way to determine if an experiment is enabled. There's an `enabled?` method that
|
|
241
|
+
can be overridden to have a high-level way of determining if an experiment should be running and tracking at all. This
|
|
242
|
+
`enabled?` check should be as efficient as possible because it's the first early opt out path an experiment can
|
|
243
|
+
implement. This can be seen in [How it works](#how-it-works).
|
|
217
244
|
|
|
218
245
|
### Segmentation rules
|
|
219
246
|
|
|
@@ -770,7 +797,14 @@ Each of these approaches could be desirable given the objectives of your experim
|
|
|
770
797
|
|
|
771
798
|
After cloning the repo, run `bundle install` to install dependencies.
|
|
772
799
|
|
|
773
|
-
|
|
800
|
+
## Running tests
|
|
801
|
+
|
|
802
|
+
The test suite requires Redis to be running. [Install](https://redis.io/docs/latest/operate/oss_and_stack/install/archive/install-redis/) and start Redis (`redis-server`) before running tests.
|
|
803
|
+
|
|
804
|
+
Once Redis is running, execute the tests:
|
|
805
|
+
`bundle exec rake`
|
|
806
|
+
|
|
807
|
+
You can also run `bundle exec pry` for an interactive prompt that will allow you to experiment.
|
|
774
808
|
|
|
775
809
|
## Contributing
|
|
776
810
|
|
|
@@ -31,6 +31,14 @@ Gitlab::Experiment.configure do |config|
|
|
|
31
31
|
# nil, :all, or ['www.gitlab.com', '.gitlab.com']
|
|
32
32
|
config.cookie_domain = :all
|
|
33
33
|
|
|
34
|
+
# Mark experiment cookies as secure (HTTPS only).
|
|
35
|
+
#
|
|
36
|
+
# When set to true, cookies will have the secure flag set, meaning they
|
|
37
|
+
# will only be sent over HTTPS connections. Defaults to true.
|
|
38
|
+
#
|
|
39
|
+
# Set to false in development/test environments if needed:
|
|
40
|
+
# config.secure_cookie = Rails.env.production?
|
|
41
|
+
|
|
34
42
|
# The default rollout strategy.
|
|
35
43
|
#
|
|
36
44
|
# The recommended default rollout strategy when not using caching would
|
|
@@ -44,6 +44,15 @@ module Gitlab
|
|
|
44
44
|
"#{experiment.name}_id"
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
# Mark experiment cookies as secure (HTTPS only).
|
|
48
|
+
#
|
|
49
|
+
# When set to true, cookies will have the secure flag set, meaning they
|
|
50
|
+
# will only be sent over HTTPS connections. Defaults to true.
|
|
51
|
+
#
|
|
52
|
+
# Set to false in development/test environments if needed:
|
|
53
|
+
# config.secure_cookie = Rails.env.production?
|
|
54
|
+
@secure_cookie = true
|
|
55
|
+
|
|
47
56
|
# The default rollout strategy.
|
|
48
57
|
#
|
|
49
58
|
# The recommended default rollout strategy when not using caching would
|
|
@@ -177,6 +186,7 @@ module Gitlab
|
|
|
177
186
|
:cache,
|
|
178
187
|
:cookie_domain,
|
|
179
188
|
:cookie_name,
|
|
189
|
+
:secure_cookie,
|
|
180
190
|
:context_key_secret,
|
|
181
191
|
:context_key_bit_length,
|
|
182
192
|
:mount_at,
|
|
@@ -32,7 +32,7 @@ module Gitlab
|
|
|
32
32
|
|
|
33
33
|
cookie ||= SecureRandom.uuid
|
|
34
34
|
cookie_jar.permanent.signed[cookie_name] = {
|
|
35
|
-
value: cookie, secure:
|
|
35
|
+
value: cookie, secure: Configuration.secure_cookie, domain: domain, httponly: true
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
hash.merge(key => cookie)
|
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: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GitLab
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|