diff --git a/app.py b/app.py index 4f177c3..3f654ed 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,5 @@ +import os +import logging from fastapi import FastAPI, HTTPException, responses, status, Request from pydantic import BaseModel from typing import Union, Dict, Optional @@ -5,9 +7,25 @@ import submodules.model.business_objects.general as general from controller import stats from controller import integration +from submodules.model import telemetry -# API creation and description -app = FastAPI() + +OTLP_GRPC_ENDPOINT = os.getenv("OTLP_GRPC_ENDPOINT", "tempo:4317") + +app_name = "refinery-weak-supervisor" +app = FastAPI(title=app_name) + +if telemetry.ENABLE_TELEMETRY: + print("WARNING: Running telemetry.", flush=True) + telemetry.setting_app_name(app_name) + telemetry.setting_otlp(app, app_name=app_name, endpoint=OTLP_GRPC_ENDPOINT) + app.add_middleware(telemetry.PrometheusMiddleware, app_name=app_name) + app.add_route("/metrics", telemetry.metrics) + + # Filter out /metrics + logging.getLogger("uvicorn.access").addFilter( + lambda record: "GET /metrics" not in record.getMessage() + ) class WeakSupervisionRequest(BaseModel): diff --git a/start b/start index 0433ae3..3daa67e 100755 --- a/start +++ b/start @@ -2,11 +2,13 @@ DEBUG_MODE=false DEBUG_PORT=15677 +ENABLE_TELEMETRY=false -while getopts d flag +while getopts dg flag do case "${flag}" in d) DEBUG_MODE=true;; + g) ENABLE_TELEMETRY=true;; esac done @@ -46,6 +48,7 @@ docker run -d --rm \ -p 7054:80 \ -e POSTGRES=postgresql://postgres:kern@graphql-postgres:5432 \ -e WS_NOTIFY_ENDPOINT="http://refinery-websocket:8080" \ +-e ENABLE_TELEMETRY=$ENABLE_TELEMETRY \ --mount type=bind,source="$(pwd)"/,target=/app \ -v /var/run/docker.sock:/var/run/docker.sock \ -v "$INFERENCE_DIR":/inference \ diff --git a/submodules/model b/submodules/model index 4cdfbd2..fa52e17 160000 --- a/submodules/model +++ b/submodules/model @@ -1 +1 @@ -Subproject commit 4cdfbd240114f22ba493d9a552b812499e0c5298 +Subproject commit fa52e1725d0691979895644d63c0b61728ea771b