Skip to content

Commit d88b68b

Browse files
authored
Add Prometheus TTS latency metrics (#123)
* Add Prometheus TTS latency metrics Introduce Prometheus metrics for TTS latency and record them in the TTS code paths. Adds a new src/prometheus/__init__.py exporting a Histogram (om1_tts_latency) and Gauge (om1_tts_latency_last), instruments both audio_output_stream.py and audio_output_live_stream.py to measure request duration and update the metrics, and adds prometheus-client to pyproject.toml (lockfile updated). This provides visibility into TTS processing latency for monitoring. * Update poetry.lock content-hash Regenerated Poetry lockfile, updating the content-hash. No other dependency or source changes were made; this reflects a lockfile refresh (e.g., after running `poetry lock`). * Bump urllib3 to 2.7.0 Add urllib3 2.7.0 to pyproject.toml and update poetry.lock to reflect the upgrade. The lockfile bumps urllib3 from 2.6.3 to 2.7.0, updates its python-versions requirement to >=3.10, and refreshes package file hashes and the lockfile content-hash.
1 parent febd4a5 commit d88b68b

5 files changed

Lines changed: 78 additions & 27 deletions

File tree

poetry.lock

Lines changed: 43 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ packages = [
88
{ include = "om1_speech", from = "src" },
99
{ include = "om1_utils", from = "src" },
1010
{ include = "om1_vlm", from = "src" },
11-
{ include = "zenoh_msgs", from = "src" }
11+
{ include = "zenoh_msgs", from = "src" },
12+
{ include = "prometheus", from = "src" }
1213
]
1314

1415
[tool.poetry.scripts]
@@ -33,6 +34,8 @@ av = "^15.1.0"
3334
vulture = "^2.14"
3435
openai= "1.60.1"
3536
filelock = "3.20.3"
37+
prometheus-client = "0.25.0"
38+
urllib3="2.7.0"
3639

3740

3841
[tool.poetry.extras]

src/om1_speech/audio/audio_output_live_stream.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import openai
1212
import zenoh
1313

14+
from prometheus import om1_tts_latency, om1_tts_latency_last
1415
from zenoh_msgs import AudioStatus, String, open_zenoh_session, prepare_header
1516

1617
root_package_name = __name__.split(".")[0] if "." in __name__ else __name__
@@ -205,13 +206,22 @@ def _process_audio(self):
205206
AudioStatus.STATUS_SPEAKER.ACTIVE.value, request_id
206207
)
207208

209+
start_time = time.time()
208210
with self.openai_client.audio.speech.with_streaming_response.create(
209211
model=self._tts_model,
210212
voice=self._tts_voice if tts_request["voice_id"] is None else tts_request["voice_id"], # type: ignore
211213
response_format=self._response_format, # type: ignore
212214
input=tts_request["text"], # type: ignore
213215
extra_body=self._extra_body,
214216
) as response:
217+
218+
om1_tts_latency.labels(model="default").observe(
219+
time.time() - start_time
220+
)
221+
om1_tts_latency_last.labels(model="default").set(
222+
time.time() - start_time
223+
)
224+
215225
for chunk in response.iter_bytes(chunk_size=1024):
216226
if not self.running:
217227
break

src/om1_speech/audio/audio_output_stream.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import requests
1313
import zenoh
1414

15+
from prometheus import om1_tts_latency, om1_tts_latency_last
1516
from zenoh_msgs import AudioStatus, String, open_zenoh_session, prepare_header
1617

1718
root_package_name = __name__.split(".")[0] if "." in __name__ else __name__
@@ -163,6 +164,7 @@ def _process_audio(self):
163164
"""
164165
while self.running:
165166
try:
167+
start_time = time.time()
166168
tts_request = self._pending_requests.get()
167169
response = requests.post(
168170
self._url,
@@ -171,6 +173,14 @@ def _process_audio(self):
171173
timeout=(5, 15),
172174
)
173175
logger.info(f"Received TTS response: {response.status_code}")
176+
177+
om1_tts_latency.labels(model="default").observe(
178+
time.time() - start_time
179+
)
180+
om1_tts_latency_last.labels(model="default").set(
181+
time.time() - start_time
182+
)
183+
174184
if response.status_code == 200:
175185
result = response.json()
176186
if "response" in result:

src/prometheus/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from prometheus_client import Gauge, Histogram
2+
3+
om1_tts_latency = Histogram(
4+
"om1_tts_latency_seconds", "Latency of TTS processing in seconds", ["model"]
5+
)
6+
7+
om1_tts_latency_last = Gauge(
8+
"om1_tts_latency_last_seconds",
9+
"Latency of the last TTS processing in seconds",
10+
["model"],
11+
)

0 commit comments

Comments
 (0)