Skip to content

Commit

Permalink
chore: add histogram metrics for relay compact block verify time
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Aug 28, 2023
1 parent 4eb4224 commit ae77dea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions sync/src/relayer/compact_block_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use ckb_verification::{HeaderError, HeaderVerifier};
use ckb_verification_traits::Verifier;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Instant;

// Keeping in mind that short_ids are expected to occasionally collide.
// On receiving compact-block message,
Expand Down Expand Up @@ -53,6 +54,7 @@ impl<'a> CompactBlockProcess<'a> {
}

pub fn execute(self) -> Status {
let instant = Instant::now();
let shared = self.relayer.shared();
let active_chain = shared.active_chain();
let compact_block = self.message.to_entity();
Expand Down Expand Up @@ -117,6 +119,11 @@ impl<'a> CompactBlockProcess<'a> {
self.relayer
.accept_block(self.nc.as_ref(), self.peer, block);

if let Some(metrics) = ckb_metrics::handle() {
metrics
.ckb_relay_cb_verify_time
.observe(instant.elapsed().as_secs_f64());
}
Status::ok()
}
ReconstructionResult::Missing(transactions, uncles) => {
Expand Down
11 changes: 9 additions & 2 deletions util/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//! [`ckb-metrics-service`]: ../ckb_metrics_service/index.html

use prometheus::{
register_histogram_vec, register_int_counter, register_int_gauge, register_int_gauge_vec,
HistogramVec, IntCounter, IntGauge, IntGaugeVec,
register_histogram, register_histogram_vec, register_int_counter, register_int_gauge,
register_int_gauge_vec, Histogram, HistogramVec, IntCounter, IntGauge, IntGaugeVec,
};
use prometheus_static_metric::make_static_metric;
use std::cell::Cell;
Expand Down Expand Up @@ -48,6 +48,8 @@ pub struct Metrics {
pub ckb_freezer_read: IntCounter,
/// Counter for relay transaction short id collide
pub ckb_relay_transaction_short_id_collide: IntCounter,
/// Histogram for relay compact block verify time
pub ckb_relay_cb_verify_time: Histogram,
/// Counter for relay compact block transaction count
pub ckb_relay_cb_transaction_count: IntCounter,
/// Counter for relay compact block reconstruct ok
Expand Down Expand Up @@ -79,6 +81,11 @@ static METRICS: once_cell::sync::Lazy<Metrics> = once_cell::sync::Lazy::new(|| M
"The CKB relay transaction short id collide"
)
.unwrap(),
ckb_relay_cb_verify_time: register_histogram!(
"ckb_relay_cb_verify_time",
"The CKB relay compact block verify time"
)
.unwrap(),
ckb_relay_cb_transaction_count: register_int_counter!(
"ckb_relay_cb_transaction_count",
"The CKB relay compact block transaction count"
Expand Down

0 comments on commit ae77dea

Please sign in to comment.