@@ -47,6 +47,7 @@ use crate::{
4747 } ,
4848 flow_generator:: { flow_map:: Config , FlowMap } ,
4949 handler:: { MiniPacket , PacketHandler } ,
50+ liveness:: { self , ComponentId , ComponentSpec , LivenessRegistry } ,
5051 rpc:: get_timestamp,
5152 utils:: {
5253 bytes:: read_u32_be,
@@ -153,6 +154,7 @@ pub(super) struct AnalyzerModeDispatcher {
153154 pub ( super ) pool_raw_size : usize ,
154155 pub ( super ) flow_generator_thread_handler : Option < JoinHandle < ( ) > > ,
155156 pub ( super ) pipeline_thread_handler : Option < JoinHandle < ( ) > > ,
157+ pub ( super ) liveness_registry : Option < LivenessRegistry > ,
156158 pub ( super ) queue_debugger : Arc < QueueDebugger > ,
157159 pub ( super ) stats_collector : Arc < stats:: Collector > ,
158160 pub ( super ) inner_queue_size : usize ,
@@ -270,13 +272,23 @@ impl AnalyzerModeDispatcher {
270272 let collector_config = base. collector_config . clone ( ) ;
271273 let packet_sequence_output_queue = base. packet_sequence_output_queue . clone ( ) ; // Enterprise Edition Feature: packet-sequence
272274 let stats = base. stats . clone ( ) ;
275+ let liveness_registry = self . liveness_registry . clone ( ) ;
273276 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
274277 let cpu_set = base. options . lock ( ) . unwrap ( ) . cpu_set ;
275278
276279 self . flow_generator_thread_handler . replace (
277280 thread:: Builder :: new ( )
278281 . name ( "dispatcher-packet-to-flow-generator" . to_owned ( ) )
279282 . spawn ( move || {
283+ let liveness = liveness:: register (
284+ liveness_registry. as_ref ( ) ,
285+ ComponentSpec {
286+ id : ComponentId :: new ( "dispatcher-flow-generator" , id as u32 ) ,
287+ display_name : "dispatcher analyzer flow generator" . into ( ) ,
288+ timeout_ms : BaseDispatcher :: LIVENESS_TIMEOUT_MS ,
289+ ..Default :: default ( )
290+ } ,
291+ ) ;
280292 let mut timestamp_map: HashMap < CaptureNetworkType , Duration > = HashMap :: new ( ) ;
281293 let mut batch = Vec :: with_capacity ( HANDLER_BATCH_SIZE ) ;
282294 let mut output_batch = Vec :: with_capacity ( HANDLER_BATCH_SIZE ) ;
@@ -298,7 +310,6 @@ impl AnalyzerModeDispatcher {
298310 warn ! ( "CPU Affinity({:?}) bind error: {:?}." , & cpu_set, e) ;
299311 }
300312 }
301-
302313 while !terminated. load ( Ordering :: Relaxed ) {
303314 let config = Config {
304315 flow : & flow_map_config. load ( ) ,
@@ -309,8 +320,11 @@ impl AnalyzerModeDispatcher {
309320 } ;
310321
311322 match receiver. recv_all ( & mut batch, Some ( Duration :: from_secs ( 1 ) ) ) {
312- Ok ( _) => { }
323+ Ok ( _) => {
324+ liveness. heartbeat ( ) ;
325+ }
313326 Err ( queue:: Error :: Timeout ) => {
327+ liveness. heartbeat ( ) ;
314328 flow_map. inject_flush_ticker ( & config, Duration :: ZERO ) ;
315329 continue ;
316330 }
@@ -535,6 +549,15 @@ impl AnalyzerModeDispatcher {
535549 }
536550
537551 pub ( super ) fn run ( & mut self ) {
552+ let liveness_handle = liveness:: register (
553+ self . liveness_registry . as_ref ( ) ,
554+ ComponentSpec {
555+ id : ComponentId :: new ( "dispatcher" , self . base . is . id as u32 ) ,
556+ display_name : "dispatcher analyzer" . into ( ) ,
557+ timeout_ms : BaseDispatcher :: LIVENESS_TIMEOUT_MS ,
558+ ..Default :: default ( )
559+ } ,
560+ ) ;
538561 let sender_to_parser = self . setup_inner_thread_and_queue ( ) ;
539562 let base = & mut self . base . is ;
540563 info ! ( "Start analyzer dispatcher {}" , base. log_id) ;
@@ -543,6 +566,7 @@ impl AnalyzerModeDispatcher {
543566 let id = base. id ;
544567 let mut batch = Vec :: with_capacity ( HANDLER_BATCH_SIZE ) ;
545568 let mut allocator = Allocator :: new ( self . raw_packet_block_size ) ;
569+ let mut last_liveness = Duration :: ZERO ;
546570 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
547571 let cpu_set = base. options . lock ( ) . unwrap ( ) . cpu_set ;
548572 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
@@ -574,6 +598,7 @@ impl AnalyzerModeDispatcher {
574598 }
575599 }
576600 if recved. is_none ( ) {
601+ liveness_handle. heartbeat ( ) ;
577602 if base. tap_interface_whitelist . next_sync ( Duration :: ZERO ) {
578603 base. need_update_bpf . store ( true , Ordering :: Relaxed ) ;
579604 }
@@ -586,6 +611,10 @@ impl AnalyzerModeDispatcher {
586611 }
587612
588613 let ( packet, timestamp) = recved. unwrap ( ) ;
614+ if timestamp >= last_liveness + BaseDispatcher :: LIVENESS_HEARTBEAT_INTERVAL {
615+ liveness_handle. heartbeat ( ) ;
616+ last_liveness = timestamp;
617+ }
589618
590619 // From here on, ANALYZER mode is different from LOCAL mode
591620 base. counter . rx . fetch_add ( 1 , Ordering :: Relaxed ) ;
@@ -615,6 +644,7 @@ impl AnalyzerModeDispatcher {
615644 let _ = handler. join ( ) ;
616645 }
617646
647+ liveness_handle. pause ( ) ;
618648 self . base . terminate_handler ( ) ;
619649 info ! ( "Stopped dispatcher {}" , self . base. is. log_id) ;
620650 }
0 commit comments