sui_bridge/
metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use 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) sui_watcher_unrecognized_events: IntCounter,
38    pub(crate) eth_watcher_received_events: IntCounter,
39    pub(crate) eth_watcher_received_actions: IntCounter,
40    pub(crate) eth_watcher_unrecognized_events: IntCounter,
41    pub(crate) action_executor_already_processed_actions: IntCounter,
42    pub(crate) action_executor_signing_queue_received_actions: IntCounter,
43    pub(crate) action_executor_signing_queue_skipped_actions: IntCounter,
44    pub(crate) action_executor_execution_queue_received_actions: IntCounter,
45    pub(crate) action_executor_execution_queue_skipped_actions_due_to_pausing: IntCounter,
46
47    pub(crate) last_observed_actions_seq_num: IntGaugeVec,
48
49    pub(crate) eth_rpc_queries: IntCounterVec,
50    pub(crate) eth_rpc_queries_latency: HistogramVec,
51
52    pub(crate) gas_coin_balance: IntGauge,
53
54    pub(crate) sui_rpc_errors: IntCounterVec,
55    pub(crate) observed_governance_actions: IntCounterVec,
56    pub(crate) current_bridge_voting_rights: IntGaugeVec,
57
58    pub(crate) auth_agg_ok_responses: IntCounterVec,
59    pub(crate) auth_agg_bad_responses: IntCounterVec,
60
61    pub(crate) sui_eth_token_transfer_approved: IntCounter,
62    pub(crate) sui_eth_token_transfer_claimed: IntCounter,
63    pub(crate) eth_sui_token_transfer_approved: IntCounter,
64    pub(crate) eth_sui_token_transfer_claimed: IntCounter,
65}
66
67impl BridgeMetrics {
68    pub fn new(registry: &Registry) -> Self {
69        Self {
70            err_build_sui_transaction: register_int_counter_with_registry!(
71                "bridge_err_build_sui_transaction",
72                "Total number of errors of building sui transactions",
73                registry,
74            )
75            .unwrap(),
76            err_signature_aggregation: register_int_counter_with_registry!(
77                "bridge_err_signature_aggregation",
78                "Total number of errors of aggregating validators signatures",
79                registry,
80            )
81            .unwrap(),
82            err_signature_aggregation_too_many_failures: register_int_counter_with_registry!(
83                "bridge_err_signature_aggregation_too_many_failures",
84                "Total number of continuous failures during validator signature aggregation",
85                registry,
86            )
87            .unwrap(),
88            err_sui_transaction_submission: register_int_counter_with_registry!(
89                "bridge_err_sui_transaction_submission",
90                "Total number of errors of submitting sui transactions",
91                registry,
92            )
93            .unwrap(),
94            err_sui_transaction_submission_too_many_failures: register_int_counter_with_registry!(
95                "bridge_err_sui_transaction_submission_too_many_failures",
96                "Total number of continuous failures to submitting sui transactions",
97                registry,
98            )
99            .unwrap(),
100            err_sui_transaction_execution: register_int_counter_with_registry!(
101                "bridge_err_sui_transaction_execution",
102                "Total number of failures of sui transaction execution",
103                registry,
104            )
105            .unwrap(),
106            requests_received: register_int_counter_vec_with_registry!(
107                "bridge_requests_received",
108                "Total number of requests received in Server, by request type",
109                &["type"],
110                registry,
111            )
112            .unwrap(),
113            requests_ok: register_int_counter_vec_with_registry!(
114                "bridge_requests_ok",
115                "Total number of ok requests, by request type",
116                &["type"],
117                registry,
118            )
119            .unwrap(),
120            err_requests: register_int_counter_vec_with_registry!(
121                "bridge_err_requests",
122                "Total number of erred requests, by request type",
123                &["type"],
124                registry,
125            )
126            .unwrap(),
127            requests_inflight: register_int_gauge_vec_with_registry!(
128                "bridge_requests_inflight",
129                "Total number of inflight requests, by request type",
130                &["type"],
131                registry,
132            )
133            .unwrap(),
134            sui_watcher_received_events: register_int_counter_with_registry!(
135                "bridge_sui_watcher_received_events",
136                "Total number of received events in sui watcher",
137                registry,
138            )
139            .unwrap(),
140            eth_watcher_received_events: register_int_counter_with_registry!(
141                "bridge_eth_watcher_received_events",
142                "Total number of received events in eth watcher",
143                registry,
144            )
145            .unwrap(),
146            sui_watcher_received_actions: register_int_counter_with_registry!(
147                "bridge_sui_watcher_received_actions",
148                "Total number of received actions in sui watcher",
149                registry,
150            )
151            .unwrap(),
152            eth_watcher_received_actions: register_int_counter_with_registry!(
153                "bridge_eth_watcher_received_actions",
154                "Total number of received actions in eth watcher",
155                registry,
156            )
157            .unwrap(),
158            sui_watcher_unrecognized_events: register_int_counter_with_registry!(
159                "bridge_sui_watcher_unrecognized_events",
160                "Total number of unrecognized events in sui watcher",
161                registry,
162            )
163            .unwrap(),
164            eth_watcher_unrecognized_events: register_int_counter_with_registry!(
165                "bridge_eth_watcher_unrecognized_events",
166                "Total number of unrecognized events in eth watcher",
167                registry,
168            )
169            .unwrap(),
170            action_executor_already_processed_actions: register_int_counter_with_registry!(
171                "bridge_action_executor_already_processed_actions",
172                "Total number of already processed actions action executor",
173                registry,
174            )
175            .unwrap(),
176            action_executor_signing_queue_received_actions: register_int_counter_with_registry!(
177                "bridge_action_executor_signing_queue_received_actions",
178                "Total number of received actions in action executor signing queue",
179                registry,
180            )
181            .unwrap(),
182            action_executor_signing_queue_skipped_actions: register_int_counter_with_registry!(
183                "bridge_action_executor_signing_queue_skipped_actions",
184                "Total number of skipped actions in action executor signing queue",
185                registry,
186            )
187            .unwrap(),
188            action_executor_execution_queue_received_actions: register_int_counter_with_registry!(
189                "bridge_action_executor_execution_queue_received_actions",
190                "Total number of received actions in action executor execution queue",
191                registry,
192            )
193            .unwrap(),
194            action_executor_execution_queue_skipped_actions_due_to_pausing: register_int_counter_with_registry!(
195                "bridge_action_executor_execution_queue_skipped_actions_due_to_pausing",
196                "Total number of skipped actions in action executor execution queue because of pausing",
197                registry,
198            )
199            .unwrap(),
200            gas_coin_balance: register_int_gauge_with_registry!(
201                "bridge_gas_coin_balance",
202                "Current balance of gas coin, in mist",
203                registry,
204            )
205            .unwrap(),
206            eth_rpc_queries: register_int_counter_vec_with_registry!(
207                "bridge_eth_rpc_queries",
208                "Total number of queries issued to eth provider, by request type",
209                &["type"],
210                registry,
211            )
212            .unwrap(),
213            eth_rpc_queries_latency: register_histogram_vec_with_registry!(
214                "bridge_eth_rpc_queries_latency",
215                "Latency of queries issued to eth provider, by request type",
216                &["type"],
217                FINE_GRAINED_LATENCY_SEC_BUCKETS.to_vec(),
218                registry,
219            )
220            .unwrap(),
221            last_synced_sui_checkpoints: register_int_gauge_vec_with_registry!(
222                "bridge_last_synced_sui_checkpoints",
223                "The latest sui checkpoints synced for each module",
224                &["module_name"],
225                registry,
226            )
227            .unwrap(),
228            last_synced_eth_blocks: register_int_gauge_vec_with_registry!(
229                "bridge_last_synced_eth_blocks",
230                "The latest synced eth blocks synced for each contract",
231                &["contract_address"],
232                registry,
233            )
234            .unwrap(),
235            last_finalized_eth_block: register_int_gauge_with_registry!(
236                "bridge_last_finalized_eth_block",
237                "The latest finalized eth block observed",
238                registry,
239            )
240            .unwrap(),
241            last_observed_actions_seq_num: register_int_gauge_vec_with_registry!(
242                "bridge_last_observed_actions_seq_num",
243                "The latest observed action sequence number per chain_id and action_type",
244                &["chain_id", "action_type"],
245                registry,
246            )
247            .unwrap(),
248            sui_rpc_errors: register_int_counter_vec_with_registry!(
249                "bridge_sui_rpc_errors",
250                "Total number of errors from sui RPC, by RPC method",
251                &["method"],
252                registry,
253            )
254            .unwrap(),
255            observed_governance_actions: register_int_counter_vec_with_registry!(
256                "bridge_observed_governance_actions",
257                "Total number of observed governance actions",
258                &["action_type", "chain_id"],
259                registry,
260            )
261            .unwrap(),
262            current_bridge_voting_rights: register_int_gauge_vec_with_registry!(
263                "current_bridge_voting_rights",
264                "Current voting power in the bridge committee",
265                &["authority"],
266                registry
267            )
268            .unwrap(),
269            auth_agg_ok_responses: register_int_counter_vec_with_registry!(
270                "bridge_auth_agg_ok_responses",
271                "Total number of ok response from auth agg",
272                &["authority"],
273                registry,
274            )
275            .unwrap(),
276            auth_agg_bad_responses: register_int_counter_vec_with_registry!(
277                "bridge_auth_agg_bad_responses",
278                "Total number of bad response from auth agg",
279                &["authority"],
280                registry,
281            )
282            .unwrap(),
283            sui_eth_token_transfer_approved: register_int_counter_with_registry!(
284                "bridge_sui_eth_token_transfer_approved",
285                "Total number of approved 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            sui_eth_token_transfer_claimed: register_int_counter_with_registry!(
291                "bridge_sui_eth_token_transfer_claimed",
292                "Total number of claimed sui to eth 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_approved: register_int_counter_with_registry!(
298                "bridge_eth_sui_token_transfer_approved",
299                "Total number of approved 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            eth_sui_token_transfer_claimed: register_int_counter_with_registry!(
305                "bridge_eth_sui_token_transfer_claimed",
306                "Total number of claimed eth to sui token transfers (since metric introduced). \
307                Should be used to track rates rather than absolute values.",
308                registry,
309            )
310            .unwrap(),
311        }
312    }
313
314    pub fn new_for_testing() -> Self {
315        let registry = Registry::new();
316        Self::new(&registry)
317    }
318}