Skip to content

Commit

Permalink
feat(state sync): record latency of p2p state requests (#12323)
Browse files Browse the repository at this point in the history
Analogous to STATE_SYNC_EXTERNAL_PARTS_REQUEST_DELAY metric for
centralized state sync.
  • Loading branch information
saketh-are authored Oct 28, 2024
1 parent ad92548 commit 251d636
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions chain/client/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,16 @@ pub(crate) static STATE_SYNC_PARTS_TOTAL: LazyLock<IntGaugeVec> = LazyLock::new(
.unwrap()
});

pub(crate) static STATE_SYNC_P2P_REQUEST_DELAY: LazyLock<HistogramVec> = LazyLock::new(|| {
try_create_histogram_vec(
"near_state_sync_p2p_request_delay_sec",
"Latency of state requests to peers",
&["shard_id", "type"],
Some(exponential_buckets(0.001, 2.0, 20).unwrap()),
)
.unwrap()
});

pub(crate) static STATE_SYNC_EXTERNAL_PARTS_REQUEST_DELAY: LazyLock<HistogramVec> =
LazyLock::new(|| {
try_create_histogram_vec(
Expand Down
5 changes: 5 additions & 0 deletions chain/client/src/sync/state/network.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::task_tracker::TaskHandle;
use super::StateSyncDownloadSource;
use crate::metrics;
use crate::sync::state::util::increment_download_count;
use futures::future::BoxFuture;
use futures::FutureExt;
Expand Down Expand Up @@ -180,6 +181,10 @@ impl StateSyncDownloadSourcePeer {
PartIdOrHeader::Header => "header",
};

let _timer = metrics::STATE_SYNC_P2P_REQUEST_DELAY
.with_label_values(&[&key.shard_id.to_string(), &typ])
.start_timer();

handle.set_status("Sending network request");
match request_sender.send_async(network_request).await {
Ok(response) => {
Expand Down

0 comments on commit 251d636

Please sign in to comment.