Skip to content

Commit fadaa9a

Browse files
OpenTelemetry monitoring (#103)
* Azure VM Updates * chore: update submodules * perf: add telemetry * fix: hanging docker stop * chore: update submodules * perf: add thread monitoring * chore(opentelemetry): update submodules
1 parent bab6c75 commit fadaa9a

File tree

7 files changed

+34
-24
lines changed

7 files changed

+34
-24
lines changed

app.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
import logging
13
from fastapi import FastAPI, responses, status
24

35

@@ -14,8 +16,25 @@
1416
from submodules.model.business_objects import general
1517
from submodules.model import enums
1618
from submodules.model import session
19+
from submodules.model import telemetry
1720

18-
app = FastAPI()
21+
22+
OTLP_GRPC_ENDPOINT = os.getenv("OTLP_GRPC_ENDPOINT", "tempo:4317")
23+
24+
app_name = "refinery-tokenizer"
25+
app = FastAPI(title=app_name)
26+
27+
if telemetry.ENABLE_TELEMETRY:
28+
print("WARNING: Running telemetry.", flush=True)
29+
telemetry.setting_app_name(app_name)
30+
telemetry.setting_otlp(app, app_name=app_name, endpoint=OTLP_GRPC_ENDPOINT)
31+
app.add_middleware(telemetry.PrometheusMiddleware, app_name=app_name)
32+
app.add_route("/metrics", telemetry.metrics)
33+
34+
# Filter out /metrics
35+
logging.getLogger("uvicorn.access").addFilter(
36+
lambda record: "GET /metrics" not in record.getMessage()
37+
)
1938

2039

2140
@app.middleware("http")

controller/rats_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from datetime import datetime
44
from typing import Optional
55

6-
from misc import daemon
7-
from submodules.model import enums
6+
from submodules.model import enums, daemon
87
from misc.notification import (
98
send_notification_created,
109
)
@@ -42,7 +41,7 @@ def trigger_rats_creation(
4241
attribute_name=tokenization_task.attribute_name,
4342
with_commit=True,
4443
)
45-
daemon.run(
44+
daemon.run_without_db_token(
4645
create_rats_entries,
4746
project_id,
4847
user_id,

controller/task_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
tokenize_calculated_attribute,
55
tokenize_initial_project,
66
)
7-
from submodules.model import enums
7+
from submodules.model import enums, daemon
88
from submodules.model.business_objects import attribute, general, notification, record
99
from submodules.model.business_objects import tokenization
1010
from submodules.model.business_objects.tokenization import create_tokenization_task
11-
from misc import daemon, notification as notification_util
11+
from misc import notification as notification_util
1212
from submodules.model.models import RecordTokenizationTask
1313
from fastapi import status
1414

@@ -48,7 +48,7 @@ def start_tokenization_task(
4848
task = set_up_tokenization_task(
4949
project_id, user_id, enums.RecordTokenizationScope.PROJECT.value
5050
)
51-
daemon.run(
51+
daemon.run_without_db_token(
5252
tokenize_initial_project,
5353
project_id,
5454
user_id,
@@ -69,7 +69,7 @@ def start_tokenization_task(
6969
enums.RecordTokenizationScope.ATTRIBUTE.value,
7070
attribute_name,
7171
)
72-
daemon.run(
72+
daemon.run_without_db_token(
7373
tokenize_calculated_attribute,
7474
project_id,
7575
user_id,
@@ -115,7 +115,7 @@ def start_rats_task(
115115
attribute_name=attribute_name,
116116
with_commit=True,
117117
)
118-
daemon.run(
118+
daemon.run_without_db_token(
119119
create_rats_entries,
120120
project_id,
121121
user_id,

handler/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 misc 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(

misc/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=15671
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

@@ -52,6 +54,7 @@ docker run -d --rm \
5254
-e S3_USE_SSL=0 \
5355
-e WS_NOTIFY_ENDPOINT=http://refinery-websocket:8080 \
5456
-e POSTGRES=postgresql://postgres:kern@graphql-postgres:5432 \
57+
-e ENABLE_TELEMETRY=$ENABLE_TELEMETRY \
5558
-v "$INFERENCE_DIR":/inference \
5659
--mount type=bind,source="$(pwd)"/,target=/app \
5760
-v /var/run/docker.sock:/var/run/docker.sock \

0 commit comments

Comments
 (0)