Skip to content

Commit 481e656

Browse files
Fedir Zadniprovskyifedirz
authored andcommitted
feat: add instrumentation
1 parent 849e0df commit 481e656

12 files changed

+662
-24
lines changed

Dockerfile.cpu

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ LABEL org.opencontainers.image.source="https://github.com/fedirz/faster-whisper-
33
# `ffmpeg` is installed because without it `gradio` won't work with mp3(possible others as well) files
44
# hadolint ignore=DL3008
55
RUN apt-get update && \
6-
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ffmpeg python3.12 && \
7-
apt-get clean && \
8-
rm -rf /var/lib/apt/lists/*
6+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ffmpeg python3.12 && \
7+
apt-get clean && \
8+
rm -rf /var/lib/apt/lists/*
99
COPY --from=ghcr.io/astral-sh/uv:0.5.9 /uv /bin/uv
1010
WORKDIR /root/faster-whisper-server
1111
# https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
1212
RUN --mount=type=cache,target=/root/.cache/uv \
13-
--mount=type=bind,source=uv.lock,target=uv.lock \
14-
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
15-
uv sync --frozen --no-install-project
13+
--mount=type=bind,source=uv.lock,target=uv.lock \
14+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
15+
uv sync --frozen --no-install-project
1616
COPY ./src ./pyproject.toml ./uv.lock ./
1717
RUN --mount=type=cache,target=/root/.cache/uv \
18-
uv sync --frozen --extra ui
18+
uv sync --frozen --extra ui
1919
ENV WHISPER__MODEL=Systran/faster-whisper-small
2020
ENV UVICORN_HOST=0.0.0.0
2121
ENV UVICORN_PORT=8000

Dockerfile.cuda

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ LABEL org.opencontainers.image.source="https://github.com/fedirz/faster-whisper-
33
# `ffmpeg` is installed because without it `gradio` won't work with mp3(possible others as well) files
44
# hadolint ignore=DL3008
55
RUN apt-get update && \
6-
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ffmpeg python3.12 && \
7-
apt-get clean && \
8-
rm -rf /var/lib/apt/lists/*
6+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ffmpeg python3.12 && \
7+
apt-get clean && \
8+
rm -rf /var/lib/apt/lists/*
99
COPY --from=ghcr.io/astral-sh/uv:0.5.9 /uv /bin/uv
1010
WORKDIR /root/faster-whisper-server
1111
# https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
1212
RUN --mount=type=cache,target=/root/.cache/uv \
13-
--mount=type=bind,source=uv.lock,target=uv.lock \
14-
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
15-
uv sync --frozen --no-install-project
13+
--mount=type=bind,source=uv.lock,target=uv.lock \
14+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
15+
uv sync --frozen --no-install-project
1616
COPY ./src ./pyproject.toml ./uv.lock ./
1717
RUN --mount=type=cache,target=/root/.cache/uv \
18-
uv sync --frozen --extra ui
18+
uv sync --frozen --extra ui --extra opentelemetry
1919
ENV WHISPER__MODEL=Systran/faster-whisper-large-v3
2020
ENV UVICORN_HOST=0.0.0.0
2121
ENV UVICORN_PORT=8000
22-
CMD ["uv", "run", "uvicorn", "--factory", "faster_whisper_server.main:create_app"]
22+
CMD ["uv", "run", "opentelemetry-instrument", "uvicorn", "--factory", "faster_whisper_server.main:create_app"]

Taskfile.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ tasks:
33
server:
44
cmds:
55
- pkill --signal SIGKILL --echo --full 'uvicorn --factory --host 0.0.0.0 faster_whisper_server.main:create_app' || true
6-
- uvicorn --factory --host 0.0.0.0 faster_whisper_server.main:create_app {{.CLI_ARGS}}
6+
- opentelemetry-instrument uvicorn --factory --host 0.0.0.0 faster_whisper_server.main:create_app {{.CLI_ARGS}}
77
sources:
88
- src/**/*.py
99
test:

compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# TODO: https://docs.astral.sh/uv/guides/integration/docker/#configuring-watch-with-docker-compose
2+
include:
3+
- observability-compose.yaml
24
services:
35
faster-whisper-server-cuda:
46
image: fedirz/faster-whisper-server:latest-cuda
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: 1
2+
datasources:
3+
- name: tempo
4+
type: tempo
5+
access: proxy
6+
url: http://tempo:3200
7+
editable: true
8+
jsonData:
9+
tracesToLogsV2:
10+
datasourceUid: loki
11+
filterByTraceID: true
12+
lokiSearch:
13+
datasourceUid: loki
14+
- name: loki
15+
type: loki
16+
access: proxy
17+
url: http://loki:3100
18+
editable: true
19+
- name: prometheus
20+
type: prometheus
21+
editable: true
22+
url: http://prometheus:9090
23+
# TODO: https://grafana.com/docs/tempo/latest/getting-started/metrics-from-traces/

configuration/loki.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# https://github.com/grafana/loki/blob/811f5f015cd5da4e25d800307b905c3385406be3/docs/sources/configure/examples/configuration-examples.md
2+
3+
auth_enabled: false # default: true
4+
# https://grafana.com/docs/loki/latest/configure/#server
5+
server:
6+
http_listen_port: 3100 # default: 3100
7+
grpc_listen_port: 9095 # default: 9095
8+
log_level: info # default: info
9+
log_format: json # default: logfmt
10+
limits_config:
11+
allow_structured_metadata: true # needed for OTEL
12+
volume_enabled: true # not sure what this does
13+
common:
14+
ring:
15+
instance_addr: 0.0.0.0
16+
kvstore:
17+
store: inmemory
18+
replication_factor: 1
19+
path_prefix: /tmp/loki
20+
storage_config:
21+
tsdb_shipper:
22+
active_index_directory: /tmp/loki/index
23+
cache_location: /tmp/loki/index_cache
24+
filesystem:
25+
directory: /tmp/loki/chunks
26+
pattern_ingester:
27+
enabled: true
28+
analytics:
29+
reporting_enabled: false # default: true
30+
tracing:
31+
enabled: true # default: false
32+
# https://grafana.com/docs/loki/latest/configure/#schema_config
33+
schema_config:
34+
configs:
35+
- from: 2020-05-15
36+
store: tsdb
37+
object_store: filesystem
38+
schema: v13
39+
index:
40+
prefix: index_
41+
period: 24h
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
grpc:
5+
endpoint: 0.0.0.0:4317
6+
http:
7+
endpoint: 0.0.0.0:4318
8+
processors:
9+
batch:
10+
exporters:
11+
otlp/tempo:
12+
endpoint: http://tempo:4317
13+
tls:
14+
insecure: true
15+
prometheus:
16+
endpoint: 0.0.0.0:8889
17+
otlphttp/loki:
18+
# https://github.com/grafana/loki/issues/5346
19+
# endpoint: http://loki:3100/otlp/v1/logs
20+
endpoint: http://loki:3100/otlp
21+
tls:
22+
insecure: true
23+
debug:
24+
verbosity: detailed
25+
extensions:
26+
health_check:
27+
endpoint: 0.0.0.0:13133 # default port
28+
service:
29+
extensions: [health_check]
30+
telemetry:
31+
logs:
32+
level: debug
33+
# development: true
34+
pipelines:
35+
traces:
36+
receivers: [otlp]
37+
processors: [batch]
38+
exporters: [otlp/tempo]
39+
metrics:
40+
receivers: [otlp]
41+
processors: [batch]
42+
exporters: [prometheus]
43+
logs:
44+
receivers: [otlp]
45+
processors: [batch]
46+
exporters: [otlphttp/loki]

configuration/prometheus.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global:
2+
scrape_interval: 5s
3+
scrape_configs:
4+
- job_name: "opentelemetry-collector"
5+
static_configs:
6+
- targets: ["opentelemetry-collector:8889"]

configuration/tempo.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
server:
2+
http_listen_port: 3200 # default: 80
3+
grpc_listen_port: 9095 # default: 9095
4+
5+
usage_report:
6+
reporting_enabled: false
7+
8+
distributor:
9+
receivers:
10+
otlp:
11+
protocols:
12+
grpc:
13+
14+
# TODO: S3 storage
15+
storage:
16+
trace:
17+
backend: local
18+
local:
19+
path: /tmp/tempo/traces

observability-compose.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
services:
2+
opentelemetry-collector:
3+
image: otel/opentelemetry-collector-contrib:0.107.0
4+
command: ["--config=/etc/opentelemetry-collector.yaml"]
5+
volumes:
6+
- ./configuration/opentelemetry-collector.yaml:/etc/opentelemetry-collector.yaml
7+
ports:
8+
# NOTE: when `faster-whisper-server` is also running as a Docker Compose service, this doesn't need to be exposed.
9+
- 4317:4317 # OTLP gRPC receiver
10+
# - 4318:4318 # OTLP HTTP receiver
11+
# - 8888:8888 # Prometheus metrics exposed by the Collector
12+
# - 8889:8889 # Prometheus exporter metrics
13+
# - 13133:13133 # health_check extension
14+
# NOTE: `healthcheck` can't be set up, as the container doesn't have a shell to run the healthcheck command.
15+
loki:
16+
image: grafana/loki:3.0.0
17+
command: ["-config.file=/etc/loki.yaml"]
18+
volumes:
19+
- ./configuration/loki.yaml:/etc/loki.yaml
20+
- loki-data:/loki
21+
ports:
22+
- "3100:3100"
23+
healthcheck:
24+
# NOTE: doesn't have a proper healthcheck endpoint
25+
test: wget --no-verbose --tries=1 --spider http://localhost:3100/ready || exit 1
26+
interval: 5s
27+
timeout: 5s
28+
retries: 3
29+
prometheus:
30+
image: prom/prometheus:v2.55.0
31+
command: ["--config.file=/etc/prometheus.yaml"]
32+
volumes:
33+
- ./configuration/prometheus.yaml:/etc/prometheus.yaml
34+
- prometheus-data:/prometheus
35+
healthcheck:
36+
test: wget --no-verbose --tries=1 --spider http://localhost:9090/-/healthy || exit 1
37+
interval: 5s
38+
timeout: 5s
39+
retries: 3
40+
tempo:
41+
image: grafana/tempo:2.5.0
42+
command: ["-config.file=/etc/tempo.yaml"]
43+
volumes:
44+
- ./configuration/tempo.yaml:/etc/tempo.yaml
45+
- tempo-data:/tmp
46+
# https://github.com/grafana/tempo/issues/1657#issuecomment-2049987178
47+
# - tempo-data:/tmp/tempo
48+
healthcheck:
49+
test: wget --no-verbose --tries=1 --spider http://localhost:3200/status || exit 1
50+
interval: 5s
51+
timeout: 5s
52+
retries: 3
53+
grafana:
54+
image: grafana/grafana:11.3.0
55+
volumes:
56+
- ./configuration/grafana/datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml
57+
- grafana-data:/var/lib/grafana
58+
environment:
59+
- GF_AUTH_ANONYMOUS_ENABLED=true
60+
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
61+
- GF_AUTH_DISABLE_LOGIN_FORM=true
62+
ports:
63+
- "3000:3000"
64+
healthcheck:
65+
test: wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
66+
interval: 5s
67+
timeout: 5s
68+
retries: 3
69+
volumes:
70+
loki-data:
71+
prometheus-data:
72+
tempo-data:
73+
grafana-data:

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ ui = [
4343
"httpx-sse>=0.4.0",
4444
"openai>=1.48.0",
4545
]
46+
opentelemetry = [
47+
"opentelemetry-distro>=0.48b0",
48+
"opentelemetry-exporter-otlp>=1.27.0",
49+
"opentelemetry-instrumentation-asyncio==0.48b0",
50+
"opentelemetry-instrumentation-logging==0.48b0",
51+
"opentelemetry-instrumentation-threading==0.48b0",
52+
"opentelemetry-instrumentation-urllib==0.48b0",
53+
# "opentelemetry-instrumentation-wsgi==0.48b0"
54+
"opentelemetry-instrumentation-fastapi==0.48b0",
55+
"opentelemetry-instrumentation-grpc==0.48b0",
56+
"opentelemetry-instrumentation-httpx==0.48b0",
57+
"opentelemetry-instrumentation-requests==0.48b0",
58+
"opentelemetry-instrumentation-urllib3==0.48b0",
59+
]
4660

4761
[build-system]
4862
requires = ["hatchling"]

0 commit comments

Comments
 (0)