Skip to content

Commit a736a78

Browse files
committed
feat: add prometheus metrics for gRPC, adapter, and signer
1 parent 7819bfa commit a736a78

11 files changed

Lines changed: 444 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/ibc-attestor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ tower-http = { workspace = true, features = ["trace"] }
6262
tonic = { workspace = true, default-features = true }
6363
tonic-reflection = { workspace = true, default-features = true }
6464
prost = { workspace = true, default-features = true }
65+
prometheus = { workspace = true, default-features = true }
6566
warp = { workspace = true, features = ["server"] }
6667
futures = { workspace = true, default-features = true }
6768
async-trait = { workspace = true }

apps/ibc-attestor/src/adapter/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use thiserror::Error;
22

3+
use crate::metrics;
34
use crate::rpc::api::CommitmentType;
45

56
use cosmos::CosmosAdapter;
@@ -76,11 +77,15 @@ impl AdapterEnum {
7677
#[async_trait::async_trait]
7778
impl AttestationAdapter for AdapterEnum {
7879
async fn get_last_height_at_configured_finality(&self) -> Result<u64, AttestationAdapterError> {
79-
match self {
80+
let result = match self {
8081
Self::Evm(a) => a.get_last_height_at_configured_finality().await,
8182
Self::Solana(a) => a.get_last_height_at_configured_finality().await,
8283
Self::Cosmos(a) => a.get_last_height_at_configured_finality().await,
84+
};
85+
if let Ok(height) = &result {
86+
metrics::set_adapter_finalized_height(*height);
8387
}
88+
result
8489
}
8590

8691
async fn get_block_timestamp(&self, height: u64) -> Result<u64, AttestationAdapterError> {

apps/ibc-attestor/src/adapter/retry.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use tokio_retry::{RetryIf, strategy::ExponentialBackoff};
77
use tracing::{debug, error};
88

99
use super::AttestationAdapterError;
10+
use crate::metrics;
1011

1112
const MAX_ATTEMPTS: u8 = 3;
1213
const INITIAL_BACKOFF: u64 = 200;
@@ -44,10 +45,15 @@ where
4445
)
4546
.await;
4647

48+
let final_attempts = attempts.load(Ordering::Relaxed);
49+
4750
if let Err(error) = &result {
51+
if final_attempts >= MAX_ATTEMPTS {
52+
metrics::inc_retry_failure(operation);
53+
}
4854
error!(
4955
operation,
50-
attempts = attempts.load(Ordering::Relaxed),
56+
attempts = final_attempts,
5157
maxAttempts = MAX_ATTEMPTS,
5258
error = %error,
5359
"request failed"

apps/ibc-attestor/src/bin/ibc_attestor/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fn run_servers(
4141
) -> Result<ServerHandles, anyhow::Error> {
4242
let adapter_name = config.adapter.adapter_name();
4343
let signer_name = config.signer.signer_name();
44+
ibc_attestor::metrics::init(adapter_name, signer_name);
4445
let server_config = config.server;
4546

4647
let grpc_shutdown_rx = shutdown_tx.subscribe();

apps/ibc-attestor/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub mod attestation_payload;
1515
pub mod config;
1616
/// Logging and observability setup
1717
pub mod logging;
18+
/// Prometheus metrics registry and recording helpers
19+
pub mod metrics;
1820
/// gRPC server and service implementations
1921
pub mod rpc;
2022
/// Signer implementations for local and remote signing

0 commit comments

Comments
 (0)