diff --git a/.drone.yml b/.drone.yml index 650ce3f..d2ebb27 100644 --- a/.drone.yml +++ b/.drone.yml @@ -11,7 +11,7 @@ steps: commands: - git submodule init - 'git config --global url."https://github.com/".insteadOf git@github.com:' - - "git submodule update --recursive --remote" + - "git submodule update --recursive" - name: build and publish image: plugins/docker settings: @@ -73,7 +73,7 @@ steps: commands: - git submodule init - 'git config --global url."https://github.com/".insteadOf git@github.com:' - - "git submodule update --recursive --remote" + - "git submodule update --recursive" - name: build and publish image: plugins/docker settings: @@ -109,7 +109,7 @@ steps: commands: - git submodule init - 'git config --global url."https://github.com/".insteadOf git@github.com:' - - "git submodule update --recursive --remote" + - "git submodule update --recursive" - name: build and publish image: plugins/docker settings: @@ -138,7 +138,7 @@ steps: commands: - git submodule init - 'git config --global url."https://github.com/".insteadOf git@github.com:' - - "git submodule update --recursive --remote" + - "git submodule update --recursive" - name: build and publish image: plugins/docker settings: diff --git a/app.py b/app.py index 0e9f191..c86292c 100644 --- a/app.py +++ b/app.py @@ -1,11 +1,29 @@ +import os +import logging from fastapi import FastAPI, responses, status from fastapi.encoders import jsonable_encoder from pydantic import BaseModel from submodules.model.business_objects import general import util -from submodules.model import session +from submodules.model import session, telemetry -app = FastAPI() + +OTLP_GRPC_ENDPOINT = os.getenv("OTLP_GRPC_ENDPOINT", "tempo:4317") + +app_name = "refinery-updater" +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() + ) @app.post("/update_to_newest") diff --git a/daemon.py b/daemon.py deleted file mode 100644 index d87da0e..0000000 --- a/daemon.py +++ /dev/null @@ -1,11 +0,0 @@ -import threading -from typing import Callable - - -def run(target: Callable, *args, **kwargs) -> None: - threading.Thread( - target=target, - args=args, - kwargs=kwargs, - daemon=True, - ).start() diff --git a/requirements-dev.txt b/requirements-dev.txt index 9534895..e4fd425 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,4 @@ -r requirements.txt -httpx==0.25.0 +httpx==0.28.1 pytest==8.1.1 debugpy==1.8.12 \ No newline at end of file diff --git a/start b/start index d5331fc..26f7b14 100755 --- a/start +++ b/start @@ -2,11 +2,13 @@ DEBUG_MODE=false DEBUG_PORT=15674 +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 @@ -39,6 +41,7 @@ docker run -d --rm \ -e NEURAL_SEARCH=http://refinery-neural-search:80 \ -e COGNITION_GATEWAY=http://cognition-gateway:80 \ -e POSTGRES=postgresql://postgres:kern@graphql-postgres:5432 \ +-e ENABLE_TELEMETRY=$ENABLE_TELEMETRY \ --mount type=bind,source="$(pwd)"/,target=/app \ -v /var/run/docker.sock:/var/run/docker.sock \ --network dev-setup_default \ 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