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

Switch to APM

parent a604531a
......@@ -49,6 +49,7 @@ secrets:
space:
stage: deploy
when: manual
script:
- kubectl apply -f deploy/tracing.yaml
- NS=$(kubectl config view -o jsonpath="{..namespace}")
......@@ -58,6 +59,7 @@ space:
hiphop:
stage: deploy
when: manual
script:
- kubectl apply -f deploy/tracing.yaml
- NS=$(kubectl config view -o jsonpath="{..namespace}")
......
This diff is collapsed.
This diff is collapsed.
import ballerina/http;
import ballerina/log;
import ballerina/config;
string astrosSvc = config:getAsString("ASTROS_SVC", "localhost:9090");
string positionSvc = config:getAsString("POSITION_SVC", "localhost:9090");
string passtimeSvc = config:getAsString("PASSTIME_SVC", "localhost:9090");
@http:ServiceConfig { basePath: "/" }
service space on new http:Listener(9090) {
@http:ResourceConfig { methods: ["GET"], path: "/" }
resource function index (http:Caller caller, http:Request req) returns @untainted error? {
log:printInfo(string `${ req.method } ${ req.rawPath } [${ req.userAgent }] by ${ caller.remoteAddress.toString() }`);
http:Response res = new;
check caller->redirect(res, 300, ["/space"]);
}
@http:ResourceConfig { methods: ["GET"], path: "/space" }
resource function alldata (http:Caller caller, http:Request req) returns @untainted error? {
log:printInfo(string `${ req.method } ${ req.rawPath } [${ req.userAgent }] by ${ caller.remoteAddress.toString() }`);
http:Client notify = new ("http://api.open-notify.org");
log:printInfo("Sending requests");
future<http:Response | error> astrosResponse = start notify->get("/astros");
future<http:Response | error> positionResponse = start notify->get("/position");
future<http:Response | error> passtimeResponse = start notify->get("/iss-pass.json?lat=0.001&lon=0.001");
log:printInfo("Awaiting answers");
http:Response | error astros = wait astrosResponse;
http:Response | error position = wait positionResponse;
http:Response | error passtime = wait passtimeResponse;
log:printInfo("Processing answers");
if (astros is error || position is error || passtime is error) {
log:printError("Could not load position or astro data from one or more endpoints");
if (astros is error) { log:printError(astros.reason()); }
if (position is error) { log:printError(position.reason()); }
if (passtime is error) { log:printError(passtime.reason()); }
check caller->internalServerError("Could not load data from one or more remote services");
} else {
json result = {
"astros": check astros.getJsonPayload(),
"position": check position.getJsonPayload(),
"passtime": check passtime.getJsonPayload()
};
http:Response res = new;
res.statusCode = 500;
res.setPayload(<@untained> result);
check caller->respond(res);
}
}
}
\ No newline at end of file
......@@ -4,8 +4,6 @@ metadata:
name: hiphop-deployment-{{ TIER }}
labels:
app: hiphop-{{ TIER }}
annotations:
"sidecar.jaegertracing.io/inject": "tracing"
spec:
replicas: 1
selector:
......@@ -20,7 +18,7 @@ spec:
- name: gitlab-registry-credentials
containers:
- name: hiphop
image: git.mylab.th-luebeck.de:4181/cloud-native/lab-tracing/hiphop:latest
image: {{ CI_REGISTRY_IMAGE }}/hiphop:latest
imagePullPolicy: Always
resources:
limits:
......@@ -32,6 +30,8 @@ spec:
value: "hiphop-svc"
- name: TIER
value: "{{ TIER }}"
- name: ELASTIC_APM_SERVER_URL
value: "http://apm-apm-server.default:8200"
---
apiVersion: v1
kind: Service
......
......@@ -4,8 +4,6 @@ metadata:
name: space-deployment
labels:
app: space
annotations:
"sidecar.jaegertracing.io/inject": "tracing"
spec:
replicas: 1
selector:
......@@ -20,7 +18,7 @@ spec:
- name: gitlab-registry-credentials
containers:
- name: hiphop
image: git.mylab.th-luebeck.de:4181/cloud-native/lab-tracing/space:latest
image: {{ CI_REGISTRY_IMAGE }}/space:latest
imagePullPolicy: Always
resources:
limits:
......@@ -30,6 +28,8 @@ spec:
env:
- name: SERVICE
value: "space-svc"
- name: ELASTIC_APM_SERVER_URL
value: "http://apm-apm-server.default:8200"
---
apiVersion: v1
kind: Service
......
from flask import Flask, redirect, request
from jaeger_client import Config
import opentracing
from opentracing.propagation import Format
import requests
import traceback
import os
import requests, traceback, os
# A very boring and basic hip-hop-service to demonstrate
# observability via tracing.
......@@ -13,14 +8,6 @@ service = os.environ.get('HIPHOP', 'hiphop')
tier = int(os.environ.get('TIER', '1'))
app = Flask(__name__)
config = Config(config = {
'sampler': { 'type': 'const', 'param': 1 },
'logging': True,
'reporter_batch_size': 1
}, service_name=service)
tracer = config.initialize_tracer()
@app.route('/')
def index():
return redirect('/hip')
......@@ -29,26 +16,14 @@ def index():
def hip():
print(request.headers)
r = ""
parent_span = tracer.extract(Format.HTTP_HEADERS, request.headers) if tier > 1 else tracer.start_span(operation_name="hip hop")
try:
print(f"{parent_span}")
url = f"http://{service}-{tier + 1}/hip"
with tracer.start_span(operation_name=url, child_of=parent_span) as span:
print(f"{span}")
span.set_tag("http.url", url)
headers = dict(request.headers)
tracer.inject(span, Format.HTTP_HEADERS, headers)
print(f"tracer injected headers: { headers }")
r = requests.get(url, headers=headers)
span.set_tag("http.status_code", r.status_code)
print(r)
r = requests.get(url)
r = r.content.decode('utf-8')
except Exception as ex:
print(ex)
traceback.print_exc()
r = "END"
if "finish" in dir(parent_span):
parent_span.finish()
hip = "hip " if tier == 1 else ""
return f"{hip} hop-{ tier } -> { r }".strip()
......
from flask import Flask, redirect, request, jsonify
from jaeger_client import Config
import opentracing
import requests
import traceback
import os
import json
from joblib import Parallel, delayed
import requests, os, json, logging
import elasticapm
from elasticapm.contrib.flask import ElasticAPM
apm = ElasticAPM(app)
# A very boring and basic space-service to demonstrate
# observability via tracing.
service = os.environ.get('SERVICE', 'space')
app = Flask(__name__)
# config = Config(config = {
# 'sampler': { 'type': 'const', 'param': 1 },
# 'logging': True,
# 'reporter_batch_size': 1
# }, service_name=service)
# tracer = config.initialize_tracer()
apm = ElasticAPM(app,
service_name=os.environ.get('SERVICE', 'space'),
)
@app.route('/')
def index():
return redirect('/space')
def load_url(key, url):
return key, json.loads(requests.get(url).content)
#with tracer.start_span(operation_name=key, child_of=ctx) as span:
# return key, json.loads(requests.get(url).content)
@app.route('/space')
def space():
#with tracer.start_span(operation_name="space") as parent_span:
try:
lat = float(request.args.get('lat', "0.0001"))
lon = float(request.args.get('lon', "0.0001"))
except Exception as ex:
print(ex)
logging.error(f"Bad request ({ ex })")
return "Bad request (lat/lon not numeric)", 400
queries = {
......@@ -49,15 +30,12 @@ def space():
"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:
results = Parallel(n_jobs=3)(delayed(load_url)(key, url) for key, url in queries.items())
result = { key: content for key, content in results }
#for key, url in queries.items():
# with tracer.start_span(operation_name=key, child_of=parent_span) as span:
# result[key] = json.loads(requests.get(url).content)
result = {}
for key, url in queries.items():
logging.info(f"Fetching { url }")
result[key] = json.loads(requests.get(url).content)
print(result)
logging.info(json.dumps(result))
return jsonify(result)
app.run(host="0.0.0.0", port=80)
Supports Markdown
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