1717import time
1818from contextlib import contextmanager
1919from threading import Thread
20- from typing import Any , Optional
20+ from typing import Any
2121from uuid import uuid4
2222
2323import psutil
@@ -334,25 +334,23 @@ def collect_storage_metrics(self) -> None:
334334 active = metrics .get ("active_keys" , 0 )
335335 self .storage_capacity .labels (storage_unit_id = label ).set (capacity )
336336 self .storage_active_keys .labels (storage_unit_id = label ).set (active )
337- self .storage_utilization .labels (storage_unit_id = label ).set (
338- active / capacity if capacity > 0 else 0.0
339- )
337+ self .storage_utilization .labels (storage_unit_id = label ).set (active / capacity if capacity > 0 else 0.0 )
340338 self .storage_memory_rss .labels (storage_unit_id = label ).set (metrics .get ("process_rss_bytes" , 0 ))
341339
342340 # Per-operation request stats
343341 for op_type , op_data in metrics .get ("op_stats" , {}).items ():
344- self .storage_request_ops .labels (
345- storage_unit_id = label , op_type = op_type
346- ). set ( op_data . get ( "request_count" , 0 ))
347- self .storage_request_latency_avg .labels (
348- storage_unit_id = label , op_type = op_type
349- ). set ( op_data . get ( "latency_avg" , 0 ))
350- self .storage_request_latency_p50 .labels (
351- storage_unit_id = label , op_type = op_type
352- ). set ( op_data . get ( "latency_p50" , 0 ))
353- self .storage_request_latency_p99 .labels (
354- storage_unit_id = label , op_type = op_type
355- ). set ( op_data . get ( "latency_p99" , 0 ))
342+ self .storage_request_ops .labels (storage_unit_id = label , op_type = op_type ). set (
343+ op_data . get ( "request_count" , 0 )
344+ )
345+ self .storage_request_latency_avg .labels (storage_unit_id = label , op_type = op_type ). set (
346+ op_data . get ( "latency_avg" , 0 )
347+ )
348+ self .storage_request_latency_p50 .labels (storage_unit_id = label , op_type = op_type ). set (
349+ op_data . get ( "latency_p50" , 0 )
350+ )
351+ self .storage_request_latency_p99 .labels (storage_unit_id = label , op_type = op_type ). set (
352+ op_data . get ( "latency_p99" , 0 )
353+ )
356354 except Exception as e :
357355 logger .warning (f"Failed to collect metrics from storage unit { su_id } : { e } " )
358356
@@ -375,7 +373,7 @@ def _get_or_create_socket(self, su_id: str, su_info: ZMQServerInfo) -> zmq.Socke
375373 self ._zmq_sockets [su_id ] = sock
376374 return sock
377375
378- def _query_storage_unit (self , su_info : ZMQServerInfo , su_id : str ) -> Optional [ dict [str , Any ]] :
376+ def _query_storage_unit (self , su_info : ZMQServerInfo , su_id : str ) -> dict [str , Any ] | None :
379377 """Send a synchronous GET_METRICS request to a single storage unit."""
380378 try :
381379 sock = self ._get_or_create_socket (su_id , su_info )
0 commit comments