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

Switch to APM

parent a604531a
...@@ -49,6 +49,7 @@ secrets: ...@@ -49,6 +49,7 @@ secrets:
space: space:
stage: deploy stage: deploy
when: manual
script: script:
- kubectl apply -f deploy/tracing.yaml - kubectl apply -f deploy/tracing.yaml
- NS=$(kubectl config view -o jsonpath="{..namespace}") - NS=$(kubectl config view -o jsonpath="{..namespace}")
...@@ -58,6 +59,7 @@ space: ...@@ -58,6 +59,7 @@ space:
hiphop: hiphop:
stage: deploy stage: deploy
when: manual
script: script:
- kubectl apply -f deploy/tracing.yaml - kubectl apply -f deploy/tracing.yaml
- NS=$(kubectl config view -o jsonpath="{..namespace}") - NS=$(kubectl config view -o jsonpath="{..namespace}")
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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: ...@@ -4,8 +4,6 @@ metadata:
name: hiphop-deployment-{{ TIER }} name: hiphop-deployment-{{ TIER }}
labels: labels:
app: hiphop-{{ TIER }} app: hiphop-{{ TIER }}
annotations:
"sidecar.jaegertracing.io/inject": "tracing"
spec: spec:
replicas: 1 replicas: 1
selector: selector:
...@@ -20,7 +18,7 @@ spec: ...@@ -20,7 +18,7 @@ spec:
- name: gitlab-registry-credentials - name: gitlab-registry-credentials
containers: containers:
- name: hiphop - name: hiphop
image: git.mylab.th-luebeck.de:4181/cloud-native/lab-tracing/hiphop:latest image: {{ CI_REGISTRY_IMAGE }}/hiphop:latest
imagePullPolicy: Always imagePullPolicy: Always
resources: resources:
limits: limits:
...@@ -32,6 +30,8 @@ spec: ...@@ -32,6 +30,8 @@ spec:
value: "hiphop-svc" value: "hiphop-svc"
- name: TIER - name: TIER
value: "{{ TIER }}" value: "{{ TIER }}"
- name: ELASTIC_APM_SERVER_URL
value: "http://apm-apm-server.default:8200"
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
......
...@@ -4,8 +4,6 @@ metadata: ...@@ -4,8 +4,6 @@ metadata:
name: space-deployment name: space-deployment
labels: labels:
app: space app: space
annotations:
"sidecar.jaegertracing.io/inject": "tracing"
spec: spec:
replicas: 1 replicas: 1
selector: selector:
...@@ -20,7 +18,7 @@ spec: ...@@ -20,7 +18,7 @@ spec:
- name: gitlab-registry-credentials - name: gitlab-registry-credentials
containers: containers:
- name: hiphop - name: hiphop
image: git.mylab.th-luebeck.de:4181/cloud-native/lab-tracing/space:latest image: {{ CI_REGISTRY_IMAGE }}/space:latest
imagePullPolicy: Always imagePullPolicy: Always
resources: resources:
limits: limits:
...@@ -30,6 +28,8 @@ spec: ...@@ -30,6 +28,8 @@ spec:
env: env:
- name: SERVICE - name: SERVICE
value: "space-svc" value: "space-svc"
- name: ELASTIC_APM_SERVER_URL
value: "http://apm-apm-server.default:8200"
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
......
from flask import Flask, redirect, request from flask import Flask, redirect, request
from jaeger_client import Config import requests, traceback, os
import opentracing
from opentracing.propagation import Format
import requests
import traceback
import os
# A very boring and basic hip-hop-service to demonstrate # A very boring and basic hip-hop-service to demonstrate
# observability via tracing. # observability via tracing.
...@@ -13,14 +8,6 @@ service = os.environ.get('HIPHOP', 'hiphop') ...@@ -13,14 +8,6 @@ service = os.environ.get('HIPHOP', 'hiphop')
tier = int(os.environ.get('TIER', '1')) tier = int(os.environ.get('TIER', '1'))
app = Flask(__name__) 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('/') @app.route('/')
def index(): def index():
return redirect('/hip') return redirect('/hip')
...@@ -29,26 +16,14 @@ def index(): ...@@ -29,26 +16,14 @@ def index():
def hip(): def hip():
print(request.headers) print(request.headers)
r = "" r = ""
parent_span = tracer.extract(Format.HTTP_HEADERS, request.headers) if tier > 1 else tracer.start_span(operation_name="hip hop")
try: try:
print(f"{parent_span}")
url = f"http://{service}-{tier + 1}/hip" url = f"http://{service}-{tier + 1}/hip"
with tracer.start_span(operation_name=url, child_of=parent_span) as span: r = requests.get(url)
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 = r.content.decode('utf-8') r = r.content.decode('utf-8')
except Exception as ex: except Exception as ex:
print(ex) print(ex)
traceback.print_exc() traceback.print_exc()
r = "END" r = "END"
if "finish" in dir(parent_span):
parent_span.finish()
hip = "hip " if tier == 1 else "" hip = "hip " if tier == 1 else ""
return f"{hip} hop-{ tier } -> { r }".strip() return f"{hip} hop-{ tier } -> { r }".strip()
......
from flask import Flask, redirect, request, jsonify from flask import Flask, redirect, request, jsonify
from jaeger_client import Config import requests, os, json, logging
import opentracing import elasticapm
import requests
import traceback
import os
import json
from joblib import Parallel, delayed
from elasticapm.contrib.flask import ElasticAPM 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.
service = os.environ.get('SERVICE', 'space')
app = Flask(__name__) app = Flask(__name__)
apm = ElasticAPM(app,
# config = Config(config = { service_name=os.environ.get('SERVICE', 'space'),
# 'sampler': { 'type': 'const', 'param': 1 }, )
# 'logging': True,
# 'reporter_batch_size': 1
# }, service_name=service)
# tracer = config.initialize_tracer()
@app.route('/') @app.route('/')
def index(): def index():
return redirect('/space') 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') @app.route('/space')
def space(): def space():
#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) logging.error(f"Bad request ({ ex })")
return "Bad request (lat/lon not numeric)", 400 return "Bad request (lat/lon not numeric)", 400
queries = { queries = {
...@@ -49,15 +30,12 @@ def space(): ...@@ -49,15 +30,12 @@ def space():
"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: result = {}
results = Parallel(n_jobs=3)(delayed(load_url)(key, url) for key, url in queries.items()) for key, url in queries.items():
result = { key: content for key, content in results } logging.info(f"Fetching { url }")
result[key] = json.loads(requests.get(url).content)
#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)
print(result) logging.info(json.dumps(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)
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