@@ -294,7 +294,7 @@ pub fn get_txs_and_assert_expected(
294294 assert_eq ! ( txs, expected_txs) ;
295295}
296296
297- #[ derive( Default ) ]
297+ #[ derive( Default , Debug , PartialEq ) ]
298298pub struct MempoolMetrics {
299299 pub txs_received_invoke : u64 ,
300300 pub txs_received_declare : u64 ,
@@ -309,54 +309,73 @@ pub struct MempoolMetrics {
309309 pub get_txs_size : u64 ,
310310 pub delayed_declares_size : u64 ,
311311 pub total_size_in_bytes : u64 ,
312- pub evictions_count : u64 ,
313312 pub transaction_time_spent_until_batched : HistogramValue ,
314313 pub transaction_time_spent_until_committed : HistogramValue ,
315314}
316315
317316impl MempoolMetrics {
318- pub fn verify_metrics ( & self , recorder : & PrometheusRecorder ) {
317+ pub fn from_recorder ( recorder : & PrometheusRecorder ) -> Self {
319318 let metrics = & recorder. handle ( ) . render ( ) ;
320- MEMPOOL_TRANSACTIONS_RECEIVED . assert_eq (
321- metrics,
322- self . txs_received_invoke ,
323- & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: Invoke . into ( ) ) ] ,
324- ) ;
325- MEMPOOL_TRANSACTIONS_RECEIVED . assert_eq (
326- metrics,
327- self . txs_received_declare ,
328- & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: Declare . into ( ) ) ] ,
329- ) ;
330- MEMPOOL_TRANSACTIONS_RECEIVED . assert_eq (
331- metrics,
332- self . txs_received_deploy_account ,
333- & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: DeployAccount . into ( ) ) ] ,
334- ) ;
335- MEMPOOL_TRANSACTIONS_COMMITTED . assert_eq ( metrics, self . txs_committed ) ;
336- MEMPOOL_TRANSACTIONS_DROPPED . assert_eq (
337- metrics,
338- self . txs_dropped_expired ,
339- & [ ( LABEL_NAME_DROP_REASON , DropReason :: Expired . into ( ) ) ] ,
340- ) ;
341- MEMPOOL_TRANSACTIONS_DROPPED . assert_eq (
342- metrics,
343- self . txs_dropped_rejected ,
344- & [ ( LABEL_NAME_DROP_REASON , DropReason :: Rejected . into ( ) ) ] ,
345- ) ;
346- MEMPOOL_TRANSACTIONS_DROPPED . assert_eq (
347- metrics,
348- self . txs_dropped_evicted ,
349- & [ ( LABEL_NAME_DROP_REASON , DropReason :: Evicted . into ( ) ) ] ,
350- ) ;
351- MEMPOOL_POOL_SIZE . assert_eq ( metrics, self . pool_size ) ;
352- MEMPOOL_PRIORITY_QUEUE_SIZE . assert_eq ( metrics, self . priority_queue_size ) ;
353- MEMPOOL_PENDING_QUEUE_SIZE . assert_eq ( metrics, self . pending_queue_size ) ;
354- MEMPOOL_GET_TXS_SIZE . assert_eq ( metrics, self . get_txs_size ) ;
355- MEMPOOL_DELAYED_DECLARES_SIZE . assert_eq ( metrics, self . delayed_declares_size ) ;
356- MEMPOOL_TOTAL_SIZE_BYTES . assert_eq ( metrics, self . total_size_in_bytes ) ;
357- TRANSACTION_TIME_SPENT_UNTIL_BATCHED
358- . assert_eq ( metrics, & self . transaction_time_spent_until_batched ) ;
359- TRANSACTION_TIME_SPENT_UNTIL_COMMITTED
360- . assert_eq ( metrics, & self . transaction_time_spent_until_committed ) ;
319+ Self {
320+ txs_received_invoke : MEMPOOL_TRANSACTIONS_RECEIVED
321+ . parse_numeric_metric :: < u64 > (
322+ metrics,
323+ & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: Invoke . into ( ) ) ] ,
324+ )
325+ . unwrap ( ) ,
326+ txs_received_declare : MEMPOOL_TRANSACTIONS_RECEIVED
327+ . parse_numeric_metric :: < u64 > (
328+ metrics,
329+ & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: Declare . into ( ) ) ] ,
330+ )
331+ . unwrap ( ) ,
332+ txs_received_deploy_account : MEMPOOL_TRANSACTIONS_RECEIVED
333+ . parse_numeric_metric :: < u64 > (
334+ metrics,
335+ & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: DeployAccount . into ( ) ) ] ,
336+ )
337+ . unwrap ( ) ,
338+ txs_committed : MEMPOOL_TRANSACTIONS_COMMITTED
339+ . parse_numeric_metric :: < u64 > ( metrics)
340+ . unwrap ( ) ,
341+ txs_dropped_expired : MEMPOOL_TRANSACTIONS_DROPPED
342+ . parse_numeric_metric :: < u64 > (
343+ metrics,
344+ & [ ( LABEL_NAME_DROP_REASON , DropReason :: Expired . into ( ) ) ] ,
345+ )
346+ . unwrap ( ) ,
347+ txs_dropped_rejected : MEMPOOL_TRANSACTIONS_DROPPED
348+ . parse_numeric_metric :: < u64 > (
349+ metrics,
350+ & [ ( LABEL_NAME_DROP_REASON , DropReason :: Rejected . into ( ) ) ] ,
351+ )
352+ . unwrap ( ) ,
353+ txs_dropped_evicted : MEMPOOL_TRANSACTIONS_DROPPED
354+ . parse_numeric_metric :: < u64 > (
355+ metrics,
356+ & [ ( LABEL_NAME_DROP_REASON , DropReason :: Evicted . into ( ) ) ] ,
357+ )
358+ . unwrap ( ) ,
359+ pool_size : MEMPOOL_POOL_SIZE . parse_numeric_metric :: < u64 > ( metrics) . unwrap ( ) ,
360+ priority_queue_size : MEMPOOL_PRIORITY_QUEUE_SIZE
361+ . parse_numeric_metric :: < u64 > ( metrics)
362+ . unwrap ( ) ,
363+ pending_queue_size : MEMPOOL_PENDING_QUEUE_SIZE
364+ . parse_numeric_metric :: < u64 > ( metrics)
365+ . unwrap ( ) ,
366+ get_txs_size : MEMPOOL_GET_TXS_SIZE . parse_numeric_metric :: < u64 > ( metrics) . unwrap ( ) ,
367+ delayed_declares_size : MEMPOOL_DELAYED_DECLARES_SIZE
368+ . parse_numeric_metric :: < u64 > ( metrics)
369+ . unwrap ( ) ,
370+ total_size_in_bytes : MEMPOOL_TOTAL_SIZE_BYTES
371+ . parse_numeric_metric :: < u64 > ( metrics)
372+ . unwrap ( ) ,
373+ transaction_time_spent_until_batched : TRANSACTION_TIME_SPENT_UNTIL_BATCHED
374+ . parse_histogram_metric ( metrics)
375+ . unwrap ( ) ,
376+ transaction_time_spent_until_committed : TRANSACTION_TIME_SPENT_UNTIL_COMMITTED
377+ . parse_histogram_metric ( metrics)
378+ . unwrap ( ) ,
379+ }
361380 }
362381}
0 commit comments