Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add contract sync liveness metrics #5181

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions rust/main/hyperlane-base/src/contract_sync/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub struct ContractSyncMetrics {
/// See `last_known_message_nonce` in CoreMetrics.
pub message_nonce: IntGaugeVec,

/// Contract sync liveness metric
pub liveness_metrics: IntGaugeVec,

/// Metrics for SequenceAware and RateLimited cursors.
pub cursor_metrics: Arc<CursorMetrics>,
}
Expand All @@ -49,13 +52,22 @@ impl ContractSyncMetrics {
)
.expect("failed to register stored_events metric");

let liveness_metrics = metrics
.new_int_gauge(
"contract_sync_liveness",
"Last timestamp observed by contract sync",
&["data_type", "chain"],
)
.expect("failed to register liveness metric");

let message_nonce = metrics.last_known_message_nonce();
let cursor_metrics = Arc::new(CursorMetrics::new(metrics));

ContractSyncMetrics {
indexed_height,
stored_events,
message_nonce,
liveness_metrics,
cursor_metrics,
}
}
Expand Down
15 changes: 15 additions & 0 deletions rust/main/hyperlane-base/src/contract_sync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
collections::HashSet, fmt::Debug, hash::Hash, marker::PhantomData, sync::Arc, time::Duration,
time::UNIX_EPOCH,
};

use axum::async_trait;
Expand Down Expand Up @@ -98,8 +99,13 @@ where
.metrics
.stored_events
.with_label_values(&[label, chain_name]);
let liveness_metric = self
.metrics
.liveness_metrics
.with_label_values(&[label, chain_name]);

loop {
Self::update_liveness_metric(&liveness_metric);
if let Some(rx) = opts.tx_id_receiver.as_mut() {
self.fetch_logs_from_receiver(rx, &stored_logs_metric).await;
}
Expand All @@ -120,6 +126,15 @@ where
info!(chain = chain_name, label, "contract sync loop exit");
}

fn update_liveness_metric(liveness_metric: &GenericGauge<AtomicI64>) {
liveness_metric.set(
UNIX_EPOCH
.elapsed()
.map(|d| d.as_secs() as i64)
.unwrap_or(0),
);
}

#[instrument(fields(domain=self.domain().name()), skip(self, recv, stored_logs_metric))]
async fn fetch_logs_from_receiver(
&self,
Expand Down
Loading