Commit a604531a authored by Nane Kratzke's avatar Nane Kratzke
Browse files

Aktualisieren space/requirements.txt, space/service.py Dateien

parent add19267
...@@ -2,4 +2,5 @@ flask ...@@ -2,4 +2,5 @@ flask
requests requests
opentracing opentracing
jaeger-client jaeger-client
joblib joblib
\ No newline at end of file elastic-apm[flask]
\ No newline at end of file
...@@ -6,6 +6,8 @@ import traceback ...@@ -6,6 +6,8 @@ import traceback
import os import os
import json import json
from joblib import Parallel, delayed from joblib import Parallel, delayed
from elasticapm.contrib.flask import ElasticAPM
apm = ElasticAPM(app)
# A very boring and basic space-service to demonstrate # A very boring and basic space-service to demonstrate
# observability via tracing. # observability via tracing.
...@@ -13,13 +15,13 @@ from joblib import Parallel, delayed ...@@ -13,13 +15,13 @@ from joblib import Parallel, delayed
service = os.environ.get('SERVICE', 'space') service = os.environ.get('SERVICE', 'space')
app = Flask(__name__) app = Flask(__name__)
config = Config(config = { # config = Config(config = {
'sampler': { 'type': 'const', 'param': 1 }, # 'sampler': { 'type': 'const', 'param': 1 },
'logging': True, # 'logging': True,
'reporter_batch_size': 1 # 'reporter_batch_size': 1
}, service_name=service) # }, service_name=service)
tracer = config.initialize_tracer() # tracer = config.initialize_tracer()
@app.route('/') @app.route('/')
def index(): def index():
...@@ -33,23 +35,23 @@ def load_url(key, url): ...@@ -33,23 +35,23 @@ def load_url(key, url):
@app.route('/space') @app.route('/space')
def space(): def space():
with tracer.start_span(operation_name="space") as parent_span: #with tracer.start_span(operation_name="space") as parent_span:
try: try:
lat = float(request.args.get('lat', "0.0001")) lat = float(request.args.get('lat', "0.0001"))
lon = float(request.args.get('lon', "0.0001")) lon = float(request.args.get('lon', "0.0001"))
except Exception as ex: except Exception as ex:
print(ex) print(ex)
return "Bad request (lat/lon not numeric)", 400 return "Bad request (lat/lon not numeric)", 400
queries = { queries = {
"astros": "http://api.open-notify.org/astros.json", "astros": "http://api.open-notify.org/astros.json",
"position": "http://api.open-notify.org/iss-now.json", "position": "http://api.open-notify.org/iss-now.json",
"passtime": f"http://api.open-notify.org/iss-pass.json?lat={ lat }&lon={ lon }" "passtime": f"http://api.open-notify.org/iss-pass.json?lat={ lat }&lon={ lon }"
} }
with tracer.start_span(operation_name="parallel", child_of=parent_span) as span: #with tracer.start_span(operation_name="parallel", child_of=parent_span) as span:
results = Parallel(n_jobs=3)(delayed(load_url)(key, url) for key, url in queries.items()) results = Parallel(n_jobs=3)(delayed(load_url)(key, url) for key, url in queries.items())
result = { key: content for key, content in results } result = { key: content for key, content in results }
#for key, url in queries.items(): #for key, url in queries.items():
# with tracer.start_span(operation_name=key, child_of=parent_span) as span: # with tracer.start_span(operation_name=key, child_of=parent_span) as span:
...@@ -58,4 +60,4 @@ def space(): ...@@ -58,4 +60,4 @@ def space():
print(result) print(result)
return jsonify(result) return jsonify(result)
app.run(host="0.0.0.0", port=80) app.run(host="0.0.0.0", port=80)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment