@@ -9,7 +9,7 @@ use starknet_api::transaction::TransactionHash;
9
9
use starknet_api:: { contract_address, nonce} ;
10
10
use starknet_mempool_types:: errors:: MempoolError ;
11
11
use starknet_mempool_types:: mempool_types:: { AddTransactionArgs , CommitBlockArgs } ;
12
- use starknet_sequencer_metrics:: metrics:: HistogramValue ;
12
+ use starknet_sequencer_metrics:: metrics:: { HistogramValue , LossyIntoF64 } ;
13
13
14
14
use crate :: mempool:: Mempool ;
15
15
use crate :: metrics:: {
@@ -107,50 +107,6 @@ macro_rules! tx {
107
107
} ;
108
108
}
109
109
110
- // TODO(Yael): Consider moving to a more general place.
111
- /// Compares a metric, by it's name and label if exists, from a metrics str with an expected value
112
- /// and asserts if false.
113
- #[ macro_export]
114
- macro_rules! assert_metric_eq {
115
- ( $metrics: expr, $expected: expr, $metric: ident $( , $labels: expr) ?) => {
116
- let return_value = $metric. parse_numeric_metric:: <u64 >( $metrics $( , $labels) ?) . unwrap( ) ;
117
- assert_eq!(
118
- return_value,
119
- $expected,
120
- "Metric {} did not match expected value. expected value: {}, returned value: {}" ,
121
- stringify!( $metric $( , $labels) ?) , $expected, return_value
122
-
123
- ) ;
124
- } ;
125
- }
126
-
127
- /// Compares a histogram metric value to the expected value. Only the sum and count values are
128
- /// compared, not the quantiles.
129
- #[ macro_export]
130
- macro_rules! assert_metric_histogram_eq {
131
- ( $metrics: expr, $expected: expr, $metric: ident) => {
132
- let return_value = $metric. parse_histogram_metric( $metrics) . unwrap( ) ;
133
- assert_eq!(
134
- return_value. sum,
135
- $expected. sum,
136
- "Histogram {} sum did not match expected value. expected value: {:?}, returned value: \
137
- {:?}",
138
- stringify!( $metric) ,
139
- $expected. sum,
140
- return_value. sum
141
- ) ;
142
- assert_eq!(
143
- return_value. count,
144
- $expected. count,
145
- "Histogram {} count did not match expected value. expected value: {:?}, returned \
146
- value: {:?}",
147
- stringify!( $metric) ,
148
- $expected. count,
149
- return_value. count
150
- ) ;
151
- } ;
152
- }
153
-
154
110
/// Creates an input for `add_tx` with the given field subset (the rest receive default values).
155
111
#[ macro_export]
156
112
macro_rules! add_tx_input {
@@ -367,57 +323,43 @@ pub struct MempoolMetrics {
367
323
impl MempoolMetrics {
368
324
pub fn verify_metrics ( & self , recorder : & PrometheusRecorder ) {
369
325
let metrics = & recorder. handle ( ) . render ( ) ;
370
- assert_metric_eq ! (
326
+ MEMPOOL_TRANSACTIONS_RECEIVED . assert_eq (
371
327
metrics,
372
328
self . txs_received_invoke ,
373
- MEMPOOL_TRANSACTIONS_RECEIVED ,
374
- & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: Invoke . into( ) ) ]
329
+ & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: Invoke . into ( ) ) ] ,
375
330
) ;
376
- assert_metric_eq ! (
331
+ MEMPOOL_TRANSACTIONS_RECEIVED . assert_eq (
377
332
metrics,
378
333
self . txs_received_declare ,
379
- MEMPOOL_TRANSACTIONS_RECEIVED ,
380
- & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: Declare . into( ) ) ]
334
+ & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: Declare . into ( ) ) ] ,
381
335
) ;
382
- assert_metric_eq ! (
336
+ MEMPOOL_TRANSACTIONS_RECEIVED . assert_eq (
383
337
metrics,
384
338
self . txs_received_deploy_account ,
385
- MEMPOOL_TRANSACTIONS_RECEIVED ,
386
- & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: DeployAccount . into( ) ) ]
339
+ & [ ( LABEL_NAME_TX_TYPE , RpcTransactionLabelValue :: DeployAccount . into ( ) ) ] ,
387
340
) ;
388
-
389
- assert_metric_eq ! ( metrics, self . txs_committed, MEMPOOL_TRANSACTIONS_COMMITTED ) ;
390
-
391
- assert_metric_eq ! (
341
+ MEMPOOL_TRANSACTIONS_COMMITTED . assert_eq ( metrics, self . txs_committed ) ;
342
+ MEMPOOL_TRANSACTIONS_DROPPED . assert_eq (
392
343
metrics,
393
344
self . txs_dropped_expired ,
394
- MEMPOOL_TRANSACTIONS_DROPPED ,
395
- & [ ( LABEL_NAME_DROP_REASON , DropReason :: Expired . into( ) ) ]
345
+ & [ ( LABEL_NAME_DROP_REASON , DropReason :: Expired . into ( ) ) ] ,
396
346
) ;
397
-
398
- assert_metric_eq ! (
347
+ MEMPOOL_TRANSACTIONS_DROPPED . assert_eq (
399
348
metrics,
400
349
self . txs_dropped_failed_add_tx_checks ,
401
- MEMPOOL_TRANSACTIONS_DROPPED ,
402
- & [ ( LABEL_NAME_DROP_REASON , DropReason :: FailedAddTxChecks . into( ) ) ]
350
+ & [ ( LABEL_NAME_DROP_REASON , DropReason :: FailedAddTxChecks . into ( ) ) ] ,
403
351
) ;
404
-
405
- assert_metric_eq ! (
352
+ MEMPOOL_TRANSACTIONS_DROPPED . assert_eq (
406
353
metrics,
407
354
self . txs_dropped_rejected ,
408
- MEMPOOL_TRANSACTIONS_DROPPED ,
409
- & [ ( LABEL_NAME_DROP_REASON , DropReason :: Rejected . into( ) ) ]
410
- ) ;
411
-
412
- assert_metric_eq ! ( metrics, self . pool_size, MEMPOOL_POOL_SIZE ) ;
413
- assert_metric_eq ! ( metrics, self . priority_queue_size, MEMPOOL_PRIORITY_QUEUE_SIZE ) ;
414
- assert_metric_eq ! ( metrics, self . pending_queue_size, MEMPOOL_PENDING_QUEUE_SIZE ) ;
415
- assert_metric_eq ! ( metrics, self . get_txs_size, MEMPOOL_GET_TXS_SIZE ) ;
416
- assert_metric_eq ! ( metrics, self . delayed_declares_size, MEMPOOL_DELAYED_DECLARES_SIZE ) ;
417
- assert_metric_histogram_eq ! (
418
- metrics,
419
- self . transaction_time_spent_in_mempool,
420
- TRANSACTION_TIME_SPENT_IN_MEMPOOL
355
+ & [ ( LABEL_NAME_DROP_REASON , DropReason :: Rejected . into ( ) ) ] ,
421
356
) ;
357
+ MEMPOOL_POOL_SIZE . assert_eq ( metrics, self . pool_size . into_f64 ( ) ) ;
358
+ MEMPOOL_PRIORITY_QUEUE_SIZE . assert_eq ( metrics, self . priority_queue_size . into_f64 ( ) ) ;
359
+ MEMPOOL_PENDING_QUEUE_SIZE . assert_eq ( metrics, self . pending_queue_size . into_f64 ( ) ) ;
360
+ MEMPOOL_GET_TXS_SIZE . assert_eq ( metrics, self . get_txs_size . into_f64 ( ) ) ;
361
+ MEMPOOL_DELAYED_DECLARES_SIZE . assert_eq ( metrics, self . delayed_declares_size . into_f64 ( ) ) ;
362
+ TRANSACTION_TIME_SPENT_IN_MEMPOOL
363
+ . assert_eq ( metrics, & self . transaction_time_spent_in_mempool ) ;
422
364
}
423
365
}
0 commit comments