Skip to content

Commit

Permalink
Updated address formatting into prometheus (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantinzolotarev authored Mar 13, 2024
1 parent 7789a4d commit ccfb981
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
39 changes: 18 additions & 21 deletions challenger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod metrics;

use contract::{OpPokeChallengedSuccessfullyFilter, OpPokedFilter, ScribeOptimisticProvider};

use crate::metrics::{ERRORS_COUNTER, LAST_SCANNED_BLOCK_GAUGE};
use crate::metrics::{CHALLENGE_COUNTER, ERRORS_COUNTER, LAST_SCANNED_BLOCK_GAUGE};

// Note: this is true virtually all of the time but because of leap seconds not always.
// We take minimal time just to be sure, it's always better to check outdated blocks
Expand Down Expand Up @@ -171,12 +171,11 @@ where
// Updating last scanned block metric
LAST_SCANNED_BLOCK_GAUGE
.with_label_values(&[
&self.address.to_string(),
&self
.contract_provider
.get_from()
.unwrap_or_default()
.to_string(),
&format!("{:?}", self.address),
&format!(
"{:?}",
self.contract_provider.get_from().unwrap_or_default()
),
])
.set(latest_block_number.as_u64() as i64);

Expand Down Expand Up @@ -242,15 +241,14 @@ where
self.address, receipt
);
// Add challenge to metrics
LAST_SCANNED_BLOCK_GAUGE
CHALLENGE_COUNTER
.with_label_values(&[
&self.address.to_string(),
&self
.contract_provider
.get_from()
.unwrap_or_default()
.to_string(),
&receipt.transaction_hash.to_string(),
&format!("{:?}", self.address),
&format!(
"{:?}",
self.contract_provider.get_from().unwrap_or_default()
),
&format!("{:?}", receipt.transaction_hash),
])
.inc();
} else {
Expand Down Expand Up @@ -319,12 +317,11 @@ where

ERRORS_COUNTER
.with_label_values(&[
&self.address.to_string(),
&self
.contract_provider
.get_from()
.unwrap_or_default()
.to_string(),
&format!("{:?}", self.address),
&format!(
"{:?}",
self.contract_provider.get_from().unwrap_or_default()
),
&err.to_string(),
])
.inc();
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ async fn main() -> Result<()> {
if res.is_err() {
ERRORS_COUNTER
.with_label_values(&[
&address.to_string(),
&signer_address.to_string(),
&format!("{:?}", address),
&format!("{:?}", signer_address),
&res.err().unwrap().to_string(),
])
.inc();
Expand Down

0 comments on commit ccfb981

Please sign in to comment.