Add metrics for completed file sync

This commit is contained in:
boqiu 2024-08-20 17:32:03 +08:00
parent 47a0e776bd
commit 914fc785de
4 changed files with 19 additions and 9 deletions

View File

@ -0,0 +1,8 @@
use std::sync::Arc;
use metrics::{register_timer, Timer};
lazy_static::lazy_static! {
pub static ref SERIAL_SYNC_FILE_COMPLETED: Arc<dyn Timer> = register_timer("sync_controllers_serial_sync_file_completed");
pub static ref SERIAL_SYNC_CHUNKS_COMPLETED: Arc<dyn Timer> = register_timer("sync_controllers_serial_sync_chunks_completed");
}

View File

@ -1,3 +1,4 @@
mod metrics;
mod peers; mod peers;
mod serial; mod serial;

View File

@ -1,6 +1,6 @@
use crate::context::SyncNetworkContext; use crate::context::SyncNetworkContext;
use crate::controllers::peers::{PeerState, SyncPeers}; use crate::controllers::peers::{PeerState, SyncPeers};
use crate::controllers::{FileSyncGoal, FileSyncInfo}; use crate::controllers::{metrics, FileSyncGoal, FileSyncInfo};
use crate::{Config, InstantWrapper}; use crate::{Config, InstantWrapper};
use file_location_cache::FileLocationCache; use file_location_cache::FileLocationCache;
use libp2p::swarm::DialError; use libp2p::swarm::DialError;
@ -311,15 +311,15 @@ impl SerialSyncController {
.peers .peers
.add_new_peer_with_config(peer_id, addr.clone(), shard_config) .add_new_peer_with_config(peer_id, addr.clone(), shard_config)
{ {
info!(%self.tx_seq, %peer_id, %addr, "Found new peer"); debug!(%self.tx_seq, %peer_id, %addr, "Found new peer");
true true
} else { } else {
// e.g. multiple `AnnounceFile` messages propagated // e.g. multiple `AnnounceFile` messages propagated
debug!(%self.tx_seq, %peer_id, %addr, "Found an existing peer"); trace!(%self.tx_seq, %peer_id, %addr, "Found an existing peer");
false false
} }
} else { } else {
debug!(%self.tx_seq, %peer_id, %addr, "Found peer without shard config"); info!(%self.tx_seq, %peer_id, %addr, "Found peer without shard config");
false false
} }
} }
@ -406,7 +406,6 @@ impl SerialSyncController {
} }
pub async fn on_response(&mut self, from_peer_id: PeerId, response: ChunkArrayWithProof) { pub async fn on_response(&mut self, from_peer_id: PeerId, response: ChunkArrayWithProof) {
debug!(%self.tx_seq, %from_peer_id, "Received RPC response");
if self.handle_on_response_mismatch(from_peer_id) { if self.handle_on_response_mismatch(from_peer_id) {
return; return;
} }
@ -511,6 +510,7 @@ impl SerialSyncController {
// completed to download chunks // completed to download chunks
if !self.goal.is_all_chunks() { if !self.goal.is_all_chunks() {
self.state = SyncState::Completed; self.state = SyncState::Completed;
metrics::SERIAL_SYNC_CHUNKS_COMPLETED.update_since(self.since.0);
return; return;
} }
@ -523,6 +523,7 @@ impl SerialSyncController {
Ok(true) => { Ok(true) => {
info!(%self.tx_seq, "Succeeded to finalize file"); info!(%self.tx_seq, "Succeeded to finalize file");
self.state = SyncState::Completed; self.state = SyncState::Completed;
metrics::SERIAL_SYNC_FILE_COMPLETED.update_since(self.since.0);
} }
Ok(false) => { Ok(false) => {
warn!(?self.tx_id, %self.tx_seq, "Transaction reverted during finalize_tx"); warn!(?self.tx_id, %self.tx_seq, "Transaction reverted during finalize_tx");

View File

@ -68,10 +68,10 @@ impl Default for Config {
// serial sync config // serial sync config
max_chunks_to_request: 2 * 1024, max_chunks_to_request: 2 * 1024,
max_request_failures: 5, max_request_failures: 5,
peer_connect_timeout: Duration::from_secs(5), peer_connect_timeout: Duration::from_secs(15),
peer_disconnect_timeout: Duration::from_secs(5), peer_disconnect_timeout: Duration::from_secs(15),
peer_find_timeout: Duration::from_secs(5), peer_find_timeout: Duration::from_secs(30),
peer_chunks_download_timeout: Duration::from_secs(5), peer_chunks_download_timeout: Duration::from_secs(15),
peer_wait_outgoing_connection_timeout: Duration::from_secs(10), peer_wait_outgoing_connection_timeout: Duration::from_secs(10),
peer_next_chunks_request_wait_timeout: Duration::from_secs(3), peer_next_chunks_request_wait_timeout: Duration::from_secs(3),