Skip to content

Commit

Permalink
fix(metrics): update latest ingested block on reorg (#515)
Browse files Browse the repository at this point in the history
Chainhook's `chainhook_stx_highest_block_ingested` and
`chainhook_btc_highest_block_ingested` metrics were not being updated on
a reorg. This was causing the Chainhook node to appear to be lagging
behing the source chains, event though Chainhook's reorg handler was
functioning properly.

This PR sets the highest block ingested metrics on a reorg based on the
highest index block being applied in the reorg.
  • Loading branch information
MicaiahReid committed Mar 27, 2024
1 parent b198b5e commit e6c5b7e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions components/chainhook-sdk/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,16 @@ pub async fn start_observer_commands_handler(
.iter()
.max_by_key(|b| b.block_identifier.index)
{
Some(highest_tip_block) => prometheus_monitoring.btc_metrics_set_reorg(
highest_tip_block.timestamp.into(),
blocks_to_apply.len() as u64,
blocks_to_rollback.len() as u64,
),
Some(highest_tip_block) => {
prometheus_monitoring.btc_metrics_set_reorg(
highest_tip_block.timestamp.into(),
blocks_to_apply.len() as u64,
blocks_to_rollback.len() as u64,
);
prometheus_monitoring.btc_metrics_ingest_block(
highest_tip_block.block_identifier.index,
);
}
None => {}
}

Expand Down Expand Up @@ -1183,12 +1188,16 @@ pub async fn start_observer_commands_handler(
.iter()
.max_by_key(|b| b.block.block_identifier.index)
{
Some(highest_tip_update) => prometheus_monitoring
.stx_metrics_set_reorg(
Some(highest_tip_update) => {
prometheus_monitoring.stx_metrics_set_reorg(
highest_tip_update.block.timestamp,
update.blocks_to_apply.len() as u64,
update.blocks_to_rollback.len() as u64,
),
);
prometheus_monitoring.stx_metrics_ingest_block(
highest_tip_update.block.block_identifier.index,
)
}
None => {}
}
}
Expand Down

0 comments on commit e6c5b7e

Please sign in to comment.