1+ use crate :: metrics:: MetricsContext ;
12use crate :: models:: node:: { NodeStatus , OrchestratorNode } ;
23use crate :: plugins:: StatusUpdatePlugin ;
34use crate :: store:: core:: StoreContext ;
@@ -7,7 +8,7 @@ use shared::web3::contracts::core::builder::Contracts;
78use shared:: web3:: wallet:: WalletProvider ;
89use std:: result:: Result ;
910use std:: sync:: Arc ;
10- use std:: time:: Duration ;
11+ use std:: time:: { Duration , Instant } ;
1112use tokio:: time:: interval;
1213
1314pub struct NodeStatusUpdater {
@@ -19,6 +20,7 @@ pub struct NodeStatusUpdater {
1920 disable_ejection : bool ,
2021 heartbeats : Arc < LoopHeartbeats > ,
2122 plugins : Vec < Box < dyn StatusUpdatePlugin > > ,
23+ metrics : Arc < MetricsContext > ,
2224}
2325
2426impl NodeStatusUpdater {
@@ -32,6 +34,7 @@ impl NodeStatusUpdater {
3234 disable_ejection : bool ,
3335 heartbeats : Arc < LoopHeartbeats > ,
3436 plugins : Vec < Box < dyn StatusUpdatePlugin > > ,
37+ metrics : Arc < MetricsContext > ,
3538 ) -> Self {
3639 Self {
3740 store_context,
@@ -42,6 +45,7 @@ impl NodeStatusUpdater {
4245 disable_ejection,
4346 heartbeats,
4447 plugins,
48+ metrics,
4549 }
4650 }
4751
@@ -133,6 +137,7 @@ impl NodeStatusUpdater {
133137 pub async fn process_nodes ( & self ) -> Result < ( ) , anyhow:: Error > {
134138 let nodes = self . store_context . node_store . get_nodes ( ) . await ?;
135139 for node in nodes {
140+ let start_time = Instant :: now ( ) ;
136141 let node = node. clone ( ) ;
137142 let old_status = node. status . clone ( ) ;
138143 let heartbeat = self
@@ -313,6 +318,12 @@ impl NodeStatusUpdater {
313318 }
314319 }
315320 }
321+ // Record status update execution time
322+ let duration = start_time. elapsed ( ) ;
323+ self . metrics . record_status_update_execution_time (
324+ & node. address . to_string ( ) ,
325+ duration. as_secs_f64 ( ) ,
326+ ) ;
316327 }
317328 Ok ( ( ) )
318329 }
@@ -346,6 +357,7 @@ mod tests {
346357 false ,
347358 Arc :: new ( LoopHeartbeats :: new ( & mode) ) ,
348359 vec ! [ ] ,
360+ app_state. metrics . clone ( ) ,
349361 ) ;
350362 let node = OrchestratorNode {
351363 address : Address :: from_str ( "0x0000000000000000000000000000000000000000" ) . unwrap ( ) ,
@@ -450,6 +462,7 @@ mod tests {
450462 false ,
451463 Arc :: new ( LoopHeartbeats :: new ( & mode) ) ,
452464 vec ! [ ] ,
465+ app_state. metrics . clone ( ) ,
453466 ) ;
454467 tokio:: spawn ( async move {
455468 updater
@@ -502,6 +515,7 @@ mod tests {
502515 false ,
503516 Arc :: new ( LoopHeartbeats :: new ( & mode) ) ,
504517 vec ! [ ] ,
518+ app_state. metrics . clone ( ) ,
505519 ) ;
506520 tokio:: spawn ( async move {
507521 updater
@@ -570,6 +584,7 @@ mod tests {
570584 false ,
571585 Arc :: new ( LoopHeartbeats :: new ( & mode) ) ,
572586 vec ! [ ] ,
587+ app_state. metrics . clone ( ) ,
573588 ) ;
574589 tokio:: spawn ( async move {
575590 updater
@@ -648,6 +663,7 @@ mod tests {
648663 false ,
649664 Arc :: new ( LoopHeartbeats :: new ( & mode) ) ,
650665 vec ! [ ] ,
666+ app_state. metrics . clone ( ) ,
651667 ) ;
652668 tokio:: spawn ( async move {
653669 updater
@@ -734,6 +750,7 @@ mod tests {
734750 false ,
735751 Arc :: new ( LoopHeartbeats :: new ( & mode) ) ,
736752 vec ! [ ] ,
753+ app_state. metrics . clone ( ) ,
737754 ) ;
738755 tokio:: spawn ( async move {
739756 updater
@@ -817,6 +834,7 @@ mod tests {
817834 false ,
818835 Arc :: new ( LoopHeartbeats :: new ( & mode) ) ,
819836 vec ! [ ] ,
837+ app_state. metrics . clone ( ) ,
820838 ) ;
821839 tokio:: spawn ( async move {
822840 updater
@@ -894,6 +912,7 @@ mod tests {
894912 false ,
895913 Arc :: new ( LoopHeartbeats :: new ( & mode) ) ,
896914 vec ! [ ] ,
915+ app_state. metrics . clone ( ) ,
897916 ) ;
898917 tokio:: spawn ( async move {
899918 updater
@@ -962,6 +981,7 @@ mod tests {
962981 false ,
963982 Arc :: new ( LoopHeartbeats :: new ( & mode) ) ,
964983 vec ! [ ] ,
984+ app_state. metrics . clone ( ) ,
965985 ) ;
966986 tokio:: spawn ( async move {
967987 updater
0 commit comments