1use mysten_metrics::COUNT_BUCKETS;
5use prometheus::{
6 Histogram, HistogramVec, IntCounter, IntCounterVec, Registry,
7 register_histogram_vec_with_registry, register_histogram_with_registry,
8 register_int_counter_vec_with_registry, register_int_counter_with_registry,
9};
10
11const REQUEST_COUNT_BUCKETS: &[f64] = &[
12 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 15.0, 20.0, 30.0, 60.0, 90.0, 120.0,
13 150.0,
14];
15
16#[derive(Clone)]
18pub struct TransactionDriverMetrics {
19 pub(crate) settlement_finality_latency: HistogramVec,
20 pub(crate) drive_transaction_errors: IntCounterVec,
21 pub(crate) total_transactions_submitted: IntCounterVec,
22 pub(crate) submit_transaction_retries: Histogram,
23 pub(crate) submit_transaction_backups: Histogram,
24 pub(crate) submit_transaction_latency: HistogramVec,
25 pub(crate) validator_submit_transaction_errors: IntCounterVec,
26 pub(crate) validator_submit_transaction_successes: IntCounterVec,
27 pub(crate) executed_transactions: IntCounter,
28 pub(crate) rejection_acks: IntCounterVec,
29 pub(crate) expiration_acks: IntCounterVec,
30 pub(crate) effects_digest_mismatches: IntCounter,
31 pub(crate) transaction_retries: HistogramVec,
32 pub(crate) transaction_fastpath_acked: IntCounterVec,
33 pub(crate) certified_effects_ack_latency: HistogramVec,
34 pub(crate) certified_effects_ack_attempts: IntCounterVec,
35 pub(crate) certified_effects_ack_successes: IntCounterVec,
36 pub(crate) validator_selections: IntCounterVec,
37 pub(crate) submit_amplification_factor: Histogram,
38 pub(crate) latency_check_runs: IntCounter,
39}
40
41impl TransactionDriverMetrics {
42 pub fn new(registry: &Registry) -> Self {
43 Self {
44 settlement_finality_latency: register_histogram_vec_with_registry!(
45 "transaction_driver_settlement_finality_latency",
46 "Settlement finality latency observed from transaction driver",
47 &["tx_type", "ping"],
48 mysten_metrics::LATENCY_SEC_BUCKETS.to_vec(),
49 registry,
50 )
51 .unwrap(),
52 drive_transaction_errors: register_int_counter_vec_with_registry!(
53 "transaction_driver_drive_transaction_errors",
54 "Number of errors observed from drive_transaction() attempts.",
55 &["error_type", "tx_type", "ping"],
56 registry,
57 )
58 .unwrap(),
59 total_transactions_submitted: register_int_counter_vec_with_registry!(
60 "transaction_driver_total_transactions_submitted",
61 "Total number of transactions submitted through the transaction driver",
62 &["tx_type", "ping"],
63 registry,
64 )
65 .unwrap(),
66 submit_transaction_retries: register_histogram_with_registry!(
67 "transaction_driver_submit_transaction_retries",
68 "Number of retries needed for successful transaction submission",
69 REQUEST_COUNT_BUCKETS.to_vec(),
70 registry,
71 )
72 .unwrap(),
73 submit_transaction_backups: register_histogram_with_registry!(
74 "transaction_driver_submit_transaction_backups",
75 "Number of backup requests sent for a transaction submission",
76 REQUEST_COUNT_BUCKETS.to_vec(),
77 registry,
78 )
79 .unwrap(),
80 submit_transaction_latency: register_histogram_vec_with_registry!(
81 "transaction_driver_submit_transaction_latency",
82 "Time in seconds to successfully submit a transaction to a validator.\n\
83 Includes all retries and measures from the start of submission\n\
84 until a validator accepts the transaction.",
85 &["tx_type", "ping"],
86 mysten_metrics::LATENCY_SEC_BUCKETS.to_vec(),
87 registry,
88 )
89 .unwrap(),
90 validator_submit_transaction_errors: register_int_counter_vec_with_registry!(
91 "transaction_driver_validator_submit_transaction_errors",
92 "Number of submit transaction errors by validator",
93 &["validator", "error_type", "tx_type", "ping"],
94 registry,
95 )
96 .unwrap(),
97 validator_submit_transaction_successes: register_int_counter_vec_with_registry!(
98 "transaction_driver_validator_submit_transaction_successes",
99 "Number of successful submit transactions by validator",
100 &["validator", "tx_type", "ping"],
101 registry,
102 )
103 .unwrap(),
104 executed_transactions: register_int_counter_with_registry!(
105 "transaction_driver_executed_transactions",
106 "Number of transactions executed observed by the transaction driver",
107 registry,
108 )
109 .unwrap(),
110 rejection_acks: register_int_counter_vec_with_registry!(
111 "transaction_driver_rejected_acks",
112 "Number of rejection acknowledgments observed by the transaction driver",
113 &["tx_type", "ping"],
114 registry,
115 )
116 .unwrap(),
117 expiration_acks: register_int_counter_vec_with_registry!(
118 "transaction_driver_expiration_acks",
119 "Number of expiration acknowledgments observed by the transaction driver",
120 &["tx_type", "ping"],
121 registry,
122 )
123 .unwrap(),
124 effects_digest_mismatches: register_int_counter_with_registry!(
125 "transaction_driver_effects_digest_mismatches",
126 "Number of effects digest mismatches detected by the transaction driver",
127 registry,
128 )
129 .unwrap(),
130 transaction_retries: register_histogram_vec_with_registry!(
131 "transaction_driver_transaction_retries",
132 "Number of retries per transaction attempt in drive_transaction",
133 &["result", "tx_type", "ping"],
134 REQUEST_COUNT_BUCKETS.to_vec(),
135 registry,
136 )
137 .unwrap(),
138 transaction_fastpath_acked: register_int_counter_vec_with_registry!(
139 "transaction_driver_transaction_fastpath_acked",
140 "Number of transactions that were executed using fast path",
141 &["validator", "ping"],
142 registry,
143 )
144 .unwrap(),
145 certified_effects_ack_latency: register_histogram_vec_with_registry!(
146 "transaction_driver_certified_effects_ack_latency",
147 "Latency in seconds for getting certified effects acknowledgment",
148 &["tx_type", "ping"],
149 mysten_metrics::LATENCY_SEC_BUCKETS.to_vec(),
150 registry,
151 )
152 .unwrap(),
153 certified_effects_ack_attempts: register_int_counter_vec_with_registry!(
154 "transaction_driver_certified_effects_ack_attempts",
155 "Total number of transactions that went through certified effects ack process",
156 &["tx_type", "ping"],
157 registry,
158 )
159 .unwrap(),
160 certified_effects_ack_successes: register_int_counter_vec_with_registry!(
161 "transaction_driver_certified_effects_ack_successes",
162 "Number of successful certified effects acknowledgments",
163 &["tx_type", "ping"],
164 registry,
165 )
166 .unwrap(),
167 validator_selections: register_int_counter_vec_with_registry!(
168 "transaction_driver_validator_selections",
169 "Number of times each validator was selected for transaction submission",
170 &["validator", "tx_type", "ping"],
171 registry,
172 )
173 .unwrap(),
174 submit_amplification_factor: register_histogram_with_registry!(
175 "transaction_driver_submit_amplification_factor",
176 "The amplification factor used by transaction driver to submit to validators",
177 COUNT_BUCKETS.to_vec(),
178 registry,
179 )
180 .unwrap(),
181 latency_check_runs: register_int_counter_with_registry!(
182 "transaction_driver_latency_check_runs",
183 "Number of times the latency check runs for consensus path",
184 registry,
185 )
186 .unwrap(),
187 }
188 }
189
190 pub fn new_for_tests() -> Self {
191 let registry = Registry::new();
192 Self::new(®istry)
193 }
194}