Skip to content

Commit 82e909b

Browse files
authored
Merge branch 'main' into brown-bag-fun
2 parents e83b798 + 8553c83 commit 82e909b

File tree

34 files changed

+544
-227
lines changed

34 files changed

+544
-227
lines changed

.github/workflows/ads.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ jobs:
4343
context: ./services/ads/python
4444
platforms: linux/amd64,linux/arm64
4545
push: true
46-
tags: ghcr.io/datadog/storedog/ads:latest
46+
tags: ghcr.io/datadog/storedog/ads-python:latest
4747

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
IMAGES=(
4444
ghcr.io/datadog/storedog/backend
4545
ghcr.io/datadog/storedog/discounts
46-
ghcr.io/datadog/storedog/ads
46+
ghcr.io/datadog/storedog/ads-python
4747
ghcr.io/datadog/storedog/ads-java
4848
ghcr.io/datadog/storedog/nginx
4949
ghcr.io/datadog/storedog/frontend

README.md

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,31 @@ There are several features that can be enabled by setting environment variables
206206

207207
Run two Ads services and split traffic between them. The amount of traffic sent to each service is set with a percent value.
208208

209+
This requires running a second Ads service in addition to the default Java Ads service and setting environment variables in the `service-proxy` service. The Python Ads service is typically used as the secondary service.
210+
211+
1. Set an environment variable for the Python Ads service version.
212+
213+
```bash
214+
export DD_VERSION_ADS_PYTHON=1.0.0
215+
```
216+
217+
1. These environment variables need to be set for the `service-proxy` service.
218+
219+
- `ADS_A_UPSTREAM`: Host and port for the primary (A) ads service (default: `ads:3030`)
220+
- `ADS_B_UPSTREAM`: Host and port for the secondary (B) ads service (default: `ads-python:3030`)
221+
- `ADS_B_PERCENT`: Percentage of traffic to route to the B (Python) ads service (default: `0`). The remainder goes to the A ads (Java) service.
222+
- Set a value between `0` and `100` to control the split.
223+
209224
**How to use**
225+
226+
#### Docker Compose
210227
1. Add a second Ads service to the `docker-compose.yml`
211228

212229
```yaml
213230
# OPTIONAL: Advertisement service (Python)
214231
ads-python:
215-
image: ghcr.io/datadog/storedog/ads:${STOREDOG_IMAGE_VERSION:-latest}
216-
build:
232+
image: ghcr.io/datadog/storedog/ads-python:${STOREDOG_IMAGE_VERSION:-latest}
233+
build: # Only used if building from source in development
217234
context: ./services/ads/python
218235
depends_on:
219236
- postgres
@@ -223,15 +240,21 @@ Run two Ads services and split traffic between them. The amount of traffic sent
223240
- POSTGRES_USER=${POSTGRES_USER:-postgres}
224241
- POSTGRES_HOST=postgres
225242
- DD_AGENT_HOST=dd-agent
243+
- DD_ENV=${DD_ENV:-production}
226244
- DD_SERVICE=store-ads-python
227245
- DD_VERSION=${DD_VERSION_ADS_PYTHON:-1.0.0}
246+
- DD_PROFILING_ENABLED=true
247+
- DD_PROFILING_TIMELINE_ENABLED=true
248+
- DD_PROFILING_ALLOCATION_ENABLED=true
249+
volumes: # Only used in development
250+
- ./services/ads/python:/app
228251
networks:
229252
- storedog-network
230253
labels:
231254
com.datadoghq.ad.logs: '[{"source": "python"}]'
232255
```
233256

234-
1. Add and set these environment variables to the `service-proxy` service:
257+
1. Add these environment variables to the `service-proxy` service in the `docker-compose.yml` file:
235258

236259
```yaml
237260
environment:
@@ -240,13 +263,40 @@ Run two Ads services and split traffic between them. The amount of traffic sent
240263
- ADS_B_PERCENT=${ADS_B_PERCENT:-0}
241264
```
242265

243-
- `ADS_A_UPSTREAM`: Host and port for the primary (A) ads service (default: `ads:3030`)
244-
- `ADS_B_UPSTREAM`: Host and port for the secondary (B) ads service (default: `ads-python:3030`)
245-
- `ADS_B_PERCENT`: Percentage of traffic to route to the B (Python) ads service (default: `0`). The remainder goes to the A (Java) ads service.
246-
- Set to a value between `0` and `100` to control the split.
247266
1. Start the app via `docker compose up -d`
248267

268+
#### Kubernetes
269+
270+
A Kubernetes manifest for the Python Ads service is available in the `services/ads/k8s-manifests/` directory.
271+
272+
1. Add the `ads-python.yaml` file to the `k8s-manifests/storedog-app/deployments/` directory.
273+
274+
1. Add the following environment variables to the `nginx.yaml` file and adjust as needed:
275+
276+
```yaml
277+
# A/B testing ads services
278+
- name: ADS_A_UPSTREAM
279+
value: "ads:3030"
280+
- name: ADS_B_UPSTREAM
281+
value: "ads-python:3030"
282+
- name: ADS_B_PERCENT
283+
value: "50"
284+
```
285+
286+
1. Follow the instructions in the [Kubernetes README](./k8s-manifests/README.md) to run Storedog in Kubernetes.
287+
288+
1. If the Storedog is already running, apply the manifests to the cluster:
289+
290+
```bash
291+
envsubst < k8s-manifests/storedog-app/deployments/ads-python.yaml | kubectl apply -n storedog -f -
292+
envsubst < k8s-manifests/storedog-app/deployments/nginx.yaml | kubectl apply -n storedog -f -
293+
```
294+
295+
> [!IMPORTANT]
296+
> Be sure to set the `DD_VERSION_ADS_PYTHON` environment variable so that it will be applied to the file by `envsubst`.
297+
249298
### Feature flags
299+
250300
Some capabilities are hidden behind feature flags, which can be controlled via `services/frontend/site/featureFlags.config.json`.
251301

252302
> [!NOTE]
@@ -258,6 +308,7 @@ Some capabilities are hidden behind feature flags, which can be controlled via `
258308
> ```
259309
260310
#### dbm
311+
261312
Enables a product ticker on the homepage with a long-running query to demonstrate DBM.
262313
263314
**How to use**:
@@ -270,6 +321,7 @@ Enables a product ticker on the homepage with a long-running query to demonstrat
270321
You can modify the ticker functionality in `services/frontend/components/common/NavBar.tsx`.
271322
272323
#### error-tracking
324+
273325
Introduces an exception in the Ads services to demonstrate Error Tracking by setting a header in to a value that is not expected by the Ads service.
274326
275327
**How to use**:
@@ -281,6 +333,7 @@ Introduces an exception in the Ads services to demonstrate Error Tracking by set
281333
Modify this functionality in `services/frontend/components/common/Ad/Ad.tsx` and respective Ads service being used.
282334
283335
#### api-errors
336+
284337
This introduces random errors that occur in the frontend service's `/api` routes.
285338

286339
**How to use**:
@@ -291,6 +344,7 @@ This introduces random errors that occur in the frontend service's `/api` routes
291344
Modify this functionality in `services/frontend/pages/api/*`.
292345

293346
#### product-card-frustration
347+
294348
This will swap out the product card component with a version that doesn't have the thumbnails linked to the product page. When paired with the Puppeteer service, this can be used to demonstrate Frustration Signals in RUM.
295349
296350
**How to use**:
@@ -301,6 +355,7 @@ This will swap out the product card component with a version that doesn't have t
301355
Modify this functionality in `services/frontend/components/Product/ProductCard.tsx` and `services/frontend/components/Product/ProductCard-v2.tsx`.
302356
303357
## Image publication
358+
304359
Images are stored in GHCR. On PR merges, only the affected services will be pushed to GHCR, using the `latest` tag. For example, if you only made changes to the `backend` service, then only the `backend` Github workflow will trigger and publish `ghcr.io/datadog/storedog/backend:latest`.
305360
306361
Separately, we tag and publish *all* images when a new release is created with the corresponding release tag e.g. `ghcr.io/datadog/storedog/backend:1.0.1`. New releases are made on an ad-hoc basis, depending on the recent features that are added.
@@ -312,6 +367,7 @@ All of the services in the Storedog application are Dockerized and run in contai
312367
Below is a breakdown of services and some instructions on how to use them.
313368

314369
### Ads
370+
315371
There are two advertisement services, the default service is built in Java and there is another option available in Python. These services do the same thing, have the same endpoints, run on the same port (`3030`), and have the same failure modes. These ads are served through the `Ads.tsx` component in the frontend service.
316372

317373
To switch between the Java and Python services, see the instructions in the [Ads service README](./services/ads/README.md).
@@ -340,6 +396,7 @@ sh ./scripts/backup-db.sh
340396
This will create a new `restore.sql` file in the `services/postgres/db/` directory and get it set up with all of necessary SQL statements to prepare the database for Datadog monitoring. When done running, you'll want to rebuild the Postgres database image with the new restore point.
341397

342398
#### Worker
399+
343400
The Spree application has a worker process that runs in the background. There is a specific Datadog tracer configuration for it in the `services/worker/` directory and is mounted into the worker container.
344401

345402
### Discounts

docker-compose.dev.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
- DD_LOGS_ENABLED=true
1212
- DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true
1313
- DD_CONTAINER_EXCLUDE=image:agent name:puppeteer
14+
- DD_CLOUD_PROVIDER_METADATA=[]
1415
- DD_HOSTNAME=${DD_HOSTNAME-development-host}
1516
- DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true
1617
networks:
@@ -38,9 +39,9 @@ services:
3839
- storedog-network
3940
environment:
4041
- DD_AGENT_HOST=dd-agent
42+
- DD_ENV=${DD_ENV:-development}
4143
- DD_SERVICE=store-frontend-api # used for Next.js API routes
4244
- DD_VERSION=${NEXT_PUBLIC_DD_VERSION_FRONTEND-1.0.0}
43-
- DD_LOGS_INJECTION=true
4445
- DD_RUNTIME_METRICS_ENABLED=true
4546
- DD_PROFILING_ENABLED=true
4647
- DD_PROFILING_TIMELINE_ENABLED=true
@@ -59,13 +60,13 @@ services:
5960
- NEXT_PUBLIC_SPREE_IMAGE_HOST=${NEXT_PUBLIC_SPREE_IMAGE_HOST:-/services/backend}
6061
- NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN=${NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN:-service-proxy}
6162
labels:
62-
com.datadoghq.ad.logs: '[{"source": "nodejs", "auto_multi_line_detection":true }]'
63+
com.datadoghq.ad.logs: '[{"source": "nodejs", "auto_multi_line_detection": true }]'
6364

6465
# Backend service (Ruby on Rails/Spree)
6566
backend:
6667
build:
6768
context: ./services/backend
68-
command: wait-for-it postgres:5432 -- bundle exec rails s -b 0.0.0.0 -p 4000 --pid /app/tmp/pids/server.pid
69+
command: wait-for-it postgres:5432 -- bundle exec ddprofrb exec rails s -b 0.0.0.0 -p 4000 --pid /app/tmp/pids/server.pid
6970
depends_on:
7071
- 'postgres'
7172
- 'redis'
@@ -85,21 +86,21 @@ services:
8586
- DB_POOL=${DB_POOL:-25}
8687
- MAX_THREADS=${MAX_THREADS:-5}
8788
- DD_AGENT_HOST=dd-agent
89+
- DD_ENV=${DD_ENV:-development}
8890
- DD_SERVICE=store-backend
8991
- DD_VERSION=${DD_VERSION_BACKEND:-1.0.0}
90-
- DD_LOGS_INJECTION=true
9192
- DD_RUNTIME_METRICS_ENABLED=true
9293
- DD_PROFILING_ENABLED=true
9394
- DD_PROFILING_ALLOCATION_ENABLED=true
9495
- DD_PROFILING_TIMELINE_ENABLED=true
9596
labels:
96-
com.datadoghq.ad.logs: '[{"source": "ruby", "auto_multi_line_detection":true }]'
97+
com.datadoghq.ad.logs: '[{"source": "ruby", "auto_multi_line_detection": true }]'
9798

9899
# Background job processor (Sidekiq)
99100
worker:
100101
build:
101102
context: ./services/backend
102-
command: wait-for-it postgres:5432 -- bundle exec sidekiq -C config/sidekiq.yml
103+
command: wait-for-it postgres:5432 -- bundle exec ddprofrb exec sidekiq -C config/sidekiq.yml
103104
depends_on:
104105
- 'postgres'
105106
- 'redis'
@@ -121,15 +122,15 @@ services:
121122
- DB_POOL=${DB_POOL:-25}
122123
- MAX_THREADS=${MAX_THREADS:-5}
123124
- DD_AGENT_HOST=dd-agent
125+
- DD_ENV=${DD_ENV:-development}
124126
- DD_SERVICE=store-worker
125127
- DD_VERSION=${DD_VERSION_BACKEND:-1.0.0}
126-
- DD_LOGS_INJECTION=true
127128
- DD_RUNTIME_METRICS_ENABLED=true
128129
- DD_PROFILING_ENABLED=true
129130
- DD_PROFILING_TIMELINE_ENABLED=true
130131
- DD_PROFILING_ALLOCATION_ENABLED=true
131132
labels:
132-
com.datadoghq.ad.logs: '[{"source": "ruby", "auto_multi_line_detection":true }]'
133+
com.datadoghq.ad.logs: '[{"source": "ruby", "auto_multi_line_detection": true }]'
133134

134135
# Discounts service (Python/Flask)
135136
discounts:
@@ -140,15 +141,13 @@ services:
140141
- postgres
141142
- dd-agent
142143
environment:
143-
- FLASK_APP=discounts.py
144-
- FLASK_DEBUG=0
145144
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
146145
- POSTGRES_USER=${POSTGRES_USER:-postgres}
147146
- POSTGRES_HOST=postgres
148147
- DD_AGENT_HOST=dd-agent
148+
- DD_ENV=${DD_ENV:-development}
149149
- DD_SERVICE=store-discounts
150150
- DD_VERSION=${DD_VERSION_DISCOUNTS:-1.0.0}
151-
- DD_LOGS_INJECTION=true
152151
- DD_RUNTIME_METRICS_ENABLED=true
153152
- DD_PROFILING_ENABLED=true
154153
- DD_PROFILING_TIMELINE_ENABLED=true
@@ -172,9 +171,9 @@ services:
172171
- POSTGRES_USER=${POSTGRES_USER:-postgres}
173172
- POSTGRES_HOST=postgres
174173
- DD_AGENT_HOST=dd-agent
174+
- DD_ENV=${DD_ENV:-development}
175175
- DD_SERVICE=store-ads
176176
- DD_VERSION=${DD_VERSION_ADS:-1.0.0}
177-
- DD_LOGS_INJECTION=true
178177
- DD_PROFILING_ENABLED=true
179178
- DD_PROFILING_TIMELINE_ENABLED=true
180179
- DD_PROFILING_ALLOCATION_ENABLED=true
@@ -197,6 +196,7 @@ services:
197196
- dd-agent
198197
environment:
199198
- DD_AGENT_HOST=dd-agent
199+
- DD_ENV=${DD_ENV:-development}
200200
- DD_SERVICE=service-proxy
201201
- DD_VERSION=${DD_VERSION_NGINX:-1.28.0}
202202
labels:
@@ -225,7 +225,7 @@ services:
225225
com.datadoghq.ad.check_names: '["postgres"]'
226226
com.datadoghq.ad.init_configs: '[{}]'
227227
com.datadoghq.ad.instances: '[{"host":"%%host%%", "port":5432, "username":"datadog", "password":"datadog"}]'
228-
com.datadoghq.ad.logs: '[{"source": "postgresql", "auto_multi_line_detection":true, "path": "/var/log/pg_log/postgresql*.json", "type": "file"}]'
228+
com.datadoghq.ad.logs: '[{"source": "postgresql", "service":"store-db", "auto_multi_line_detection": true, "path": "/var/log/pg_log/postgresql*.json", "type": "file"}]'
229229

230230
# Cache and job queue
231231
redis:
@@ -238,7 +238,6 @@ services:
238238
- storedog-network
239239
labels:
240240
com.datadoghq.tags.service: 'redis'
241-
com.datadoghq.tags.env: '${DD_ENV:-development}'
242241
com.datadoghq.tags.version: '${DD_VERSION_REDIS:-6.2}'
243242
com.datadoghq.ad.check_names: '["redisdb"]'
244243
com.datadoghq.ad.init_configs: '[{}]'

0 commit comments

Comments
 (0)