Skip to content

Commit

Permalink
feat(examples): add metric for latest l2 reference safe head update (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Jul 11, 2024
1 parent 0cb5955 commit fbce137
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/trusted-sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,25 @@ async fn sync(cli: cli::Cli) -> Result<()> {
// Update the reference l2 head.
match l2_provider.latest_block_number().await {
Ok(latest) => {
let prev = metrics::REFERENCE_L2_HEAD.get();
metrics::REFERENCE_L2_HEAD.set(latest as i64);
if latest as i64 > prev {
let time = match std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|s| s.as_secs())
{
Ok(time) => time,
Err(e) => {
error!(target: LOG_TARGET, "Failed to get latest timestamp in seconds: {:?}", e);
continue;
}
};
metrics::LATEST_REF_SAFE_HEAD_UPDATE.set(time as i64);
}
}
Err(e) => {
warn!(target: LOG_TARGET, "Failed to fetch latest reference l2 safe head: {:?}", e);
continue; // retry the reference fetch.
}
}
if advance_cursor_flag {
Expand Down
7 changes: 7 additions & 0 deletions examples/trusted-sync/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ lazy_static! {
pub static ref REFERENCE_L2_HEAD: IntGauge =
register_int_gauge!("trusted_sync_reference_l2_head", "Reference L2 head").expect("Failed to register reference L2 head metric");

/// Tracks the latest reference l2 safe head update.
pub static ref LATEST_REF_SAFE_HEAD_UPDATE: IntGauge = register_int_gauge!(
"trusted_sync_latest_ref_safe_head_update",
"Latest reference L2 safe head update"
)
.expect("Failed to register latest reference L2 safe head update metric");

/// Tracks the number of pipeline steps.
pub static ref PIPELINE_STEPS: GaugeVec = {
let opts = opts!("trusted_sync_pipeline_steps", "Number of pipeline steps");
Expand Down

0 comments on commit fbce137

Please sign in to comment.