@@ -575,10 +575,6 @@ impl SyntheticDataValidator {
575575 . await
576576 . context ( "Failed to get work keys from the last 24 hours" ) ?;
577577
578- if let Some ( metrics) = & self . metrics {
579- metrics. record_work_keys_to_process ( work_keys. len ( ) as f64 ) ;
580- }
581-
582578 if !work_keys. is_empty ( ) {
583579 info ! (
584580 "Found {} work keys to validate in the last {} seconds creation time" ,
@@ -603,6 +599,8 @@ impl SyntheticDataValidator {
603599 let mut status_check_tasks: Vec < String > = Vec :: new ( ) ;
604600 let mut group_status_check_tasks: Vec < ToplocGroup > = Vec :: new ( ) ;
605601
602+ let mut keys_to_process = 0 ;
603+
606604 for work_key in work_keys {
607605 // Get work info from cache or fetch
608606 let work_info = match self . get_work_info_from_redis ( & work_key) . await ? {
@@ -634,6 +632,7 @@ impl SyntheticDataValidator {
634632 continue ; // Already processed
635633 }
636634 Some ( ValidationResult :: Unknown ) => {
635+ keys_to_process += 1 ;
637636 if self . with_node_grouping {
638637 let check_group = self . get_group ( & work_key) . await ?;
639638 debug ! ( "Group for work key: {:?} | {:?}" , work_key, check_group) ;
@@ -651,6 +650,7 @@ impl SyntheticDataValidator {
651650 }
652651 }
653652 Some ( _) | None => {
653+ keys_to_process += 1 ;
654654 // Needs triggering (covers Pending, Invalidated, and None cases)
655655 if self . with_node_grouping {
656656 debug ! ( "Checking group for work key: {:?}" , work_key) ;
@@ -668,6 +668,10 @@ impl SyntheticDataValidator {
668668 }
669669 }
670670
671+ if let Some ( metrics) = & self . metrics {
672+ metrics. record_work_keys_to_process ( keys_to_process as f64 ) ;
673+ }
674+
671675 Ok ( ValidationPlan {
672676 single_trigger_tasks,
673677 group_trigger_tasks,
@@ -887,6 +891,8 @@ impl SyntheticDataValidator {
887891
888892#[ cfg( test) ]
889893mod tests {
894+ use crate :: metrics:: export_metrics;
895+
890896 use super :: * ;
891897 use alloy:: primitives:: Address ;
892898 use anyhow:: Ok ;
@@ -942,6 +948,7 @@ mod tests {
942948 // Add test to build validation plan
943949 // Since we do not have blockchain access add task infos to redis first
944950 let ( store, contracts) = setup_test_env ( ) ?;
951+ let metrics_context = MetricsContext :: new ( "0" . to_string ( ) , Some ( "0" . to_string ( ) ) ) ;
945952 let mock_storage = MockStorageProvider :: new ( ) ;
946953
947954 // single group
@@ -996,7 +1003,7 @@ mod tests {
9961003 1 ,
9971004 true ,
9981005 false ,
999- None ,
1006+ Some ( metrics_context ) ,
10001007 ) ;
10011008
10021009 let work_keys = vec ! [
@@ -1024,6 +1031,12 @@ mod tests {
10241031 assert_eq ! ( validation_plan. group_trigger_tasks. len( ) , 2 ) ;
10251032 assert_eq ! ( validation_plan. status_check_tasks. len( ) , 0 ) ;
10261033 assert_eq ! ( validation_plan. group_status_check_tasks. len( ) , 1 ) ;
1034+
1035+ let metrics = export_metrics ( ) . unwrap ( ) ;
1036+ assert ! (
1037+ metrics. contains( "validator_work_keys_to_process{pool_id=\" 0\" ,validator_id=\" 0\" } 4" )
1038+ ) ;
1039+
10271040 Ok ( ( ) )
10281041 }
10291042
@@ -1260,7 +1273,6 @@ mod tests {
12601273 assert_eq ! ( plan. group_trigger_tasks[ 0 ] . group_id, group_id) ;
12611274
12621275 let group = validator. get_group ( file_sha) . await ?;
1263- println ! ( "group: {:?}" , group) ;
12641276 assert ! ( group. is_some( ) ) ;
12651277 let group = group. unwrap ( ) ;
12661278 assert_eq ! ( group. group_id, group_id) ;
0 commit comments