@@ -101,6 +101,35 @@ def from_entries(
101101 )
102102
103103
104+ class ReporterState (str , Enum ):
105+ """State of the DIVA Quality Reporter service."""
106+
107+ STARTING = "starting"
108+ HEALTHY = "healthy"
109+ CATCHING_UP = "catching_up"
110+ STALE = "stale"
111+ ERROR = "error"
112+
113+
114+ class ReporterStatus (BaseModel ):
115+ """Health status of the DIVA Quality Reporter."""
116+
117+ state : ReporterState
118+ kafka_connected : bool
119+ consumer_group : str | None = None
120+ last_poll_at : float | None = None
121+ last_message_at : float | None = None
122+ last_flush_at : float | None = None
123+ seconds_since_last_flush : float | None = None
124+ messages_processed_total : int = 0
125+ current_batch_size : int = 0
126+ validation_pending_messages : int | None = None
127+ validation_pending_by_partition : dict [str , int ] = Field (default_factory = dict )
128+ reconnect_count : int = 0
129+ last_error : str | None = None
130+ is_mock : bool = False
131+
132+
104133class DivaClient :
105134 """Client for DIVA Kafka REST Gateway and Quality Reporter APIs.
106135
@@ -377,3 +406,34 @@ async def get_validation_results(
377406 processed_rows = processed_rows ,
378407 last_requested_at = start_time ,
379408 )
409+
410+ async def get_reporter_status (self ) -> ReporterStatus :
411+ """Fetch health status from DIVA Quality Reporter.
412+
413+ Returns:
414+ ReporterStatus with current health state. Returns ERROR state
415+ on any failure instead of raising.
416+ """
417+ url = self .settings .url_report_status ()
418+
419+ _logger .debug ("Fetching reporter status from DIVA: url=%s" , url )
420+
421+ try :
422+ async with httpx .AsyncClient (
423+ timeout = self .settings .request_timeout
424+ ) as client :
425+ response = await client .get (url , auth = self ._auth )
426+ response .raise_for_status ()
427+ data = response .json ()
428+ return ReporterStatus (** data )
429+ except (
430+ httpx .HTTPStatusError ,
431+ httpx .RequestError ,
432+ Exception ,
433+ ) as e :
434+ _logger .error ("Failed to fetch reporter status: %s" , str (e ))
435+ return ReporterStatus (
436+ state = ReporterState .ERROR ,
437+ kafka_connected = False ,
438+ last_error = str (e ),
439+ )
0 commit comments