Skip to content

Commit

Permalink
fix: Continue to update metrics as moving backward through already in…
Browse files Browse the repository at this point in the history
…dexed sequences (hyperlane-xyz#5579)

### Description

Currently, backward cursor metrics get stuck in the middle of allowed
range if there is nothing else left to reindex. The metric becomes
misleading suggesting that backward cursor does not make progress.
Actually, backward cursor has finished indexing and hanging on sequence
0.

### Drive-by

Made `update_metrics` method sync.

### Backward compatibility

Yes

### Testing

None

---------

Co-authored-by: Danil Nemirovsky <[email protected]>
  • Loading branch information
ameten and ameten authored Feb 27, 2025
1 parent 0d49a35 commit 6723512
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ impl<T: Debug + Clone + Sync + Send + Indexable + 'static> BackwardSequenceAware

self.current_indexing_snapshot = self.last_indexed_snapshot.previous_target();

// Update metrics during fast-forward (actually backward in this case) so that
// the metrics do not stuck on the last indexed sequence.
self.update_metrics();

debug!(
last_indexed_snapshot=?self.last_indexed_snapshot,
current_indexing_snapshot=?self.current_indexing_snapshot,
Expand Down Expand Up @@ -345,7 +349,7 @@ impl<T: Debug + Clone + Sync + Send + Indexable + 'static> BackwardSequenceAware
}

/// Updates the cursor metrics.
async fn update_metrics(&self) {
fn update_metrics(&self) {
let labels = hashmap! {
"event_type" => T::name(),
"chain" => self.domain.name(),
Expand Down Expand Up @@ -403,7 +407,7 @@ impl<T: Debug + Clone + Sync + Send + Indexable + 'static> ContractSyncCursor<T>
logs: Vec<(Indexed<T>, LogMeta)>,
range: RangeInclusive<u32>,
) -> Result<()> {
self.update_metrics().await;
self.update_metrics();
let Some(current_indexing_snapshot) = self.current_indexing_snapshot.clone() else {
// We're synced, no need to update at all.
return Ok(());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<T: Debug + Clone + Sync + Send + Indexable + 'static> ForwardSequenceAwareS

// for updating metrics even if there's no indexable events available
let max_sequence = onchain_sequence_count.saturating_sub(1) as i64;
self.update_metrics(max_sequence).await;
self.update_metrics(max_sequence);

let current_sequence = self.current_indexing_snapshot.sequence;
let range = match current_sequence.cmp(&onchain_sequence_count) {
Expand Down Expand Up @@ -425,7 +425,7 @@ impl<T: Debug + Clone + Sync + Send + Indexable + 'static> ForwardSequenceAwareS
}

// Updates the cursor metrics.
async fn update_metrics(&self, max_sequence: i64) {
fn update_metrics(&self, max_sequence: i64) {
let mut labels = hashmap! {
"event_type" => T::name(),
"chain" => self.domain.name(),
Expand Down

0 comments on commit 6723512

Please sign in to comment.