Skip to content

Commit 518fa7d

Browse files
authored
Merge pull request #72 from DataDog/dash-workshop-updates
Adds updates for Dash workshops
2 parents 83da12c + f2f6ceb commit 518fa7d

File tree

73 files changed

+285067
-24353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+285067
-24353
lines changed

docker-compose.pinned.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ services:
2323
- /var/run/docker.sock:/var/run/docker.sock:ro
2424
- /proc/:/host/proc/:ro
2525
- /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
26-
- ./services/datadog-agent/postgres/dd-agent-conf.yaml:/conf.d/postgres.d/conf.yaml
2726
frontend:
2827
image: public.ecr.aws/x2b9z2t7/storedog/frontend:1.2.0
2928
command: npm run dev
@@ -88,7 +87,6 @@ services:
8887
- DD_RUNTIME_METRICS_ENABLED=true
8988
- DD_PROFILING_ENABLED=true
9089
volumes:
91-
- 'postgres:/var/lib/postgresql/data'
9290
- ./services/backend/db/restore:/docker-entrypoint-initdb.d
9391
- ./services/backend/db/postgresql.conf:/postgresql.conf
9492
labels:
@@ -117,7 +115,10 @@ services:
117115
},
118116
"max_relations": 400,
119117
"collect_function_metrics": true,
120-
"collection_interval": 1
118+
"collection_interval": 1,
119+
"collect_schemas": {
120+
"enabled": true
121+
}
121122
},
122123
{
123124
"dbm":true,
@@ -135,7 +136,10 @@ services:
135136
},
136137
"max_relations": 400,
137138
"collect_function_metrics": true,
138-
"collection_interval": 1
139+
"collection_interval": 1,
140+
"collect_schemas": {
141+
"enabled": true
142+
}
139143
}]'
140144
com.datadoghq.ad.logs: '[{"source": "postgresql", "service": "postgres", "auto_multi_line_detection":true }]'
141145
my.custom.label.team: 'database'
@@ -221,7 +225,7 @@ services:
221225
my.custom.label.team: 'backend'
222226
discounts:
223227
image: public.ecr.aws/x2b9z2t7/storedog/discounts:1.2.0
224-
command: ./my-wrapper-script.sh ${DISCOUNTS_PORT}
228+
command: wait-for-it postgres:5432 -- ./my-wrapper-script.sh ${DISCOUNTS_PORT}
225229
depends_on:
226230
- postgres
227231
- dd-agent
@@ -243,7 +247,6 @@ services:
243247
- ./services/discounts:/app
244248
ports:
245249
- '${DISCOUNTS_PORT}:${DISCOUNTS_PORT}'
246-
- '22:22'
247250
labels:
248251
com.datadoghq.ad.logs: '[{"source": "python", "service": "store-discounts"}]'
249252
com.datadoghq.tags.env: '${DD_ENV-dev}'
@@ -264,7 +267,7 @@ services:
264267
- DD_VERSION=${DD_VERSION-7}
265268
- DD_ENV=${DD_ENV-dev}
266269
ports:
267-
- '3030:8080'
270+
- '${ADS_PORT}:8080'
268271
labels:
269272
com.datadoghq.ad.logs: '[{"source": "java", "service": "ads-java"}]'
270273
com.datadoghq.tags.env: '${DD_ENV-dev}'
@@ -274,4 +277,3 @@ services:
274277

275278
volumes:
276279
redis:
277-
postgres:

docker-compose.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ services:
2222
- /var/run/docker.sock:/var/run/docker.sock:ro
2323
- /proc/:/host/proc/:ro
2424
- /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
25-
- ./services/datadog-agent/postgres/dd-agent-conf.yaml:/conf.d/postgres.d/conf.yaml
2625
frontend:
2726
build:
2827
context: ./services/frontend
@@ -114,7 +113,6 @@ services:
114113
- DD_RUNTIME_METRICS_ENABLED=true
115114
- DD_PROFILING_ENABLED=true
116115
volumes:
117-
- 'postgres:/var/lib/postgresql/data'
118116
- ./services/backend/db/restore:/docker-entrypoint-initdb.d
119117
- ./services/backend/db/postgresql.conf:/postgresql.conf
120118
labels:
@@ -143,7 +141,10 @@ services:
143141
},
144142
"max_relations": 400,
145143
"collect_function_metrics": true,
146-
"collection_interval": 1
144+
"collection_interval": 1,
145+
"collect_schemas": {
146+
"enabled": true
147+
}
147148
},
148149
{
149150
"dbm":true,
@@ -161,7 +162,10 @@ services:
161162
},
162163
"max_relations": 400,
163164
"collect_function_metrics": true,
164-
"collection_interval": 1
165+
"collection_interval": 1,
166+
"collect_schemas": {
167+
"enabled": true
168+
}
165169
}]'
166170
com.datadoghq.ad.logs: '[{"source": "postgresql", "service": "postgres", "auto_multi_line_detection":true }]'
167171
my.custom.label.team: 'database'
@@ -232,6 +236,8 @@ services:
232236
- REDIS_URL=redis://redis:6379/0
233237
- DB_HOST=postgres
234238
- DB_PORT=5432
239+
- POSTGRES_USER
240+
- POSTGRES_PASSWORD
235241
- DISABLE_SPRING=1
236242
- DD_AGENT_HOST=dd-agent
237243
- DD_ENV=${DD_ENV-dev}
@@ -250,7 +256,7 @@ services:
250256
ads:
251257
build:
252258
context: ./services/ads/python
253-
command: flask run --port=${ADS_PORT} --host=0.0.0.0 # If using any other port besides the default 9292, overriding the CMD is required
259+
command: wait-for-it postgres:5432 -- flask run --port=${ADS_PORT} --host=0.0.0.0 # If using any other port besides the default 9292, overriding the CMD is required
254260
depends_on:
255261
- postgres
256262
- dd-agent
@@ -283,7 +289,7 @@ services:
283289
discounts:
284290
build:
285291
context: ./services/discounts
286-
command: ./my-wrapper-script.sh ${DISCOUNTS_PORT}
292+
command: wait-for-it postgres:5432 -- ./my-wrapper-script.sh ${DISCOUNTS_PORT}
287293
depends_on:
288294
- postgres
289295
- dd-agent
@@ -305,7 +311,6 @@ services:
305311
- ./services/discounts:/app
306312
ports:
307313
- '${DISCOUNTS_PORT}:${DISCOUNTS_PORT}'
308-
- '22:22'
309314
labels:
310315
com.datadoghq.ad.logs: '[{"source": "python", "service": "store-discounts"}]'
311316
com.datadoghq.tags.env: '${DD_ENV-dev}'
@@ -363,8 +368,6 @@ services:
363368
- STOREDOG_URL=${STOREDOG_URL-http://localhost}
364369
- PUPPETEER_TIMEOUT
365370
- SKIP_SESSION_CLOSE
366-
profiles:
367-
- puppeteer
368371
depends_on:
369372
- frontend
370373
command: bash puppeteer.sh
@@ -374,4 +377,3 @@ services:
374377

375378
volumes:
376379
redis:
377-
postgres:

scripts/backup-db.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#! /bin/bash
2+
3+
# exec dump on postgres container
4+
5+
# get root of repository
6+
root=$(git rev-parse --show-toplevel)
7+
prependstatements=$root/scripts/prepend_db_statements.sql
8+
destination=$root/services/backend/db/restore/restore-$(date +%Y-%m-%d-%H-%M-%S).sql
9+
10+
# remove old backups in the restore folder
11+
rm -f $root/services/backend/db/restore/*.sql
12+
13+
# exec dump
14+
docker compose exec postgres pg_dump -U postgres spree_starter_development > $destination
15+
16+
echo "Backup created at $destination"
17+
18+
# prepend statements to the dump
19+
cat $prependstatements $destination > $destination.tmp
20+
mv $destination.tmp $destination

scripts/prepend_db_statements.sql

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
CREATE user datadog WITH password 'datadog';
2+
3+
--
4+
-- PostgreSQL database dump
5+
--
6+
7+
-- Dumped from database version 13.8
8+
-- Dumped by pg_dump version 13.8
9+
10+
SET statement_timeout = 0;
11+
SET lock_timeout = 0;
12+
SET idle_in_transaction_session_timeout = 0;
13+
SET client_encoding = 'UTF8';
14+
SET standard_conforming_strings = on;
15+
SELECT pg_catalog.set_config('search_path', '', false);
16+
SET check_function_bodies = false;
17+
SET xmloption = content;
18+
SET client_min_messages = warning;
19+
SET row_security = off;
20+
21+
\connect postgres
22+
23+
CREATE SCHEMA IF NOT EXISTS datadog;
24+
GRANT USAGE ON SCHEMA datadog TO datadog;
25+
GRANT USAGE ON SCHEMA public TO datadog;
26+
GRANT pg_monitor TO datadog;
27+
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
28+
29+
CREATE OR REPLACE FUNCTION datadog.explain_statement(
30+
l_query TEXT,
31+
OUT explain JSON
32+
)
33+
RETURNS SETOF JSON AS
34+
$$
35+
DECLARE
36+
curs REFCURSOR;
37+
plan JSON;
38+
39+
BEGIN
40+
OPEN curs FOR EXECUTE pg_catalog.concat('EXPLAIN (FORMAT JSON) ', l_query);
41+
FETCH curs INTO plan;
42+
CLOSE curs;
43+
RETURN QUERY SELECT plan;
44+
END;
45+
$$
46+
LANGUAGE 'plpgsql'
47+
RETURNS NULL ON NULL INPUT
48+
SECURITY DEFINER;
49+
50+
--
51+
-- Name: spree_starter_development; Type: DATABASE; Schema: -; Owner: postgres
52+
--
53+
54+
CREATE DATABASE spree_starter_development WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE = 'en_US.utf8';
55+
56+
57+
ALTER DATABASE spree_starter_development OWNER TO postgres;
58+
59+
\connect spree_starter_development
60+

services/ads/java/src/main/java/adsjava/AdsJavaApplication.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ public String home() {
4747
public HashMap[] ads(@RequestHeader HashMap<String, String> headers) {
4848

4949
boolean errorFlag = false;
50-
if(headers.get("x-throw-error") != null) {
51-
errorFlag = Boolean.parseBoolean(headers.get("x-throw-error"));
50+
if(headers.get("X-Throw-Error") != null) {
51+
errorFlag = Boolean.parseBoolean(headers.get("X-Throw-Error"));
5252
}
5353

54-
if(errorFlag) {
54+
// if x-error-rate is present, set to variable errorRate (if missing, set to 1)
55+
double errorRate = 1;
56+
if(headers.get("X-Error-Rate") != null) {
57+
errorRate = Double.parseDouble(headers.get("X-Error-Rate"));
58+
}
59+
60+
if(errorFlag && Math.random() < errorRate) {
5561
// Intentionally throw error here to demonstrate Logs Error Tracking behavior
5662
try {
5763
throw new TimeoutException("took too long to get a response");

services/ads/python/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
# run with the DOCKER_BUILDKIT=1 environment variable in your
44
# docker build command (see build.sh)
55
FROM python:3.9.6-slim-buster
6-
76
# Update, upgrade, and cleanup debian packages
87
RUN export DEBIAN_FRONTEND=noninteractive && \
98
apt-get update && \
109
apt-get upgrade --yes && \
11-
apt-get install --yes build-essential libpq-dev && \
10+
apt-get install --yes build-essential libpq-dev wait-for-it && \
1211
apt-get clean && \
1312
rm -rf /var/lib/apt/lists/*
1413

services/ads/python/ads.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ def weighted_image(weight):
7171
def status():
7272
if flask_request.method == 'GET':
7373

74+
# determine if should throw error and save to variable
75+
throw_error = False
7476
if 'X-Throw-Error' in flask_request.headers and flask_request.headers['X-Throw-Error'] == 'true':
77+
throw_error = True
7578

79+
# fetch error rate from header if present (0 - 1)
80+
error_rate = 1
81+
if 'X-Error-Rate' in flask_request.headers:
82+
error_rate = float(flask_request.headers['X-Error-Rate'])
83+
84+
if throw_error and random.random() < error_rate:
7685
try:
7786
raise ValueError('something went wrong')
7887
except ValueError:

services/backend/db/postgresql.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,9 @@ default_text_search_config = 'pg_catalog.english'
704704
# - Shared Library Preloading -
705705

706706
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
707-
pg_stat_statements.track = all
707+
pg_stat_statements.track = ALL
708+
pg_stat_statments.max = 10000
709+
pg_stat_statements.track_utility = off
708710
#local_preload_libraries = ''
709711
#session_preload_libraries = ''
710712
#jit_provider = 'llvmjit' # JIT library to use

0 commit comments

Comments
 (0)