From cecd98625177c1e9ddd051ce5e0559ef620ad188 Mon Sep 17 00:00:00 2001 From: Jan-Niklas Tille Date: Thu, 9 May 2024 12:31:23 +0200 Subject: [PATCH] do_stuff returns response, so we don't need _ --- .../initial/src/app.py | 75 ++++++++++--------- .../solution/src/app.py | 3 +- labs/collector/initial/src/app.py | 1 + labs/collector/solution/src/app.py | 1 + .../initial/src/app.py | 3 +- .../solution/src/app.py | 1 + .../initial/src/app.py | 3 +- .../solution/src/app.py | 3 +- .../initial/src/app.py | 1 + .../solution/src/app.py | 11 ++- 10 files changed, 59 insertions(+), 43 deletions(-) diff --git a/labs/automatic-instrumentation/library-instrumentation/initial/src/app.py b/labs/automatic-instrumentation/library-instrumentation/initial/src/app.py index 8f3bb83..6c78b85 100644 --- a/labs/automatic-instrumentation/library-instrumentation/initial/src/app.py +++ b/labs/automatic-instrumentation/library-instrumentation/initial/src/app.py @@ -1,37 +1,38 @@ -# pyright: reportMissingTypeStubs=false, reportUnknownParameterType=false, reportMissingParameterType=false, reportUnknownArgumentType=false, reportUnknownMemberType=false, reportAttributeAccessIssue=false - -import time - -import requests -from client import ChaosClient, FakerClient -from flask import Flask, make_response - -# global variables -app = Flask(__name__) - -@app.route("/users", methods=["GET"]) -def get_user(): - user, status = db.get_user(123) - data = {} - if user is not None: - data = {"id": user.id, "name": user.name, "address": user.address} - response = make_response(data, status) - return response - - -def do_stuff(): - time.sleep(0.1) - url = "http://echo:6000/" - _response = requests.get(url) - - -@app.route("/") -def index(): - do_stuff() - current_time = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()) - return f"Hello, World! It's currently {current_time}" - - -if __name__ == "__main__": - db = ChaosClient(client=FakerClient()) - app.run(host="0.0.0.0", debug=True) +# pyright: reportMissingTypeStubs=false, reportUnknownParameterType=false, reportMissingParameterType=false, reportUnknownArgumentType=false, reportUnknownMemberType=false, reportAttributeAccessIssue=false + +import time + +import requests +from client import ChaosClient, FakerClient +from flask import Flask, make_response + +# global variables +app = Flask(__name__) + +@app.route("/users", methods=["GET"]) +def get_user(): + user, status = db.get_user(123) + data = {} + if user is not None: + data = {"id": user.id, "name": user.name, "address": user.address} + response = make_response(data, status) + return response + + +def do_stuff(): + time.sleep(0.1) + url = "http://echo:6000/" + response = requests.get(url) + return response + + +@app.route("/") +def index(): + do_stuff() + current_time = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()) + return f"Hello, World! It's currently {current_time}" + + +if __name__ == "__main__": + db = ChaosClient(client=FakerClient()) + app.run(host="0.0.0.0", debug=True) diff --git a/labs/automatic-instrumentation/library-instrumentation/solution/src/app.py b/labs/automatic-instrumentation/library-instrumentation/solution/src/app.py index 8285514..97ee317 100644 --- a/labs/automatic-instrumentation/library-instrumentation/solution/src/app.py +++ b/labs/automatic-instrumentation/library-instrumentation/solution/src/app.py @@ -38,7 +38,8 @@ def get_user(): def do_stuff(): time.sleep(0.1) url = "http://echo:6000/" - _response = requests.get(url) + response = requests.get(url) + return response @app.route("/") diff --git a/labs/collector/initial/src/app.py b/labs/collector/initial/src/app.py index f57fcc5..3dd2901 100644 --- a/labs/collector/initial/src/app.py +++ b/labs/collector/initial/src/app.py @@ -83,6 +83,7 @@ def do_stuff(): response = requests.get(url) print(response.json()) logging.info(str(response.json())) + return response @tracer.start_as_current_span("index") @app.route("/") diff --git a/labs/collector/solution/src/app.py b/labs/collector/solution/src/app.py index c8485a2..d5fe1b9 100644 --- a/labs/collector/solution/src/app.py +++ b/labs/collector/solution/src/app.py @@ -83,6 +83,7 @@ def do_stuff(): response = requests.get(url) print(response.json()) logging.info(str(response.json())) + return response @tracer.start_as_current_span("index") @app.route("/") diff --git a/labs/manual-instrumentation-logs/initial/src/app.py b/labs/manual-instrumentation-logs/initial/src/app.py index 8f3bb83..de5d0cf 100644 --- a/labs/manual-instrumentation-logs/initial/src/app.py +++ b/labs/manual-instrumentation-logs/initial/src/app.py @@ -22,7 +22,8 @@ def get_user(): def do_stuff(): time.sleep(0.1) url = "http://echo:6000/" - _response = requests.get(url) + response = requests.get(url) + return response @app.route("/") diff --git a/labs/manual-instrumentation-logs/solution/src/app.py b/labs/manual-instrumentation-logs/solution/src/app.py index 701ec42..820c24c 100644 --- a/labs/manual-instrumentation-logs/solution/src/app.py +++ b/labs/manual-instrumentation-logs/solution/src/app.py @@ -34,6 +34,7 @@ def do_stuff(): url = "http://echo:6000/" response = requests.get(url) logging.info(response.json()) + return response @app.route("/") diff --git a/labs/manual-instrumentation-metrics/initial/src/app.py b/labs/manual-instrumentation-metrics/initial/src/app.py index 8f3bb83..de5d0cf 100644 --- a/labs/manual-instrumentation-metrics/initial/src/app.py +++ b/labs/manual-instrumentation-metrics/initial/src/app.py @@ -22,7 +22,8 @@ def get_user(): def do_stuff(): time.sleep(0.1) url = "http://echo:6000/" - _response = requests.get(url) + response = requests.get(url) + return response @app.route("/") diff --git a/labs/manual-instrumentation-metrics/solution/src/app.py b/labs/manual-instrumentation-metrics/solution/src/app.py index 42e0ecb..66cf1db 100644 --- a/labs/manual-instrumentation-metrics/solution/src/app.py +++ b/labs/manual-instrumentation-metrics/solution/src/app.py @@ -47,7 +47,8 @@ def get_user(): def do_stuff(): time.sleep(0.1) url = "http://echo:6000/" - _response = requests.get(url) + response = requests.get(url) + return response @app.route("/") diff --git a/labs/manual-instrumentation-traces/initial/src/app.py b/labs/manual-instrumentation-traces/initial/src/app.py index 1df59b6..de5d0cf 100644 --- a/labs/manual-instrumentation-traces/initial/src/app.py +++ b/labs/manual-instrumentation-traces/initial/src/app.py @@ -23,6 +23,7 @@ def do_stuff(): time.sleep(0.1) url = "http://echo:6000/" response = requests.get(url) + return response @app.route("/") diff --git a/labs/manual-instrumentation-traces/solution/src/app.py b/labs/manual-instrumentation-traces/solution/src/app.py index b8fed05..99f500f 100644 --- a/labs/manual-instrumentation-traces/solution/src/app.py +++ b/labs/manual-instrumentation-traces/solution/src/app.py @@ -1,6 +1,7 @@ # pyright: reportMissingTypeStubs=false, reportUnknownParameterType=false, reportMissingParameterType=false, reportUnknownArgumentType=false import time +import json import requests from client import ChaosClient, FakerClient @@ -47,8 +48,14 @@ def do_stuff(): time.sleep(.1) url = "http://echo:6000/" - _response = requests.get(url, headers=headers) - + response = requests.get(url, headers=headers) + + # debug + print("Headers included in outbound request:") + print(json.dumps(response.json()["request"]["headers"], indent=2)) + + return response + @app.route('/') @tracer.start_as_current_span("index") def index():