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