Skip to content

Commit 9476184

Browse files
fscelliottMike Davis
authored andcommitted
agent docs for readme sync
exported from ReadMe fullstack project 6/12/20
1 parent 26f7fe0 commit 9476184

File tree

11 files changed

+680
-0
lines changed

11 files changed

+680
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
title: "Optimizely Agent"
3+
slug: "optimizely-agent"
4+
hidden: false
5+
metadata:
6+
title: "Optimizely Agent microservice - Optimizely Full Stack"
7+
createdAt: "2020-02-21T20:35:58.387Z"
8+
updatedAt: "2020-04-01T20:51:52.458Z"
9+
---
10+
Optimizely Agent is a stand-alone, open-source, and highly available microservice that provides major benefits over using Optimizely SDKs in certain use cases. The Agent [REST API](https://optimizely.github.io/docs/api/agent/) offers consolidated and simplified endpoints for accessing all the functionality of Optimizely Full Stack SDKs.
11+
12+
A typical production installation of Optimizely Agent is to run two or more services behind a load balancer or proxy. The service itself can be run via a Docker container or installed from source. See [Setup Optimizely Agent](doc:setup-optimizely-agent) for instructions on how to run Optimizely Agent.
13+
14+
###Example Implementation
15+
[block:image]
16+
{
17+
"images": [
18+
{
19+
"image": [
20+
"https://files.readme.io/b5c2fc4-Screen_Shot_2020-03-23_at_9.26.51_AM.png",
21+
"Screen Shot 2020-03-23 at 9.26.51 AM.png",
22+
3136,
23+
1711,
24+
"#e6ebf7"
25+
],
26+
"caption": "Click to Enlarge"
27+
}
28+
]
29+
}
30+
[/block]
31+
# Should I Use Optimizely Agent?
32+
33+
Here are some of the top reasons to consider using Optimizely Agent:
34+
35+
##1. Service Oriented Architecture (SOA)
36+
If you already separate some of your logic into services that might need to access the Optimizely decision APIs, we recommend using Optimizely Agent.
37+
38+
The images below compare implementation styles in a service-oriented architecture, first *without* using Optimizely Agent, which shows six SDK embedded instances:
39+
[block:image]
40+
{
41+
"images": [
42+
{
43+
"image": [
44+
"https://files.readme.io/f653562-Screen_Shot_2020-03-23_at_9.18.29_AM.png",
45+
"Screen Shot 2020-03-23 at 9.18.29 AM.png",
46+
2869,
47+
1786,
48+
"#f0f2fc"
49+
],
50+
"caption": "A diagram showing the use of SDKs installed on each service in a service oriented architecture \n(Click to Enlarge)"
51+
}
52+
]
53+
}
54+
[/block]
55+
Now *with* Agent, instead of installing the SDK six times, you create just one Optimizely instance: an HTTP API that every service can access as needed.
56+
57+
[block:image]
58+
{
59+
"images": [
60+
{
61+
"image": [
62+
"https://files.readme.io/be2c361-Screen_Shot_2020-03-23_at_9.18.59_AM.png",
63+
"Screen Shot 2020-03-23 at 9.18.59 AM.png",
64+
3032,
65+
1728,
66+
"#f2f4fc"
67+
],
68+
"caption": "A diagram showing the use of Optimizely Agent in a single service \n(Click to Enlarge)"
69+
}
70+
]
71+
}
72+
[/block]
73+
##2. Standardize Access Across Teams
74+
If you want to deploy Optimizely Full Stack once, then roll out the single implementation across a large number of teams, we recommend using Optimizely Agent.
75+
76+
By standardizing your teams' access to the Optimizely service, you can better enforce processes and implement governance around feature management and experimentation as a practice.
77+
78+
[block:image]
79+
{
80+
"images": [
81+
{
82+
"image": [
83+
"https://files.readme.io/befdfae-image_1.png",
84+
"image (1).png",
85+
2601,
86+
1451,
87+
"#ccd5d9"
88+
],
89+
"caption": "A diagram showing the central and standardized access to the Optimizely Agent service across an arbitrary number of teams.\n(Click to Enlarge)"
90+
}
91+
]
92+
}
93+
[/block]
94+
##3. Networking Centralization
95+
You don’t want many SDK instances connecting to Optimizely's cloud service from every node in your application. Optimizely Agent centralizes your network connection. Only one cluster of agent instances connects to Optimizely for tasks like update [datafiles](doc:get-the-datafile) and dispatch [events](doc:track-events).
96+
97+
##4. Languages
98+
You’re using a language that isn’t supported by a native SDK (i.e. Elixir, Scala, Perl). While its possible to create your own service using an Optimizely SDK of your choice, you could also customize the open-source Optimizely Agent to your needs without building the service layer on your own.
99+
100+
101+
#Reasons to *not* use Optimizely Agent
102+
If your use case wouldn't benefit greatly from Optimizely Agent, you should consider the below reasons to *not* use Optimizely Agent and review Optimizely's many [open-source SDKs](doc:sdk-reference-guides) instead.
103+
104+
##1. Latency
105+
If time to provide bucketing decisions is a primary concern for you, you may want to use an embedded Full Stack SDK rather than Optimizely Agent.
106+
[block:parameters]
107+
{
108+
"data": {
109+
"h-0": "Implementation Option",
110+
"h-1": "Decision Latency",
111+
"0-0": "Embedded SDK",
112+
"0-1": "microseconds",
113+
"1-0": "Optimizely Agent",
114+
"1-1": "milliseconds"
115+
},
116+
"cols": 2,
117+
"rows": 2
118+
}
119+
[/block]
120+
##2. Monolith
121+
If your app is constructed as a monolith, embedded SDKs might be easier to install and might be a more natural fit for your application and development practices.
122+
123+
##3. Velocity
124+
If you’re looking for the fastest way to get a single team up and running with deploying feature management and experimentation, embedding an SDK is the best option for you at first. You can always start using Optimizely Agent later, and it can even be used alongside Optimizely Full Stack SDKs running in another part of your stack.
125+
126+
#Best Practices
127+
While every implementation is different, you can review this section of best practices for tips on these commonly discussed topics.
128+
129+
130+
##How many Agent instances should I deploy?
131+
Agent can scale to large decision / event tracking volumes with relatively low CPU / memory specs. For example, at Optimizely, we scaled our deployment to 740 clients with a cluster of 12 agent instances, which in total use 6 vCPUs and 12GB RAM. You will likely need to focus more on network bandwidth than compute power.
132+
133+
##Using a load balancer
134+
Any standard load balancer should let you route traffic across your agent cluster. At Optimizely, we used an AWS Elastic Load Balancer (ELB) for our internal deployment. This allows us to transparently scale our agent cluster as internal demands increase.
135+
136+
##Synchronizing datafiles across Agent instances
137+
Agent offers eventual rather than strong consistency across datafiles.
138+
In detail, today, each agent instance maintains a dedicated, separate cache. Each agent instance persists an SDK instance for each SDK key your team uses. Agent instances automatically keep datafiles up to date for each SDK key instance so that you will have eventual consistency across the cluster. The rate of the datafile update can be [set as the configuration](doc:configure-optimizely-agent) value ```OPTIMIZELY_CLIENT_POLLINGINTERVAL``` (the default is 1 minute).
139+
Because SDKs are generally stateless today, they shouldn’t need to share data. We plan to add a common backing data store, so we invite you to share your feedback.
140+
If you require strong consistency across datafiles, then we recommend an active / passive deployment where all requests are made to a single vertically scaled host, with a passive, standby cluster available for high availability.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: "Set up Optimizely Agent"
3+
slug: "setup-optimizely-agent"
4+
hidden: false
5+
metadata:
6+
title: "Getting started with Agent - Optimizely Full Stack"
7+
createdAt: "2020-02-21T17:44:27.363Z"
8+
updatedAt: "2020-03-31T23:54:17.841Z"
9+
---
10+
## Running Agent from source (Linux / OSX)
11+
12+
To develop and compile Optimizely Agent from source:
13+
14+
1. Install [Golang](https://golang.org/dl/) version 1.13+ .
15+
2. Clone the [Optimizely Agent repo](https://github.com/optimizely/agent).
16+
3. From the repo directory, open a terminal and start Optimizely Agent:
17+
18+
```bash
19+
make setup
20+
```
21+
Then
22+
```bash
23+
make run
24+
```
25+
26+
This starts the Optimizely Agent with the default configuration in the foreground.
27+
28+
## Running Agent from source (Windows)
29+
30+
You can use a [helper script](https://github.com/optimizely/agent/blob/master/scripts/build.ps1) to install prerequisites (Golang, Git) and compile agent in a Windows environment. Take these steps:
31+
32+
1. Clone the [Optimizely Agent repo](https://github.com/optimizely/agent)
33+
2. From the repo directory, open a Powershell terminal and run
34+
35+
```bash
36+
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser
37+
38+
.\scripts\build.ps1
39+
40+
.\bin\optimizely.exe
41+
```
42+
43+
## Running Agent via Docker
44+
45+
If you have Docker installed, you can start Optimizely Agent as a container. Take these steps:
46+
47+
1. Pull the Docker image:
48+
49+
```bash
50+
docker pull optimizely/agent
51+
```
52+
By default this will pull the "latest" tag. You can also specify a specific version of Agent by providing the version as a tag to the docker command:
53+
54+
```bash
55+
docker pull optimizely/agent:X.Y.Z
56+
```
57+
58+
2. Run the docker container with:
59+
60+
```bash
61+
docker run -p 8080:8080 optimizely/agent
62+
```
63+
This will start Agent in the foreground and expose the container API port 8080 to the host.
64+
65+
3. (Optional) You can alter the configuration by passing in environment variables to the preceding command, without having to create a config.yaml file. See [configure optimizely agent](doc:configure-optimizely-agent) for more options.
66+
67+
Versioning:
68+
When a new version is released, 2 images are pushed to dockerhub. They are distinguished by their tags:
69+
- :latest (same as :X.Y.Z)
70+
- :alpine (same as :X.Y.Z-alpine)
71+
72+
The difference between latest and alpine is that latest is built `FROM scratch` while alpine is `FROM alpine`.
73+
- [latest Dockerfile](https://github.com/optimizely/agent/blob/master/scripts/dockerfiles/Dockerfile.static)
74+
- [alpine Dockerfile](https://github.com/optimizely/agent/blob/master/scripts/dockerfiles/Dockerfile.alpine)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: "Evaluate REST APIs"
3+
slug: "evaluate-rest-apis"
4+
hidden: false
5+
metadata:
6+
title: "Evaluate REST APIs - Optimizely Full Stack"
7+
createdAt: "2020-02-21T17:44:53.019Z"
8+
updatedAt: "2020-04-13T23:02:34.056Z"
9+
---
10+
Below is an example demonstrating the APIs capabilities. For brevity, we've chosen to illustrate the API usage with Python. Note that the API documentation is defined via an OpenAPI (Swagger) spec and can be viewed [here](https://optimizely.github.io/docs/api/agent/).
11+
12+
## Start an http session
13+
Each request made into Optimizely Agent is in the context of an Optimizely SDK Key. SDK Keys map API requests to a specific Optimizely Project and Environment. We can setup a global request header by using the `requests.Session` object.
14+
15+
16+
[block:code]
17+
{
18+
"codes": [
19+
{
20+
"code": "import requests\n\ns = requests.Session()\ns.headers.update({'X-Optimizely-SDK-Key': '<<YOUR-SDK-KEY>>'})",
21+
"language": "python"
22+
}
23+
]
24+
}
25+
[/block]
26+
The following examples will assume this session is being maintained.
27+
28+
## Get current environment configuration
29+
The `/v1/config` endpoint returns a manifest of the current working environment.
30+
31+
[block:code]
32+
{
33+
"codes": [
34+
{
35+
"code": "resp = s.get('http://localhost:8080/v1/config')\nenv = resp.json()\n\nfor key in env['featuresMap']:\n print(key)",
36+
"language": "python"
37+
}
38+
]
39+
}
40+
[/block]
41+
## Activate Feature
42+
The `/v1/activate?featureKey={key}` endpoint activates the feature for a given user. In Optimizely, activation is in the context of a given user to make the relative bucketing decision. In this case we'll provide a `userId` via the request body. The `userId` will be used to determine how the feature will be evaluated. Features can either be part of a Feature Test in which variations of feature variables are being measured against one another or a feature rollout, which progressively make the feature available to the selected audience.
43+
44+
From an API standpoint the presence of a Feature Test or Rollout is abstracted away from the response and only the resulting variation or enabled feature is returned.
45+
46+
47+
[block:code]
48+
{
49+
"codes": [
50+
{
51+
"code": "# single feature activate\nparams = { \"featureKey\": \"my-feature\" }\npayload = { \"userId\": \"test-user\" }\nresp = s.post(url = 'http://localhost:8080/v1/activate', params=params, json=payload)\n\nprint(resp.json())\n\n\n# multiple (bulk) feature activate\nparams = {\n \"featureKey\": [key for key in env['featuresMap']],\n \"experimentKey\": [key for key in env['experimentsMap']]\n}\nresp2 = s.post(url = 'http://localhost:8080/v1/activate', params=params, json=payload)\nprint(json.dumps(resp.json(), indent=4, sort_keys=True))",
52+
"language": "python"
53+
}
54+
]
55+
}
56+
[/block]
57+
The activate API is a POST to signal to the caller that there are side-effects. Namely, activation results in a "decision" event sent to Optimizely analytics for the purpose of analyzing Feature Test results. A "decision" will NOT be sent if the feature is simply part of a rollout.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: "Admin API"
3+
slug: "admin-api"
4+
hidden: false
5+
metadata:
6+
title: "Admin APIs - Optimizely Full Stack"
7+
createdAt: "2020-02-21T17:44:28.054Z"
8+
updatedAt: "2020-02-21T23:09:19.274Z"
9+
---
10+
The Admin API provides system information about the running process. This can be used to check the availability of the service, runtime information and operational metrics. By default the admin listener is configured on port 8088.
11+
12+
## Info
13+
14+
The `/info` endpoint provides basic information about the Optimizely Agent instance.
15+
16+
Example Request:
17+
```bash
18+
curl localhost:8088/info
19+
```
20+
21+
Example Response:
22+
```json
23+
{
24+
"version": "v0.10.0",
25+
"author": "Optimizely Inc.",
26+
"app_name": "optimizely"
27+
}
28+
```
29+
30+
## Health Check
31+
32+
The `/health` endpoint is used to determine service availability.
33+
34+
Example Request:
35+
```bash
36+
curl localhost:8088/health
37+
```
38+
39+
Example Response:
40+
```json
41+
{
42+
"status": "ok"
43+
}
44+
```
45+
46+
Agent will return a HTTP 200 - OK response if and only if all configured listeners are open and all external dependent services can be reached.
47+
A non-healthy service will return a HTTP 503 - Unavailable response with a descriptive message to help diagnose the issue.
48+
49+
This endpoint can used when placing Agent behind a load balancer to indicate whether a particular instance can receive inbound requests.
50+
51+
## Metrics
52+
53+
The `/metrics` endpoint exposes telemetry data of the running Optimizely Agent. The core runtime metrics are exposed via the go expvar package. Documentation for the various statistics can be found as part of the [mstats](https://golang.org/src/runtime/mstats.go) package.
54+
55+
Example Request:
56+
```bash
57+
curl localhost:8088/metrics
58+
```
59+
60+
Example Response:
61+
```json
62+
{
63+
"cmdline": [
64+
"bin/optimizely"
65+
],
66+
"memstats": {
67+
"Alloc": 924136,
68+
"TotalAlloc": 924136,
69+
"Sys": 71893240,
70+
"Lookups": 0,
71+
"Mallocs": 4726,
72+
"HeapAlloc": 924136,
73+
...
74+
"Frees": 172
75+
},
76+
...
77+
}
78+
```
79+
Custom metrics are also provided for the individual service endpoints and follow the pattern of:
80+
81+
```bash
82+
"timers.<metric-name>.counts": 0,
83+
"timers.<metric-name>.responseTime": 0,
84+
"timers.<metric-name>.responseTimeHist.p50": 0,
85+
"timers.<metric-name>.responseTimeHist.p90": 0,
86+
"timers.<metric-name>.responseTimeHist.p95": 0,
87+
"timers.<metric-name>.responseTimeHist.p99": 0,
88+
```

0 commit comments

Comments
 (0)