1use iota_metrics::histogram::Histogram;
7use prometheus::{
8 HistogramVec, IntCounter, IntCounterVec, IntGauge, Registry,
9 register_histogram_vec_with_registry, register_int_counter_vec_with_registry,
10 register_int_counter_with_registry, register_int_gauge_with_registry,
11};
12
13const FINALITY_LATENCY_SEC_BUCKETS: &[f64] = &[
14 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85,
15 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6,
16 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5,
17 7.0, 7.5, 8.0, 8.5, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0,
18 25.0,
19];
20
21#[derive(Clone)]
22pub struct QuorumDriverMetrics {
23 pub(crate) total_requests: IntCounter,
24 pub(crate) total_enqueued: IntCounter,
25 pub(crate) total_ok_responses: IntCounter,
26 pub(crate) total_err_responses: IntCounterVec,
27 pub(crate) attempt_times_ok_response: Histogram,
28
29 pub(crate) current_requests_in_flight: IntGauge,
31
32 pub(crate) total_err_process_tx_responses_with_nonzero_conflicting_transactions: IntCounter,
33 pub(crate) total_attempts_retrying_conflicting_transaction: IntCounter,
34 pub(crate) total_successful_attempts_retrying_conflicting_transaction: IntCounter,
35 pub(crate) total_times_conflicting_transaction_already_finalized_when_retrying: IntCounter,
36 pub(crate) total_retryable_overload_errors: IntCounter,
37 pub(crate) transaction_retry_count: Histogram,
38 pub(crate) current_transactions_in_retry: IntGauge,
39
40 pub(crate) settlement_finality_latency: HistogramVec,
41}
42
43impl QuorumDriverMetrics {
44 pub fn new(registry: &Registry) -> Self {
45 Self {
46 total_requests: register_int_counter_with_registry!(
47 "quorum_driver_total_requests",
48 "Total number of requests received",
49 registry,
50 )
51 .unwrap(),
52 total_enqueued: register_int_counter_with_registry!(
53 "quorum_driver_total_enqueued",
54 "Total number of requests enqueued",
55 registry,
56 )
57 .unwrap(),
58 total_ok_responses: register_int_counter_with_registry!(
59 "quorum_driver_total_ok_responses",
60 "Total number of requests processed with Ok responses",
61 registry,
62 )
63 .unwrap(),
64 total_err_responses: register_int_counter_vec_with_registry!(
65 "quorum_driver_total_err_responses",
66 "Total number of requests returned with Err responses, grouped by error type",
67 &["error"],
68 registry,
69 )
70 .unwrap(),
71 attempt_times_ok_response: Histogram::new_in_registry(
72 "quorum_driver_attempt_times_ok_response",
73 "Total attempt times of ok response",
74 registry,
75 ),
76 current_requests_in_flight: register_int_gauge_with_registry!(
77 "current_requests_in_flight",
78 "Current number of requests being processed in QuorumDriver",
79 registry,
80 )
81 .unwrap(),
82 total_err_process_tx_responses_with_nonzero_conflicting_transactions: register_int_counter_with_registry!(
83 "quorum_driver_total_err_process_tx_responses_with_nonzero_conflicting_transactions",
84 "Total number of err process_tx responses with non empty conflicting transactions",
85 registry,
86 )
87 .unwrap(),
88 total_attempts_retrying_conflicting_transaction: register_int_counter_with_registry!(
89 "quorum_driver_total_attempts_trying_conflicting_transaction",
90 "Total number of attempts to retry a conflicting transaction",
91 registry,
92 )
93 .unwrap(),
94 total_successful_attempts_retrying_conflicting_transaction: register_int_counter_with_registry!(
95 "quorum_driver_total_successful_attempts_trying_conflicting_transaction",
96 "Total number of successful attempts to retry a conflicting transaction",
97 registry,
98 )
99 .unwrap(),
100 total_times_conflicting_transaction_already_finalized_when_retrying: register_int_counter_with_registry!(
101 "quorum_driver_total_times_conflicting_transaction_already_finalized_when_retrying",
102 "Total number of times the conflicting transaction is already finalized when retrying",
103 registry,
104 )
105 .unwrap(),
106 total_retryable_overload_errors: register_int_counter_with_registry!(
107 "quorum_driver_total_retryable_overload_errors",
108 "Total number of transactions experiencing retryable overload error",
109 registry,
110 )
111 .unwrap(),
112 transaction_retry_count: Histogram::new_in_registry(
113 "quorum_driver_transaction_retry_count",
114 "Histogram of transaction retry count",
115 registry,
116 ),
117 current_transactions_in_retry: register_int_gauge_with_registry!(
118 "current_transactions_in_retry",
119 "Current number of transactions in retry loop in QuorumDriver",
120 registry,
121 )
122 .unwrap(),
123 settlement_finality_latency: register_histogram_vec_with_registry!(
124 "quorum_driver_settlement_finality_latency",
125 "Settlement finality latency observed from quorum driver",
126 &["tx_type"],
127 FINALITY_LATENCY_SEC_BUCKETS.to_vec(),
128 registry,
129 )
130 .unwrap(),
131 }
132 }
133
134 pub fn new_for_tests() -> Self {
135 let registry = Registry::new();
136 Self::new(®istry)
137 }
138}