-
Notifications
You must be signed in to change notification settings - Fork 221
/
helpers.rs
240 lines (233 loc) · 7.32 KB
/
helpers.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use crate::{AppContext, Experiment, NimbusTargetingHelper, TargetingAttributes};
use serde_json::json;
cfg_if::cfg_if! {
if #[cfg(feature = "stateful")] {
use crate::behavior::EventStore;
use std::sync::{Arc, Mutex};
}
}
impl From<TargetingAttributes> for NimbusTargetingHelper {
fn from(value: TargetingAttributes) -> Self {
cfg_if::cfg_if! {
if #[cfg(feature = "stateful")] {
let store = Arc::new(Mutex::new(EventStore::new()));
NimbusTargetingHelper::new(value, store)
} else {
NimbusTargetingHelper::new(value)
}
}
}
}
impl Default for NimbusTargetingHelper {
fn default() -> Self {
cfg_if::cfg_if! {
if #[cfg(feature = "stateful")] {
let ctx: AppContext = Default::default();
let store = Arc::new(Mutex::new(EventStore::new()));
NimbusTargetingHelper::new(ctx, store)
} else {
let ctx: AppContext = Default::default();
NimbusTargetingHelper::new(ctx)
}
}
}
}
pub(crate) fn get_test_experiments() -> Vec<Experiment> {
vec![
serde_json::from_value(json!({
"schemaVersion": "1.0.0",
"slug": "secure-gold",
"endDate": null,
"featureIds": ["some_control"],
"branches":[
{
"slug": "control",
"ratio": 1,
"feature": {
"featureId": "some_control",
"enabled": false,
"value": {
"text": "OK then",
"number": 42
}
}
},
{
"slug": "treatment",
"ratio":1,
"feature": {
"featureId": "some_control",
"enabled": true,
"value": {
"text": "OK then",
"number": 42
}
}
}
],
"channel": "nightly",
"probeSets":[],
"startDate":null,
"appName": "fenix",
"appId": "org.mozilla.fenix",
"bucketConfig":{
// Setup to enroll everyone by default.
"count":10_000,
"start":0,
"total":10_000,
"namespace":"secure-gold",
"randomizationUnit":"nimbus_id"
},
"userFacingName":"Diagnostic test experiment",
"referenceBranch":"control",
"isEnrollmentPaused":false,
"proposedEnrollment":7,
"userFacingDescription":"This is a test experiment for diagnostic purposes.",
"id":"secure-gold",
"last_modified":1_602_197_324_372i64
}))
.unwrap(),
serde_json::from_value(json!({
"schemaVersion": "1.0.0",
"slug": "secure-silver",
"endDate": null,
"branches":[
{
"slug": "control",
"ratio": 1,
"feature": {
"featureId": "about_welcome",
"enabled": true,
}
},
{
"slug": "treatment",
"ratio": 1,
"feature": {
"featureId": "about_welcome",
"enabled": false,
}
},
],
"featureIds": ["about_welcome"],
"channel": "nightly",
"probeSets":[],
"startDate":null,
"appName":"fenix",
"appId":"org.mozilla.fenix",
"bucketConfig":{
// Also enroll everyone.
"count":10_000,
"start":0,
"total":10_000,
"namespace":"secure-silver",
"randomizationUnit":"nimbus_id"
},
"userFacingName":"2nd test experiment",
"referenceBranch":"control",
"isEnrollmentPaused":false,
"proposedEnrollment":7,
"userFacingDescription":"2nd test experiment.",
"id":"secure-silver",
"last_modified":1_602_197_324_372i64
}))
.unwrap(),
]
}
pub fn get_ios_rollout_experiment() -> Experiment {
serde_json::from_value(json!(
{
"appId": "org.mozilla.ios.Firefox",
"appName": "firefox_ios",
"application": "org.mozilla.ios.Firefox",
"arguments": {},
"branches": [
{
"feature": {
"enabled": true,
"featureId": "coordinators-refactor-feature",
"value": {
"enabled": true
}
},
"ratio": 1,
"slug": "control"
}
],
"bucketConfig": {
"count": 10000,
"namespace": "ios-coordinators-refactor-feature-release-no_targeting-rollout-1",
"randomizationUnit": "nimbus_id",
"start": 0,
"total": 10000
},
"channel": "release",
"endDate": null,
"enrollmentEndDate": null,
"featureIds": [
"coordinators-refactor-feature"
],
"featureValidationOptOut": false,
"id": "ios-coordinators-rollout",
"isEnrollmentPaused": false,
"isRollout": true,
"localizations": null,
"outcomes": [],
"probeSets": [],
"proposedDuration": 28,
"proposedEnrollment": 7,
"referenceBranch": "control",
"schemaVersion": "1.12.0",
"slug": "ios-coordinators-rollout",
"startDate": null,
"targeting": "(app_version|versionCompare('114.!') >= 0)",
"userFacingDescription": "Rollout of coordinators refactor.",
"userFacingName": "iOS Coordinators Rollout"
}))
.unwrap()
}
pub fn get_bucketed_rollout(slug: &str, count: i64) -> Experiment {
let feature_id = "a-feature";
serde_json::from_value(json!(
{
"schemaVersion": "1.0.0",
"slug": slug,
"endDate": null,
"branches":[
{
"slug": "control",
"ratio": 1,
"feature": {
"featureId": feature_id,
"enabled": true,
"value": {},
}
},
],
"isRollout": true,
"featureIds": [feature_id],
"channel": "nightly",
"probeSets": [],
"startDate": null,
"appName":"fenix",
"appId":"org.mozilla.fenix",
"bucketConfig":{
// Also enroll everyone.
"count": count,
"start": 0,
"total": 10_000,
"namespace":"secure-silver",
"randomizationUnit":"nimbus_id"
},
"userFacingName":"",
"referenceBranch":"control",
"isEnrollmentPaused":false,
"proposedEnrollment":7,
"userFacingDescription":"",
}
))
.unwrap()
}