1use prometheus::{
5 HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Registry,
6 register_histogram_vec_with_registry, register_int_counter_vec_with_registry,
7 register_int_counter_with_registry, register_int_gauge_vec_with_registry,
8 register_int_gauge_with_registry,
9};
10
11const FINE_GRAINED_LATENCY_SEC_BUCKETS: &[f64] = &[
12 0.001, 0.005, 0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9,
13 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.0, 3.5, 4.0, 5.0, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5,
14 10., 15., 20., 25., 30., 35., 40., 45., 50., 60., 70., 80., 90., 100., 120., 140., 160., 180.,
15 200., 250., 300., 350., 400.,
16];
17
18#[derive(Clone, Debug)]
19pub struct BridgeMetrics {
20 pub(crate) err_build_sui_transaction: IntCounter,
21 pub(crate) err_signature_aggregation: IntCounter,
22 pub(crate) err_signature_aggregation_too_many_failures: IntCounter,
23 pub(crate) err_sui_transaction_submission: IntCounter,
24 pub(crate) err_sui_transaction_submission_too_many_failures: IntCounter,
25 pub(crate) err_sui_transaction_execution: IntCounter,
26 pub(crate) requests_received: IntCounterVec,
27 pub(crate) requests_ok: IntCounterVec,
28 pub(crate) err_requests: IntCounterVec,
29 pub(crate) requests_inflight: IntGaugeVec,
30
31 pub(crate) last_synced_sui_checkpoints: IntGaugeVec,
32 pub(crate) last_finalized_eth_block: IntGauge,
33 pub(crate) last_synced_eth_blocks: IntGaugeVec,
34
35 pub(crate) sui_watcher_received_events: IntCounter,
36 pub(crate) sui_watcher_received_actions: IntCounter,
37 pub(crate) eth_watcher_received_events: IntCounter,
38 pub(crate) eth_watcher_received_actions: IntCounter,
39 pub(crate) eth_watcher_unrecognized_events: IntCounter,
40 pub(crate) action_executor_already_processed_actions: IntCounter,
41 pub(crate) action_executor_signing_queue_received_actions: IntCounter,
42 pub(crate) action_executor_signing_queue_skipped_actions: IntCounter,
43 pub(crate) action_executor_execution_queue_received_actions: IntCounter,
44 pub(crate) action_executor_execution_queue_skipped_actions_due_to_pausing: IntCounter,
45
46 pub(crate) last_observed_actions_seq_num: IntGaugeVec,
47
48 pub(crate) eth_rpc_queries: IntCounterVec,
49 pub(crate) eth_rpc_queries_latency: HistogramVec,
50
51 pub(crate) gas_coin_balance: IntGauge,
52
53 pub(crate) sui_rpc_errors: IntCounterVec,
54 pub(crate) observed_governance_actions: IntCounterVec,
55 pub(crate) current_bridge_voting_rights: IntGaugeVec,
56
57 pub(crate) auth_agg_ok_responses: IntCounterVec,
58 pub(crate) auth_agg_bad_responses: IntCounterVec,
59
60 pub(crate) sui_eth_token_transfer_approved: IntCounter,
61 pub(crate) sui_eth_token_transfer_claimed: IntCounter,
62 pub(crate) eth_sui_token_transfer_approved: IntCounter,
63 pub(crate) eth_sui_token_transfer_claimed: IntCounter,
64}
65
66impl BridgeMetrics {
67 pub fn new(registry: &Registry) -> Self {
68 Self {
69 err_build_sui_transaction: register_int_counter_with_registry!(
70 "bridge_err_build_sui_transaction",
71 "Total number of errors of building sui transactions",
72 registry,
73 )
74 .unwrap(),
75 err_signature_aggregation: register_int_counter_with_registry!(
76 "bridge_err_signature_aggregation",
77 "Total number of errors of aggregating validators signatures",
78 registry,
79 )
80 .unwrap(),
81 err_signature_aggregation_too_many_failures: register_int_counter_with_registry!(
82 "bridge_err_signature_aggregation_too_many_failures",
83 "Total number of continuous failures during validator signature aggregation",
84 registry,
85 )
86 .unwrap(),
87 err_sui_transaction_submission: register_int_counter_with_registry!(
88 "bridge_err_sui_transaction_submission",
89 "Total number of errors of submitting sui transactions",
90 registry,
91 )
92 .unwrap(),
93 err_sui_transaction_submission_too_many_failures: register_int_counter_with_registry!(
94 "bridge_err_sui_transaction_submission_too_many_failures",
95 "Total number of continuous failures to submitting sui transactions",
96 registry,
97 )
98 .unwrap(),
99 err_sui_transaction_execution: register_int_counter_with_registry!(
100 "bridge_err_sui_transaction_execution",
101 "Total number of failures of sui transaction execution",
102 registry,
103 )
104 .unwrap(),
105 requests_received: register_int_counter_vec_with_registry!(
106 "bridge_requests_received",
107 "Total number of requests received in Server, by request type",
108 &["type"],
109 registry,
110 )
111 .unwrap(),
112 requests_ok: register_int_counter_vec_with_registry!(
113 "bridge_requests_ok",
114 "Total number of ok requests, by request type",
115 &["type"],
116 registry,
117 )
118 .unwrap(),
119 err_requests: register_int_counter_vec_with_registry!(
120 "bridge_err_requests",
121 "Total number of erred requests, by request type",
122 &["type"],
123 registry,
124 )
125 .unwrap(),
126 requests_inflight: register_int_gauge_vec_with_registry!(
127 "bridge_requests_inflight",
128 "Total number of inflight requests, by request type",
129 &["type"],
130 registry,
131 )
132 .unwrap(),
133 sui_watcher_received_events: register_int_counter_with_registry!(
134 "bridge_sui_watcher_received_events",
135 "Total number of received events in sui watcher",
136 registry,
137 )
138 .unwrap(),
139 eth_watcher_received_events: register_int_counter_with_registry!(
140 "bridge_eth_watcher_received_events",
141 "Total number of received events in eth watcher",
142 registry,
143 )
144 .unwrap(),
145 sui_watcher_received_actions: register_int_counter_with_registry!(
146 "bridge_sui_watcher_received_actions",
147 "Total number of received actions in sui watcher",
148 registry,
149 )
150 .unwrap(),
151 eth_watcher_received_actions: register_int_counter_with_registry!(
152 "bridge_eth_watcher_received_actions",
153 "Total number of received actions in eth watcher",
154 registry,
155 )
156 .unwrap(),
157 eth_watcher_unrecognized_events: register_int_counter_with_registry!(
158 "bridge_eth_watcher_unrecognized_events",
159 "Total number of unrecognized events in eth watcher",
160 registry,
161 )
162 .unwrap(),
163 action_executor_already_processed_actions: register_int_counter_with_registry!(
164 "bridge_action_executor_already_processed_actions",
165 "Total number of already processed actions action executor",
166 registry,
167 )
168 .unwrap(),
169 action_executor_signing_queue_received_actions: register_int_counter_with_registry!(
170 "bridge_action_executor_signing_queue_received_actions",
171 "Total number of received actions in action executor signing queue",
172 registry,
173 )
174 .unwrap(),
175 action_executor_signing_queue_skipped_actions: register_int_counter_with_registry!(
176 "bridge_action_executor_signing_queue_skipped_actions",
177 "Total number of skipped actions in action executor signing queue",
178 registry,
179 )
180 .unwrap(),
181 action_executor_execution_queue_received_actions: register_int_counter_with_registry!(
182 "bridge_action_executor_execution_queue_received_actions",
183 "Total number of received actions in action executor execution queue",
184 registry,
185 )
186 .unwrap(),
187 action_executor_execution_queue_skipped_actions_due_to_pausing: register_int_counter_with_registry!(
188 "bridge_action_executor_execution_queue_skipped_actions_due_to_pausing",
189 "Total number of skipped actions in action executor execution queue because of pausing",
190 registry,
191 )
192 .unwrap(),
193 gas_coin_balance: register_int_gauge_with_registry!(
194 "bridge_gas_coin_balance",
195 "Current balance of gas coin, in mist",
196 registry,
197 )
198 .unwrap(),
199 eth_rpc_queries: register_int_counter_vec_with_registry!(
200 "bridge_eth_rpc_queries",
201 "Total number of queries issued to eth provider, by request type",
202 &["type"],
203 registry,
204 )
205 .unwrap(),
206 eth_rpc_queries_latency: register_histogram_vec_with_registry!(
207 "bridge_eth_rpc_queries_latency",
208 "Latency of queries issued to eth provider, by request type",
209 &["type"],
210 FINE_GRAINED_LATENCY_SEC_BUCKETS.to_vec(),
211 registry,
212 )
213 .unwrap(),
214 last_synced_sui_checkpoints: register_int_gauge_vec_with_registry!(
215 "bridge_last_synced_sui_checkpoints",
216 "The latest sui checkpoints synced for each module",
217 &["module_name"],
218 registry,
219 )
220 .unwrap(),
221 last_synced_eth_blocks: register_int_gauge_vec_with_registry!(
222 "bridge_last_synced_eth_blocks",
223 "The latest synced eth blocks synced for each contract",
224 &["contract_address"],
225 registry,
226 )
227 .unwrap(),
228 last_finalized_eth_block: register_int_gauge_with_registry!(
229 "bridge_last_finalized_eth_block",
230 "The latest finalized eth block observed",
231 registry,
232 )
233 .unwrap(),
234 last_observed_actions_seq_num: register_int_gauge_vec_with_registry!(
235 "bridge_last_observed_actions_seq_num",
236 "The latest observed action sequence number per chain_id and action_type",
237 &["chain_id", "action_type"],
238 registry,
239 )
240 .unwrap(),
241 sui_rpc_errors: register_int_counter_vec_with_registry!(
242 "bridge_sui_rpc_errors",
243 "Total number of errors from sui RPC, by RPC method",
244 &["method"],
245 registry,
246 )
247 .unwrap(),
248 observed_governance_actions: register_int_counter_vec_with_registry!(
249 "bridge_observed_governance_actions",
250 "Total number of observed governance actions",
251 &["action_type", "chain_id"],
252 registry,
253 )
254 .unwrap(),
255 current_bridge_voting_rights: register_int_gauge_vec_with_registry!(
256 "current_bridge_voting_rights",
257 "Current voting power in the bridge committee",
258 &["authority"],
259 registry
260 )
261 .unwrap(),
262 auth_agg_ok_responses: register_int_counter_vec_with_registry!(
263 "bridge_auth_agg_ok_responses",
264 "Total number of ok response from auth agg",
265 &["authority"],
266 registry,
267 )
268 .unwrap(),
269 auth_agg_bad_responses: register_int_counter_vec_with_registry!(
270 "bridge_auth_agg_bad_responses",
271 "Total number of bad response from auth agg",
272 &["authority"],
273 registry,
274 )
275 .unwrap(),
276 sui_eth_token_transfer_approved: register_int_counter_with_registry!(
277 "bridge_sui_eth_token_transfer_approved",
278 "Total number of approved sui to eth token transfers (since metric introduced). \
279 Should be used to track rates rather than absolute values.",
280 registry,
281 )
282 .unwrap(),
283 sui_eth_token_transfer_claimed: register_int_counter_with_registry!(
284 "bridge_sui_eth_token_transfer_claimed",
285 "Total number of claimed sui to eth token transfers (since metric introduced). \
286 Should be used to track rates rather than absolute values.",
287 registry,
288 )
289 .unwrap(),
290 eth_sui_token_transfer_approved: register_int_counter_with_registry!(
291 "bridge_eth_sui_token_transfer_approved",
292 "Total number of approved eth to sui token transfers (since metric introduced). \
293 Should be used to track rates rather than absolute values.",
294 registry,
295 )
296 .unwrap(),
297 eth_sui_token_transfer_claimed: register_int_counter_with_registry!(
298 "bridge_eth_sui_token_transfer_claimed",
299 "Total number of claimed eth to sui token transfers (since metric introduced). \
300 Should be used to track rates rather than absolute values.",
301 registry,
302 )
303 .unwrap(),
304 }
305 }
306
307 pub fn new_for_testing() -> Self {
308 let registry = Registry::new();
309 Self::new(®istry)
310 }
311}