Skip to content

Commit 2d85eb9

Browse files
OpenTelemetry monitoring (#80)
* chore: update submodules * perf: add telemetry * fix: hanging docker stop * chore: update submodules * perf: enhance monitoring * chore(opentelemetry): update submodules * ci: trigger Drone
1 parent d6424d3 commit 2d85eb9

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

app.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1+
import os
2+
import logging
13
from fastapi import FastAPI, HTTPException, responses, status, Request
24
from pydantic import BaseModel
35
from typing import Union, Dict, Optional
46

57
import submodules.model.business_objects.general as general
68
from controller import stats
79
from controller import integration
10+
from submodules.model import telemetry
811

9-
# API creation and description
10-
app = FastAPI()
12+
13+
OTLP_GRPC_ENDPOINT = os.getenv("OTLP_GRPC_ENDPOINT", "tempo:4317")
14+
15+
app_name = "refinery-weak-supervisor"
16+
app = FastAPI(title=app_name)
17+
18+
if telemetry.ENABLE_TELEMETRY:
19+
print("WARNING: Running telemetry.", flush=True)
20+
telemetry.setting_app_name(app_name)
21+
telemetry.setting_otlp(app, app_name=app_name, endpoint=OTLP_GRPC_ENDPOINT)
22+
app.add_middleware(telemetry.PrometheusMiddleware, app_name=app_name)
23+
app.add_route("/metrics", telemetry.metrics)
24+
25+
# Filter out /metrics
26+
logging.getLogger("uvicorn.access").addFilter(
27+
lambda record: "GET /metrics" not in record.getMessage()
28+
)
1129

1230

1331
class WeakSupervisionRequest(BaseModel):

start

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
DEBUG_MODE=false
44
DEBUG_PORT=15677
5+
ENABLE_TELEMETRY=false
56

6-
while getopts d flag
7+
while getopts dg flag
78
do
89
case "${flag}" in
910
d) DEBUG_MODE=true;;
11+
g) ENABLE_TELEMETRY=true;;
1012
esac
1113
done
1214

@@ -46,6 +48,7 @@ docker run -d --rm \
4648
-p 7054:80 \
4749
-e POSTGRES=postgresql://postgres:kern@graphql-postgres:5432 \
4850
-e WS_NOTIFY_ENDPOINT="http://refinery-websocket:8080" \
51+
-e ENABLE_TELEMETRY=$ENABLE_TELEMETRY \
4952
--mount type=bind,source="$(pwd)"/,target=/app \
5053
-v /var/run/docker.sock:/var/run/docker.sock \
5154
-v "$INFERENCE_DIR":/inference \

0 commit comments

Comments
 (0)