add metrics in log sync package

This commit is contained in:
boqiu 2024-08-20 16:12:34 +08:00
parent c1f465e009
commit 24d41f32b2
4 changed files with 19 additions and 3 deletions

2
Cargo.lock generated
View File

@ -4538,6 +4538,8 @@ dependencies = [
"futures-core",
"futures-util",
"jsonrpsee",
"lazy_static",
"metrics",
"serde_json",
"shared_types",
"storage",

View File

@ -22,3 +22,5 @@ contract-interface = { path = "../../common/contract-interface" }
futures-core = "0.3.28"
futures-util = "0.3.28"
thiserror = "1.0.44"
lazy_static = "1.4.0"
metrics = { workspace = true }

View File

@ -0,0 +1,7 @@
use std::sync::Arc;
use metrics::{register_timer, Timer};
lazy_static::lazy_static! {
pub static ref STORE_PUT_TX: Arc<dyn Timer> = register_timer("log_entry_sync_store_put_tx");
}

View File

@ -11,7 +11,7 @@ use std::collections::BTreeMap;
use std::fmt::Debug;
use std::future::Future;
use std::sync::Arc;
use std::time::Duration;
use std::time::{Duration, Instant};
use storage::log_store::{tx_store::BlockHashAndSubmissionIndex, Store};
use task_executor::{ShutdownReason, TaskExecutor};
use tokio::sync::broadcast;
@ -358,7 +358,11 @@ impl LogSyncManager {
}
async fn put_tx_inner(&mut self, tx: Transaction) -> bool {
if let Err(e) = self.store.put_tx(tx.clone()) {
let start_time = Instant::now();
let result = self.store.put_tx(tx.clone());
metrics::STORE_PUT_TX.update_since(start_time);
if let Err(e) = result {
error!("put_tx error: e={:?}", e);
false
} else {
@ -458,3 +462,4 @@ pub(crate) mod config;
mod data_cache;
mod log_entry_fetcher;
mod log_query;
mod metrics;