From a95168a30cb97457cf8d398e1d87baa287c89582 Mon Sep 17 00:00:00 2001 From: longbowlu Date: Thu, 24 Oct 2024 15:16:40 -0700 Subject: [PATCH] report last_observed_actions_seq_num metrics --- Cargo.lock | 1 + crates/sui-bridge/Cargo.toml | 1 + crates/sui-bridge/src/metrics.rs | 9 +++++++++ crates/sui-bridge/src/orchestrator.rs | 12 +++++++++++- crates/sui-bridge/src/types.rs | 3 ++- crates/sui-types/src/bridge.rs | 28 ++++++++++++++++++--------- 6 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 80e1dc6c34a09..84f751eef4c2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13085,6 +13085,7 @@ dependencies = [ "serde_json", "serde_with 3.9.0", "shared-crypto", + "strum_macros 0.24.3", "sui-authority-aggregation", "sui-config", "sui-json-rpc-api", diff --git a/crates/sui-bridge/Cargo.toml b/crates/sui-bridge/Cargo.toml index 8ed6d95cdeb64..49b28a3f7fe79 100644 --- a/crates/sui-bridge/Cargo.toml +++ b/crates/sui-bridge/Cargo.toml @@ -12,6 +12,7 @@ tokio = { workspace = true, features = ["full"] } sui-types.workspace = true sui-authority-aggregation.workspace = true arc-swap.workspace = true +strum_macros.workspace = true num_enum.workspace = true move-core-types.workspace = true url.workspace = true diff --git a/crates/sui-bridge/src/metrics.rs b/crates/sui-bridge/src/metrics.rs index c147787dc11c6..6b9126e96bbd0 100644 --- a/crates/sui-bridge/src/metrics.rs +++ b/crates/sui-bridge/src/metrics.rs @@ -103,6 +103,8 @@ pub struct BridgeMetrics { pub(crate) action_executor_execution_queue_received_actions: IntCounter, pub(crate) action_executor_execution_queue_skipped_actions_due_to_pausing: IntCounter, + pub(crate) last_observed_actions_seq_num: IntGaugeVec, + pub(crate) signer_with_cache_hit: IntCounterVec, pub(crate) signer_with_cache_miss: IntCounterVec, @@ -293,6 +295,13 @@ impl BridgeMetrics { registry, ) .unwrap(), + last_observed_actions_seq_num: register_int_gauge_vec_with_registry!( + "bridge_last_observed_actions_seq_num", + "The latest observed action sequence number per chain_id and action_type", + &["chain_id", "action_type"], + registry, + ) + .unwrap(), signer_with_cache_hit: register_int_counter_vec_with_registry!( "bridge_signer_with_cache_hit", "Total number of hit in signer's cache, by verifier type", diff --git a/crates/sui-bridge/src/orchestrator.rs b/crates/sui-bridge/src/orchestrator.rs index dcd89f7b8eef7..f5809baf78d36 100644 --- a/crates/sui-bridge/src/orchestrator.rs +++ b/crates/sui-bridge/src/orchestrator.rs @@ -160,6 +160,10 @@ where if let Some(action) = bridge_event .try_into_bridge_action(sui_event.id.tx_digest, sui_event.id.event_seq as u16) { + metrics.last_observed_actions_seq_num.with_label_values(&[ + action.chain_id().to_string().as_str(), + action.action_type().to_string().as_str(), + ]); actions.push(action); } } @@ -238,7 +242,13 @@ where .expect("Sending event to monitor channel should not fail"); match bridge_event.try_into_bridge_action(log.tx_hash, log.log_index_in_tx) { - Ok(Some(action)) => actions.push(action), + Ok(Some(action)) => { + metrics.last_observed_actions_seq_num.with_label_values(&[ + action.chain_id().to_string().as_str(), + action.action_type().to_string().as_str(), + ]); + actions.push(action) + } Ok(None) => {} Err(e) => { error!(eth_tx_hash=?log.tx_hash, eth_event_index=?log.log_index_in_tx, "Error converting EthBridgeEvent to BridgeAction: {:?}", e); diff --git a/crates/sui-bridge/src/types.rs b/crates/sui-bridge/src/types.rs index 13aba4d461839..ef453a95c2019 100644 --- a/crates/sui-bridge/src/types.rs +++ b/crates/sui-bridge/src/types.rs @@ -23,6 +23,7 @@ use serde::{Deserialize, Serialize}; use shared_crypto::intent::IntentScope; use std::collections::{BTreeMap, BTreeSet}; use std::fmt::Debug; +use strum_macros::Display; use sui_types::base_types::SuiAddress; use sui_types::bridge::{ BridgeChainId, MoveTypeTokenTransferPayload, APPROVAL_THRESHOLD_ADD_TOKENS_ON_EVM, @@ -201,7 +202,7 @@ impl CommitteeTrait for BridgeCommittee { } } -#[derive(Serialize, Copy, Clone, PartialEq, Eq, TryFromPrimitive, Hash)] +#[derive(Serialize, Copy, Clone, PartialEq, Eq, TryFromPrimitive, Hash, Display)] #[repr(u8)] pub enum BridgeActionType { TokenTransfer = 0, diff --git a/crates/sui-types/src/bridge.rs b/crates/sui-types/src/bridge.rs index 661a05cc052de..6a3e4cb13d151 100644 --- a/crates/sui-types/src/bridge.rs +++ b/crates/sui-types/src/bridge.rs @@ -1,14 +1,6 @@ // Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 -use enum_dispatch::enum_dispatch; -use move_core_types::ident_str; -use move_core_types::identifier::IdentStr; -use num_enum::TryFromPrimitive; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use serde_with::serde_as; - use crate::base_types::ObjectID; use crate::base_types::SequenceNumber; use crate::collection_types::LinkedTableNode; @@ -26,6 +18,14 @@ use crate::{ error::SuiError, id::UID, }; +use enum_dispatch::enum_dispatch; +use move_core_types::ident_str; +use move_core_types::identifier::IdentStr; +use num_enum::TryFromPrimitive; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use serde_with::serde_as; +use strum_macros::Display; pub type BridgeInnerDynamicField = Field; pub type BridgeRecordDyanmicField = Field< @@ -71,7 +71,17 @@ pub const TOKEN_ID_USDC: u8 = 3; pub const TOKEN_ID_USDT: u8 = 4; #[derive( - Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy, TryFromPrimitive, JsonSchema, Hash, + Debug, + Serialize, + Deserialize, + PartialEq, + Eq, + Clone, + Copy, + TryFromPrimitive, + JsonSchema, + Hash, + Display, )] #[repr(u8)] pub enum BridgeChainId {