Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pump, Cedric
lab-tracing
Commits
508e1205
Commit
508e1205
authored
Mar 06, 2021
by
Nane Kratzke
Browse files
Instrument hip-hop
parent
2a1f7d4d
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
ballerina-space/ballerina-internal.log
deleted
100644 → 0
View file @
2a1f7d4d
This diff is collapsed.
Click to expand it.
ballerina-space/ballerina-internal.log.1
deleted
100644 → 0
View file @
2a1f7d4d
This diff is collapsed.
Click to expand it.
ballerina-space/space-service.bal
deleted
100644 → 0
View file @
2a1f7d4d
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
hiphop/service.py
View file @
508e1205
from
flask
import
Flask
,
redirect
,
request
import
requests
,
traceback
,
os
from
elasticapm.contrib.flask
import
ElasticAPM
# A very boring and basic hip-hop-service to demonstrate
# observability via tracing.
service
=
os
.
environ
.
get
(
'HIPHOP'
,
'hiphop'
)
tier
=
int
(
os
.
environ
.
get
(
'TIER'
,
'1'
))
app
=
Flask
(
__name__
)
apm
=
ElasticAPM
(
app
,
service_name
=
os
.
environ
.
get
(
'HIPHOP'
,
'hiphop'
),
)
@
app
.
route
(
'/'
)
def
index
():
...
...
space/service.py
View file @
508e1205
from
flask
import
Flask
,
redirect
,
request
,
jsonify
import
requests
,
os
,
json
,
logging
import
elasticapm
from
elasticapm.contrib.flask
import
ElasticAPM
# A very boring and basic space-service to demonstrate
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment