Fix corrupted JSONL metrics file due to concurrent writes (#19011)
This commit is contained in:
@@ -87,6 +87,7 @@ class FileRequestMetricsExporter(RequestMetricsExporter):
|
||||
|
||||
# File handler state management
|
||||
self._current_file_handler = None
|
||||
self._current_file_lock = asyncio.Lock()
|
||||
self._current_hour_suffix = None
|
||||
|
||||
def _ensure_file_handler(self, hour_suffix: str):
|
||||
@@ -135,6 +136,7 @@ class FileRequestMetricsExporter(RequestMetricsExporter):
|
||||
current_time = datetime.now()
|
||||
hour_suffix = current_time.strftime("%Y%m%d_%H")
|
||||
|
||||
async with self._current_file_lock:
|
||||
# Ensure correct file handler is open for current hour
|
||||
self._ensure_file_handler(hour_suffix)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user