1- use metrics:: { counter , describe_counter , describe_gauge, gauge} ;
1+ use metrics:: { describe_gauge, gauge} ;
22use starknet_api:: block:: BlockNumber ;
33use starknet_sequencer_metrics:: metrics:: { MetricCounter , MetricGauge } ;
44
@@ -9,59 +9,36 @@ pub const STORAGE_HEIGHT: MetricGauge = MetricGauge {
99} ;
1010
1111// Proposal metrics.
12- pub const PROPOSAL_STARTED : MetricCounter = MetricCounter {
13- name : "batcher_proposal_started" ,
14- description : "Counter of proposals started" ,
15- initial_value : 0 ,
16- } ;
17- pub const PROPOSAL_SUCCEEDED : MetricCounter = MetricCounter {
18- name : "batcher_proposal_succeeded" ,
19- description : "Counter of successful proposals" ,
20- initial_value : 0 ,
21- } ;
22- pub const PROPOSAL_FAILED : MetricCounter = MetricCounter {
23- name : "batcher_proposal_failed" ,
24- description : "Counter of failed proposals" ,
25- initial_value : 0 ,
26- } ;
27- pub const PROPOSAL_ABORTED : MetricCounter = MetricCounter {
28- name : "batcher_proposal_aborted" ,
29- description : "Counter of aborted proposals" ,
30- initial_value : 0 ,
31- } ;
12+ pub const PROPOSAL_STARTED : MetricCounter =
13+ MetricCounter :: new ( "batcher_proposal_started" , "Counter of proposals started" , 0 ) ;
14+ pub const PROPOSAL_SUCCEEDED : MetricCounter =
15+ MetricCounter :: new ( "batcher_proposal_succeeded" , "Counter of successful proposals" , 0 ) ;
16+ pub const PROPOSAL_FAILED : MetricCounter =
17+ MetricCounter :: new ( "batcher_proposal_failed" , "Counter of failed proposals" , 0 ) ;
18+ pub const PROPOSAL_ABORTED : MetricCounter =
19+ MetricCounter :: new ( "batcher_proposal_aborted" , "Counter of aborted proposals" , 0 ) ;
3220
3321// Transaction metrics.
34- pub const BATCHED_TRANSACTIONS : MetricCounter = MetricCounter {
35- name : "batcher_batched_transactions" ,
36- description : "Counter of batched transactions" ,
37- initial_value : 0 ,
38- } ;
39- pub const REJECTED_TRANSACTIONS : MetricCounter = MetricCounter {
40- name : "batcher_rejected_transactions" ,
41- description : "Counter of rejected transactions" ,
42- initial_value : 0 ,
43- } ;
22+ pub const BATCHED_TRANSACTIONS : MetricCounter =
23+ MetricCounter :: new ( "batcher_batched_transactions" , "Counter of batched transactions" , 0 ) ;
24+ pub const REJECTED_TRANSACTIONS : MetricCounter =
25+ MetricCounter :: new ( "batcher_rejected_transactions" , "Counter of rejected transactions" , 0 ) ;
4426
4527pub fn register_metrics ( storage_height : BlockNumber ) {
4628 let storage_height_metric = gauge ! ( STORAGE_HEIGHT . name) ;
4729 describe_gauge ! ( STORAGE_HEIGHT . name, STORAGE_HEIGHT . description) ;
4830 #[ allow( clippy:: as_conversions) ]
4931 storage_height_metric. set ( storage_height. 0 as f64 ) ;
5032
51- counter ! ( PROPOSAL_STARTED . name) . absolute ( PROPOSAL_STARTED . initial_value ) ;
52- describe_counter ! ( PROPOSAL_STARTED . name, PROPOSAL_STARTED . description) ;
53- counter ! ( PROPOSAL_SUCCEEDED . name) . absolute ( PROPOSAL_STARTED . initial_value ) ;
54- describe_counter ! ( PROPOSAL_SUCCEEDED . name, PROPOSAL_SUCCEEDED . description) ;
55- counter ! ( PROPOSAL_FAILED . name) . absolute ( PROPOSAL_STARTED . initial_value ) ;
56- describe_counter ! ( PROPOSAL_FAILED . name, PROPOSAL_FAILED . description) ;
57- counter ! ( PROPOSAL_ABORTED . name) . absolute ( PROPOSAL_STARTED . initial_value ) ;
58- describe_counter ! ( PROPOSAL_ABORTED . name, PROPOSAL_ABORTED . description) ;
33+ PROPOSAL_STARTED . register ( ) ;
34+ PROPOSAL_STARTED . register ( ) ;
35+ PROPOSAL_SUCCEEDED . register ( ) ;
36+ PROPOSAL_FAILED . register ( ) ;
37+ PROPOSAL_ABORTED . register ( ) ;
5938
6039 // In case of revert, consider calling `absolute`.
61- counter ! ( BATCHED_TRANSACTIONS . name) . absolute ( PROPOSAL_STARTED . initial_value ) ;
62- describe_counter ! ( BATCHED_TRANSACTIONS . name, BATCHED_TRANSACTIONS . description) ;
63- counter ! ( REJECTED_TRANSACTIONS . name) . absolute ( PROPOSAL_STARTED . initial_value ) ;
64- describe_counter ! ( REJECTED_TRANSACTIONS . name, REJECTED_TRANSACTIONS . description) ;
40+ BATCHED_TRANSACTIONS . register ( ) ;
41+ REJECTED_TRANSACTIONS . register ( ) ;
6542}
6643
6744/// A handle to update the proposal metrics when the proposal is created and dropped.
@@ -72,7 +49,7 @@ pub(crate) struct ProposalMetricsHandle {
7249
7350impl ProposalMetricsHandle {
7451 pub fn new ( ) -> Self {
75- counter ! ( crate :: metrics :: PROPOSAL_STARTED . name ) . increment ( 1 ) ;
52+ PROPOSAL_STARTED . increment ( 1 ) ;
7653 Self { finish_status : ProposalFinishStatus :: Failed }
7754 }
7855
@@ -95,15 +72,9 @@ enum ProposalFinishStatus {
9572impl Drop for ProposalMetricsHandle {
9673 fn drop ( & mut self ) {
9774 match self . finish_status {
98- ProposalFinishStatus :: Succeeded => {
99- counter ! ( crate :: metrics:: PROPOSAL_SUCCEEDED . name) . increment ( 1 )
100- }
101- ProposalFinishStatus :: Aborted => {
102- counter ! ( crate :: metrics:: PROPOSAL_ABORTED . name) . increment ( 1 )
103- }
104- ProposalFinishStatus :: Failed => {
105- counter ! ( crate :: metrics:: PROPOSAL_FAILED . name) . increment ( 1 )
106- }
75+ ProposalFinishStatus :: Succeeded => PROPOSAL_SUCCEEDED . increment ( 1 ) ,
76+ ProposalFinishStatus :: Aborted => PROPOSAL_ABORTED . increment ( 1 ) ,
77+ ProposalFinishStatus :: Failed => PROPOSAL_FAILED . increment ( 1 ) ,
10778 }
10879 }
10980}
0 commit comments