@@ -13,10 +13,7 @@ use bigdecimal::num_bigint::BigInt;
1313use  eventuals:: Eventual ; 
1414use  indexer_common:: { escrow_accounts:: EscrowAccounts ,  prelude:: SubgraphClient } ; 
1515use  jsonrpsee:: { core:: client:: ClientT ,  http_client:: HttpClientBuilder ,  rpc_params} ; 
16- use  prometheus:: { 
17-     register_counter,  register_counter_vec,  register_gauge_vec,  register_histogram_vec,  Counter , 
18-     CounterVec ,  GaugeVec ,  HistogramVec , 
19- } ; 
16+ use  prometheus:: { register_counter_vec,  register_histogram_vec,  CounterVec ,  HistogramVec } ; 
2017use  ractor:: { Actor ,  ActorProcessingErr ,  ActorRef ,  RpcReplyPort } ; 
2118use  sqlx:: { types:: BigDecimal ,  PgPool } ; 
2219use  tap_aggregator:: jsonrpsee_helpers:: JsonRpcResponse ; 
@@ -46,52 +43,26 @@ use crate::{
4643} ; 
4744
4845lazy_static !  { 
49-     static  ref UNAGGREGATED_FEES :  GaugeVec  = register_gauge_vec!( 
50-         format!( "unaggregated_fees" ) , 
51-         "Unggregated Fees value" , 
52-         & [ "sender" ,  "allocation" ] 
53-     ) 
54-     . unwrap( ) ; 
55- } 
56- 
57- lazy_static !  { 
58-     static  ref RAV_VALUE :  GaugeVec  = register_gauge_vec!( 
59-         format!( "rav_value" ) , 
60-         "Value of the last RAV" , 
61-         & [ "sender" ,  "allocation" ] 
62-     ) 
63-     . unwrap( ) ; 
64- } 
65- 
66- lazy_static !  { 
67-     static  ref CLOSED_SENDER_ALLOCATIONS :  Counter  = register_counter!( 
68-         format!( "closed_sender_allocation" ) , 
46+     static  ref CLOSED_SENDER_ALLOCATIONS :  CounterVec  = register_counter_vec!( 
47+         "tap_closed_sender_allocation_total" , 
6948        "Count of sender-allocation managers closed since the start of the program" , 
49+         & [ "sender" ] 
7050    ) 
7151    . unwrap( ) ; 
72- } 
73- 
74- lazy_static !  { 
7552    static  ref RAVS_CREATED :  CounterVec  = register_counter_vec!( 
76-         format! ( "ravs_created" ) , 
53+         "tap_ravs_created_total" , 
7754        "RAVs updated or created per sender allocation since the start of the program" , 
7855        & [ "sender" ,  "allocation" ] 
7956    ) 
8057    . unwrap( ) ; 
81- } 
82- 
83- lazy_static !  { 
8458    static  ref RAVS_FAILED :  CounterVec  = register_counter_vec!( 
85-         format! ( "ravs_failed" ) , 
59+         "tap_ravs_failed_total" , 
8660        "RAV requests failed since the start of the program" , 
8761        & [ "sender" ,  "allocation" ] 
8862    ) 
8963    . unwrap( ) ; 
90- } 
91- 
92- lazy_static !  { 
9364    static  ref RAV_RESPONSE_TIME :  HistogramVec  = register_histogram_vec!( 
94-         format! ( "rav_response_time" ) , 
65+         "tap_rav_response_time_seconds" , 
9566        "RAV response time per sender" , 
9667        & [ "sender" ] 
9768    ) 
@@ -166,22 +137,15 @@ impl Actor for SenderAllocation {
166137
167138        // update unaggregated_fees 
168139        state. unaggregated_fees  = state. calculate_unaggregated_fee ( ) . await ?; 
140+ 
169141        sender_account_ref. cast ( SenderAccountMessage :: UpdateReceiptFees ( 
170142            allocation_id, 
171143            state. unaggregated_fees . clone ( ) , 
172144        ) ) ?; 
173145
174-         UNAGGREGATED_FEES 
175-             . with_label_values ( & [ & state. sender . to_string ( ) ,  & state. allocation_id . to_string ( ) ] ) 
176-             . set ( state. unaggregated_fees . value  as  f64 ) ; 
177- 
178146        // update rav tracker for sender account 
179147        if  let  Some ( rav)  = & state. latest_rav  { 
180148            sender_account_ref. cast ( SenderAccountMessage :: UpdateRav ( rav. clone ( ) ) ) ?; 
181- 
182-             RAV_VALUE 
183-                 . with_label_values ( & [ & state. sender . to_string ( ) ,  & state. allocation_id . to_string ( ) ] ) 
184-                 . set ( rav. message . valueAggregate  as  f64 ) ; 
185149        } 
186150
187151        tracing:: info!( 
@@ -219,7 +183,9 @@ impl Actor for SenderAllocation {
219183        } 
220184
221185        // Since this is only triggered after allocation is closed will be counted here 
222-         CLOSED_SENDER_ALLOCATIONS . inc ( ) ; 
186+         CLOSED_SENDER_ALLOCATIONS 
187+             . with_label_values ( & [ & state. sender . to_string ( ) ] ) 
188+             . inc ( ) ; 
223189
224190        Ok ( ( ) ) 
225191    } 
@@ -236,21 +202,23 @@ impl Actor for SenderAllocation {
236202            ?message, 
237203            "New SenderAllocation message" 
238204        ) ; 
239-         let  unaggreated_fees  = & mut  state. unaggregated_fees ; 
205+         let  unaggregated_fees  = & mut  state. unaggregated_fees ; 
240206        match  message { 
241207            SenderAllocationMessage :: NewReceipt ( NewReceiptNotification  { 
242208                id,  value :  fees,  ..
243209            } )  => { 
244-                 if  id > unaggreated_fees. last_id  { 
245-                     unaggreated_fees. last_id  = id; 
246-                     unaggreated_fees. value  =
247-                         unaggreated_fees. value . checked_add ( fees) . unwrap_or_else ( || { 
210+                 if  id > unaggregated_fees. last_id  { 
211+                     unaggregated_fees. last_id  = id; 
212+                     unaggregated_fees. value  = unaggregated_fees
213+                         . value 
214+                         . checked_add ( fees) 
215+                         . unwrap_or_else ( || { 
248216                            // This should never happen, but if it does, we want to know about it. 
249217                            error ! ( 
250218                            "Overflow when adding receipt value {} to total unaggregated fees {} \  
251219                             for allocation {} and sender {}. Setting total unaggregated fees to \ 
252220                             u128::MAX.", 
253-                             fees,  unaggreated_fees . value,  state. allocation_id,  state. sender
221+                             fees,  unaggregated_fees . value,  state. allocation_id,  state. sender
254222                        ) ; 
255223                            u128:: MAX 
256224                        } ) ; 
@@ -259,16 +227,9 @@ impl Actor for SenderAllocation {
259227                        . sender_account_ref 
260228                        . cast ( SenderAccountMessage :: UpdateReceiptFees ( 
261229                            state. allocation_id , 
262-                             unaggreated_fees . clone ( ) , 
230+                             unaggregated_fees . clone ( ) , 
263231                        ) ) ?; 
264232                } 
265- 
266-                 UNAGGREGATED_FEES 
267-                     . with_label_values ( & [ 
268-                         & state. sender . to_string ( ) , 
269-                         & state. allocation_id . to_string ( ) , 
270-                     ] ) 
271-                     . set ( state. unaggregated_fees . value  as  f64 ) ; 
272233            } 
273234            // we use a blocking call here to ensure that only one RAV request is running at a time. 
274235            SenderAllocationMessage :: TriggerRAVRequest ( reply)  => { 
@@ -285,7 +246,7 @@ impl Actor for SenderAllocation {
285246            #[ cfg( test) ]  
286247            SenderAllocationMessage :: GetUnaggregatedReceipts ( reply)  => { 
287248                if  !reply. is_closed ( )  { 
288-                     let  _ = reply. send ( unaggreated_fees . clone ( ) ) ; 
249+                     let  _ = reply. send ( unaggregated_fees . clone ( ) ) ; 
289250                } 
290251            } 
291252        } 
@@ -462,6 +423,13 @@ impl SenderAllocationState {
462423                Ok ( rav)  => { 
463424                    self . unaggregated_fees  = self . calculate_unaggregated_fee ( ) . await ?; 
464425                    self . latest_rav  = Some ( rav) ; 
426+                     RAVS_CREATED 
427+                         . with_label_values ( & [ 
428+                             & self . sender . to_string ( ) , 
429+                             & self . allocation_id . to_string ( ) , 
430+                         ] ) 
431+                         . inc ( ) ; 
432+ 
465433                    return  Ok ( ( ) ) ; 
466434                } 
467435                Err ( e)  => { 
@@ -584,16 +552,6 @@ impl SenderAllocationState {
584552                anyhow:: bail!( "Error while verifying and storing RAV: {:?}" ,  e) ; 
585553            } 
586554        } 
587-         RAV_VALUE 
588-             . with_label_values ( & [ & self . sender . to_string ( ) ,  & self . allocation_id . to_string ( ) ] ) 
589-             . set ( expected_rav. clone ( ) . valueAggregate  as  f64 ) ; 
590-         RAVS_CREATED 
591-             . with_label_values ( & [ & self . sender . to_string ( ) ,  & self . allocation_id . to_string ( ) ] ) 
592-             . inc ( ) ; 
593-         UNAGGREGATED_FEES 
594-             . with_label_values ( & [ & self . sender . to_string ( ) ,  & self . allocation_id . to_string ( ) ] ) 
595-             . set ( self . unaggregated_fees . value  as  f64 ) ; 
596- 
597555        Ok ( response. data ) 
598556    } 
599557
0 commit comments