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