Skip to content

Commit b868d48

Browse files
OpenTelemetry monitoring (#167)
* chore: update submodules * perf: add telemetry * fix: hanging docker stop * chore: update submodules * perf: add thread monitoring * chore(opentelemetry): update submodules
1 parent 369b734 commit b868d48

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

app.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
1-
# -*- coding: utf-8 -*-
21
from fastapi import FastAPI, responses, status, Request
32
from typing import Union
43

54
import torch
5+
import logging
6+
import os
67

78
from src.util import request_util
89
from src.data import data_type
910
import controller
1011

1112
from submodules.model.business_objects import general
12-
from submodules.model import session
13+
from submodules.model import session, telemetry
14+
15+
16+
OTLP_GRPC_ENDPOINT = os.getenv("OTLP_GRPC_ENDPOINT", "tempo:4317")
17+
18+
app_name = "refinery-embedder"
19+
app = FastAPI(title=app_name)
20+
21+
if telemetry.ENABLE_TELEMETRY:
22+
print("WARNING: Running telemetry.", flush=True)
23+
telemetry.setting_app_name(app_name)
24+
telemetry.setting_otlp(app, app_name=app_name, endpoint=OTLP_GRPC_ENDPOINT)
25+
app.add_middleware(telemetry.PrometheusMiddleware, app_name=app_name)
26+
app.add_route("/metrics", telemetry.metrics)
27+
28+
# Filter out /metrics
29+
logging.getLogger("uvicorn.access").addFilter(
30+
lambda record: "GET /metrics" not in record.getMessage()
31+
)
1332

14-
app = FastAPI()
1533

1634
if torch.cuda.is_available():
1735
print(

controller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
PrivatemodeAISentenceEmbedder,
2626
)
2727
from src.embedders.classification.reduce import PCASentenceReducer # noqa: F401
28-
from src.util import daemon, request_util
28+
from src.util import request_util
2929
from src.util.decorator import param_throttle
3030
from src.util.embedders import get_embedder
3131
from src.util.notification import send_project_update, embedding_warning_templates
3232

3333
from submodules.s3 import controller as s3
34-
from submodules.model import enums
34+
from submodules.model import enums, daemon
3535
from submodules.model.business_objects import (
3636
attribute,
3737
embedding,
@@ -120,7 +120,7 @@ def get_docbins(
120120

121121

122122
def manage_encoding_thread(project_id: str, embedding_id: str) -> int:
123-
daemon.run(prepare_run, project_id, embedding_id)
123+
daemon.run_without_db_token(prepare_run, project_id, embedding_id)
124124
return status.HTTP_200_OK
125125

126126

src/util/config_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict, Any, Optional, Union
22
import requests
33
import time
4-
from src.util import daemon
4+
from submodules.model import daemon
55

66
__config = None
77

@@ -25,7 +25,7 @@ def refresh_config():
2525
)
2626
global __config
2727
__config = response.json()
28-
daemon.run(invalidate_after, 3600) # one hour
28+
daemon.run_without_db_token(invalidate_after, 3600) # one hour
2929

3030

3131
def get_config_value(

src/util/daemon.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

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=15675
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

@@ -68,6 +70,7 @@ docker run -d --rm \
6870
-e MODEL_PROVIDER=http://refinery-model-provider:80 \
6971
-e WS_NOTIFY_ENDPOINT="http://refinery-websocket:8080" \
7072
-e NEURAL_SEARCH=http://refinery-neural-search:80 \
73+
-e ENABLE_TELEMETRY=$ENABLE_TELEMETRY \
7174
--mount type=bind,source="$(pwd)"/,target=/app \
7275
-v /var/run/docker.sock:/var/run/docker.sock \
7376
-v "$MODEL_DIR":/models \

0 commit comments

Comments
 (0)