From e49fe2f5a928431b017c847f5165f8439090870f Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Fri, 12 Jul 2019 21:57:11 -0400 Subject: [PATCH] update steps --- dash-apm-python/background.sh | 6 ++++++ dash-apm-python/index.json | 14 ++++++++++-- dash-apm-python/step_11.md | 7 ++++++ dash-apm-python/step_12.md | 5 +++++ dash-apm-python/step_4.md | 6 +++--- dash-apm-python/step_5.md | 31 +++++---------------------- dash-apm-python/step_5_background.sh | 7 ++++++ dash-apm-python/step_6.md | 32 +++++----------------------- dash-apm-python/step_6_background.sh | 7 ++++++ 9 files changed, 57 insertions(+), 58 deletions(-) create mode 100644 dash-apm-python/step_11.md create mode 100644 dash-apm-python/step_12.md create mode 100644 dash-apm-python/step_5_background.sh create mode 100644 dash-apm-python/step_6_background.sh diff --git a/dash-apm-python/background.sh b/dash-apm-python/background.sh index 319cf16..d2d29b4 100644 --- a/dash-apm-python/background.sh +++ b/dash-apm-python/background.sh @@ -1,6 +1,12 @@ #!/usr/bin/env bash + +# Setup workshop code mkdir /tracing-workshop git clone https://github.com/brettlangdon/distributed-tracing-with-apm-workshop /tracing-workshop cd /tracing-workshop +# Try to install yaml_cli helper +(cd /tmp/ && git clone https://github.com/Gallore/yaml_cli && cd ./yaml_cli && python setup.py install) || true + +# Start pulling containers as soon as they load docker-compose pull diff --git a/dash-apm-python/index.json b/dash-apm-python/index.json index db91677..36bb894 100644 --- a/dash-apm-python/index.json +++ b/dash-apm-python/index.json @@ -21,11 +21,13 @@ }, { "title": "Introducing errors", - "text": "step_5.md" + "text": "step_5.md", + "courseData": "step_5_background.sh" }, { "title": "Introducing latencies", - "text": "step_6.md" + "text": "step_6.md", + "courseData": "step_6_background.sh" }, { "title": "Enable trace and logs", @@ -42,6 +44,14 @@ { "title": "Setup custom dashboard", "text": "step_10.md" + }, + { + "title": "Introducing failures", + "text": "step_11.md" + }, + { + "title": "Restart stopped service", + "text": "step_12.md" } ], "intro": { diff --git a/dash-apm-python/step_11.md b/dash-apm-python/step_11.md new file mode 100644 index 0000000..786e6e2 --- /dev/null +++ b/dash-apm-python/step_11.md @@ -0,0 +1,7 @@ +In this phase we are going to introduce a service failure. + +Open a new terminal window and run: + +`docker-compose stop pumps` + +to cause the `pumps` service to stop. diff --git a/dash-apm-python/step_12.md b/dash-apm-python/step_12.md new file mode 100644 index 0000000..660bca4 --- /dev/null +++ b/dash-apm-python/step_12.md @@ -0,0 +1,5 @@ +Before continuing to the next step please be sure to restart the `pumps` service. + +`docker-compose start pumps`. + +You may close the new terminal window you have opened in the previous step. diff --git a/dash-apm-python/step_4.md b/dash-apm-python/step_4.md index fc5bf45..0b73a35 100644 --- a/dash-apm-python/step_4.md +++ b/dash-apm-python/step_4.md @@ -6,13 +6,13 @@ Add the following code after the `app = Flask('api')`. ``` python @app.before_request -def add_user_id(): +def add_customer_id(): # Get the current user's id - user_id = get_user_id() + customer_id = get_customer_id() # Get the current root span (the `flask.request` span) span = tracer.current_root_span() - span.set_tag('user_id', user_id) + span.set_tag(customer_id', customer_id) ```{{copy}} `restart-services`{{execute interrupt}} diff --git a/dash-apm-python/step_5.md b/dash-apm-python/step_5.md index 8af5f5f..d759918 100644 --- a/dash-apm-python/step_5.md +++ b/dash-apm-python/step_5.md @@ -1,29 +1,8 @@ -What happens when unexpected exceptions are raised from our application? +In this phase we are going to introduce an exception into our application +to see how we can track it down. -Open `frontend/frontend/api.py` file in the editor. +`restart-services`{{execute interrupt}} to continue. -Add the following code to the beginning of the `def simulate_sensors` route. +Open the `frontend` service page to continue. -``` python -maybe_raise_exception() -```{{copy}} - -The end result function should look like: - -``` python -@app.route('/simulate_sensors') -def simulate_sensors(): - maybe_raise_exception() - - app.logger.info('Simulating refresh of sensor data') - resp = requests.get('http://sensors:5002/refresh_sensors') - resp.raise_for_status() - sensors = resp.json() - return jsonify(sensors) -```{{copy}} - -`restart-services`{{execute interrupt}}. - -Open the `/simulate_sensors` resource page for our `frontend` service. - -https://app.datadoghq.com/apm/service/frontend/flask.request +https://app.datadoghq.com/apm/service/frontend diff --git a/dash-apm-python/step_5_background.sh b/dash-apm-python/step_5_background.sh new file mode 100644 index 0000000..01753d3 --- /dev/null +++ b/dash-apm-python/step_5_background.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +command -v yaml_cli > /dev/null && \ + yaml_cli -i docker-compose.yml \ + -o docker-compose.yml \ + --list-append \ + -s services:frontend:environment 'WORKSHOP_ADD_ERRORS=true' diff --git a/dash-apm-python/step_6.md b/dash-apm-python/step_6.md index 49bb68b..c7b16a2 100644 --- a/dash-apm-python/step_6.md +++ b/dash-apm-python/step_6.md @@ -1,30 +1,8 @@ -With APM we can easily visualize where latencies are coming from. +In this phase we are going to introduce an latency into our application +to see how we can track it down. -Open `sensors/sensors.py` file in the editor. +`restart-services`{{execute interrupt}} to continue. -Add the following to the `def simulate_all_sensors` function. +Open the `frontend` service page to continue. -```python -db.session.execute('SELECT pg_sleep(2);') -```{{copy}} - -When we are done the function should look like: - -``` python -@tracer.wrap(name='sensor-simulator') -def simulate_all_sensors(): - db.session.execute('SELECT pg_sleep(2);') - sensors = Sensor.query.all() - for sensor in sensors: - sensor.value = random.randint(1,100) - db.session.add_all(sensors) - db.session.commit() - app.logger.info('Sensor data updated') - return [s.serialize() for s in sensors] -```{{copy}} - -`restart-services`{{execute interrupt}} - -Open the service page for our `frontend` service. - -https://app.datadoghq.com/apm/service/frontend/flask.request +https://app.datadoghq.com/apm/service/frontend diff --git a/dash-apm-python/step_6_background.sh b/dash-apm-python/step_6_background.sh new file mode 100644 index 0000000..c13134f --- /dev/null +++ b/dash-apm-python/step_6_background.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +command -v yaml_cli > /dev/null && \ + yaml_cli -i docker-compose.yml \ + -o docker-compose.yml \ + --list-append \ + -s services:sensors:environment 'WORKSHOP_ADD_LATENCY=true'