Skip to content

Commit 45418eb

Browse files
committed
perf: add telemetry
1 parent 46c500f commit 45418eb

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

app.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
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_otlp(app, app_name=app_name, endpoint=OTLP_GRPC_ENDPOINT)
21+
app.add_middleware(telemetry.PrometheusMiddleware, app_name=app_name)
22+
app.add_route("/metrics", telemetry.metrics)
23+
24+
# Filter out /metrics
25+
logging.getLogger("uvicorn.access").addFilter(
26+
lambda record: "GET /metrics" not in record.getMessage()
27+
)
1128

1229

1330
class WeakSupervisionRequest(BaseModel):

start

Lines changed: 6 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,10 +48,13 @@ 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 \
5255
--network dev-setup_default \
56+
--log-driver=loki \
57+
--log-opt loki-url="http://$HOST_IP:3100/loki/api/v1/push" \
5358
refinery-weak-supervisor-dev $CMD > /dev/null 2>&1
5459
echo -ne '\t\t\t [done]\n'
5560

0 commit comments

Comments
 (0)