Skip to content

Commit 4a9cff3

Browse files
authored
Merge pull request #72 from reddit/update_docs
Update docs
2 parents 728a950 + 3de4934 commit 4a9cff3

File tree

7 files changed

+220
-96
lines changed

7 files changed

+220
-96
lines changed

docs/conf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
master_doc = "index"
3939

4040
# General information about the project.
41-
project = "Experiments"
41+
project = "Experiments.py"
4242

4343
# The language for content autogenerated by Sphinx. Refer to documentation
4444
# for a list of supported languages.
@@ -54,7 +54,7 @@
5454
# -- Options for HTML output ----------------------------------------------
5555

5656
html_theme_path = [alabaster.get_path()]
57-
html_static_path = []
57+
html_static_path = ["images"]
5858

5959
# The theme to use for HTML and HTML Help pages. See the documentation for
6060
# a list of builtin themes.
@@ -67,7 +67,7 @@
6767
# which templates to put in the sidebar. we're just removing the relations
6868
# section from the defaults here, that's "next article" and "previous article"
6969
html_sidebars = {
70-
"**": []
70+
"**": ["about.html", "searchbox.html", "navigation.html"]
7171
}
7272

7373
html_theme_options = {
@@ -76,6 +76,7 @@
7676
"github_repo": "experiments.py",
7777
"github_user": "reddit",
7878
"github_banner": True,
79+
"logo": "ddg-logo.png",
7980
"logo_name": True,
8081
"show_powered_by": False,
8182
"show_related": False,

docs/images/ddg-logo.png

52.4 KB
Loading

docs/images/favicon.png

2.79 KB
Loading

docs/index.rst

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
``reddit_experiments``
1+
.. _reddit_decider:
2+
3+
``reddit_decider``
24
===============================
35

46
.. automodule:: reddit_decider
57

68

79
Prerequisite packages
8-
-------
10+
---------------------
911
.. code-block:: python
1012
1113
baseplate>=2.0.0
@@ -18,13 +20,13 @@ Prerequisite packages
1820
reddit-v2-events
1921
2022
Prerequisite infrastructure
21-
-------
23+
---------------------------
2224
Set up your service to pull down & synchronize experiment configurations from Zookeeper via the Baseplate `live-data watcher sidecar
2325
<https://baseplate.readthedocs.io/en/stable/api/baseplate/lib/live_data.html?highlight=sidecar#watcher-daemon>`_ (minimum v2.4.13).
2426
You'll have to make sure that your service is authorized to fetch the appropriate secret from Vault.
2527

26-
Prerequisite configuration:
27-
-------
28+
Prerequisite configuration
29+
---------------------------
2830
Setup :code:`reddit-experiments` in your application's configuration file:
2931

3032
.. code-block:: ini
@@ -50,7 +52,18 @@ Setup :code:`reddit-experiments` in your application's configuration file:
5052
5153
5254
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+
5467
In your service's initialization process, add a :code:`decider` instance to baseplate's context:
5568
(Note the use of the :code:`ExperimentLogger`, which is used to publish exposure V2 events,
5669
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-
6881
def make_wsgi_app(app_config):
6982
baseplate = Baseplate(app_config)
7083
decider_factory = decider_client_from_config(app_config=app_config,
71-
event_logger=ExperimentLogger,
84+
event_logger=ExperimentLogger(),
7285
prefix="experiments.",
7386
request_field_extractor=my_field_extractor) # this is optional, can be `None` if edge_context contains all the fields you need
7487
baseplate.add_to_context("decider", decider_factory)
@@ -78,11 +91,11 @@ an example can be seen `here <https://github.snooguts.net/reddit/reddit-service-
7891
baseplate.configure_context({
7992
"decider": DeciderClient(
8093
prefix="experiments.",
81-
event_logger=EventLogger,
94+
event_logger=ExperimentLogger,
8295
request_field_extractor=my_field_extractor # optional
8396
})
8497
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:
8699
87100
.. code-block:: python
88101
@@ -108,16 +121,17 @@ Make sure :code:`edge_context` is accessible on :code:`request` object like so:
108121
109122
# Customized fields can be defined below to be extracted from a baseplate request
110123
# and will override above edge_context fields.
124+
# These fields may be used for targeting.
111125
112126
def my_field_extractor(request):
113127
# an example of customized baseplate request field extractor:
114128
return {"foo": request.headers.get("Foo"), "bar": "something"}
115129
116130
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)::
121135
122136
def my_method(request):
123137
if request.decider.get_variant("foo") == "bar":
@@ -130,20 +144,32 @@ or optionally, if manual exposure is necessary, use::
130144
...
131145
request.decider.expose(experiment_name='experiment_name', variant_name=variant)
132146
133-
Configuration Classes
134-
-------------
135147
136-
.. autofunction:: decider_client_from_config
148+
Decider API
149+
-----------
137150
151+
.. autoclass:: Decider
152+
:members:
153+
154+
Configuration Class
155+
-------------------
138156
139157
.. autoclass:: DeciderClient
140158
159+
Configuration Function
160+
----------------------
161+
162+
.. autofunction:: decider_client_from_config
163+
164+
165+
Configuration Context Factory
166+
-----------------------------
141167
142168
.. autoclass:: DeciderContextFactory
143169
170+
Legacy API docs:
171+
----------------
144172
145-
Decider API
146-
-------
173+
.. toctree::
147174
148-
.. autoclass:: Decider
149-
:members:
175+
legacy/index

docs/legacy/index.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
``reddit_experiments (legacy)``
2+
===============================
3+
4+
.. automodule:: reddit_experiments
5+
6+
Please consider upgrading your service to use the latest :ref:`reddit_decider` SDK
7+
to gain access to new features, such as **Mutually Exclusive Groups**, **Holdout Groups**, and **Dynamic Configurations**.
8+
9+
10+
Initialize :py:class:`~reddit_experiments.Experiments` instance on Baseplate context
11+
------------------------------------------------------------------------------------
12+
13+
Add the :code:`Experiments` client to your application via::
14+
15+
baseplate.configure_context(
16+
{
17+
...
18+
"experiments": ExperimentsClient(event_logger),
19+
...
20+
}
21+
)
22+
23+
or alternatively using::
24+
25+
experiments_factory = experiments_client_from_config(
26+
app_config=app_config,
27+
event_logger=ExperimentLogger
28+
)
29+
baseplate.add_to_context("experiments", experiments_factory)
30+
31+
32+
Configure :py:class:`~reddit_experiments.Experiments` client
33+
------------------------------------------------------------
34+
35+
Configure the client in your application's configuration file:
36+
37+
.. code-block:: ini
38+
39+
[app:main]
40+
41+
...
42+
43+
# optional: a path to the file where experiment configuration is written
44+
# (default: /var/local/experiments.json)
45+
experiments.path = /var/local/foo.json
46+
47+
# optional: how long to wait for the experiments file to exist before failing
48+
# (default: do not wait. fail immediately if not available)
49+
experiments.timeout = 60 seconds
50+
51+
# optional: the base amount of time for exponential backoff while waiting
52+
# for the file to be available.
53+
# (default: no backoff time between tries)
54+
experiments.backoff = 1 second
55+
56+
...
57+
58+
59+
Usage
60+
-----
61+
Use the attached :py:class:`~reddit_experiments.Experiments` object in
62+
request to get a variant::
63+
64+
def my_method(request):
65+
if request.experiments.variant("foo") == "bar":
66+
pass
67+
68+
Experiments API
69+
---------------
70+
71+
.. autoclass:: Experiments
72+
:members:
73+
74+
Configuration Class
75+
-------------------
76+
77+
.. autoclass:: ExperimentsClient
78+
79+
Configuration Function
80+
----------------------
81+
82+
.. autofunction:: experiments_client_from_config
83+
84+
Configuration Context Factory
85+
-----------------------------
86+
87+
.. autoclass:: ExperimentsContextFactory
88+
89+
Link to Latest SDK
90+
------------------
91+
See :ref:`reddit_decider`

0 commit comments

Comments
 (0)