1
- ``reddit_experiments ``
1
+ .. _reddit_decider :
2
+
3
+ ``reddit_decider ``
2
4
===============================
3
5
4
6
.. automodule :: reddit_decider
5
7
6
8
7
9
Prerequisite packages
8
- -------
10
+ ---------------------
9
11
.. code-block :: python
10
12
11
13
baseplate>= 2.0 .0
@@ -18,13 +20,13 @@ Prerequisite packages
18
20
reddit- v2- events
19
21
20
22
Prerequisite infrastructure
21
- -------
23
+ ---------------------------
22
24
Set up your service to pull down & synchronize experiment configurations from Zookeeper via the Baseplate `live-data watcher sidecar
23
25
<https://baseplate.readthedocs.io/en/stable/api/baseplate/lib/live_data.html?highlight=sidecar#watcher-daemon> `_ (minimum v2.4.13).
24
26
You'll have to make sure that your service is authorized to fetch the appropriate secret from Vault.
25
27
26
- Prerequisite configuration:
27
- -------
28
+ Prerequisite configuration
29
+ ---------------------------
28
30
Setup :code: `reddit-experiments ` in your application's configuration file:
29
31
30
32
.. code-block :: ini
@@ -50,7 +52,18 @@ Setup :code:`reddit-experiments` in your application's configuration file:
50
52
51
53
52
54
Integrate :code: `reddit-experiments ` into Baseplate service
53
- -------
55
+ -----------------------------------------------------------
56
+
57
+ Upgrade or integrate reddit-experiments package:
58
+
59
+ .. code-block :: python
60
+
61
+ # import latest reddit-experiments package in service requirements.txt
62
+ reddit- experiments>= 1.3 .7
63
+
64
+ Initialize :code: `decider ` instance on Baseplate context
65
+ --------------------------------------------------------
66
+
54
67
In your service's initialization process, add a :code: `decider ` instance to baseplate's context:
55
68
(Note the use of the :code: `ExperimentLogger `, which is used to publish exposure V2 events,
56
69
an example can be seen `here <https://github.snooguts.net/reddit/reddit-service-graphql/blob/3734b51732c29d07eef32aced86677cce5064dbb/graphql-py/graphql_api/events/utils.py#L205 >`_)
@@ -68,7 +81,7 @@ an example can be seen `here <https://github.snooguts.net/reddit/reddit-service-
68
81
def make_wsgi_app (app_config ):
69
82
baseplate = Baseplate(app_config)
70
83
decider_factory = decider_client_from_config(app_config = app_config,
71
- event_logger = ExperimentLogger,
84
+ event_logger = ExperimentLogger() ,
72
85
prefix = " experiments." ,
73
86
request_field_extractor = my_field_extractor) # this is optional, can be `None` if edge_context contains all the fields you need
74
87
baseplate.add_to_context(" decider" , decider_factory)
@@ -78,11 +91,11 @@ an example can be seen `here <https://github.snooguts.net/reddit/reddit-service-
78
91
baseplate.configure_context({
79
92
" decider" : DeciderClient(
80
93
prefix = " experiments." ,
81
- event_logger = EventLogger ,
94
+ event_logger = ExperimentLogger ,
82
95
request_field_extractor = my_field_extractor # optional
83
96
})
84
97
85
- Make sure :code:`edge_context ` is accessible on :code:`request` object like so:
98
+ Make sure :code:`EdgeContext ` is accessible on :code:`request` object like so:
86
99
87
100
.. code- block:: python
88
101
@@ -108,16 +121,17 @@ Make sure :code:`edge_context` is accessible on :code:`request` object like so:
108
121
109
122
# Customized fields can be defined below to be extracted from a baseplate request
110
123
# and will override above edge_context fields.
124
+ # These fields may be used for targeting.
111
125
112
126
def my_field_extractor(request):
113
127
# an example of customized baseplate request field extractor:
114
128
return {" foo" : request.headers.get(" Foo" ), " bar" : " something" }
115
129
116
130
117
- Usage
118
- ------ -
119
- Use the attached :py:class :`~ reddit_decider.Decider` object in request and
120
- :code:`decider.get_variant()` (which will automatically send an expose event)::
131
+ Basic Usage
132
+ ---------- -
133
+ Use the attached :py:class :`~ reddit_decider.Decider` object in request to call
134
+ :code:`decider.get_variant()` (automatically sends an expose event)::
121
135
122
136
def my_method(request):
123
137
if request.decider.get_variant(" foo" ) == " bar" :
@@ -130,20 +144,32 @@ or optionally, if manual exposure is necessary, use::
130
144
...
131
145
request.decider.expose(experiment_name = ' experiment_name' , variant_name = variant)
132
146
133
- Configuration Classes
134
- ------------ -
135
147
136
- .. autofunction:: decider_client_from_config
148
+ Decider API
149
+ ---------- -
137
150
151
+ .. autoclass:: Decider
152
+ :members:
153
+
154
+ Configuration Class
155
+ ------------------ -
138
156
139
157
.. autoclass:: DeciderClient
140
158
159
+ Configuration Function
160
+ ----------------------
161
+
162
+ .. autofunction:: decider_client_from_config
163
+
164
+
165
+ Configuration Context Factory
166
+ ---------------------------- -
141
167
142
168
.. autoclass:: DeciderContextFactory
143
169
170
+ Legacy API docs:
171
+ ----------------
144
172
145
- Decider API
146
- ------ -
173
+ .. toctree::
147
174
148
- .. autoclass:: Decider
149
- :members:
175
+ legacy/ index
0 commit comments