Skip to content

Commit

Permalink
update all metric macros
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Dec 27, 2023
1 parent 113235a commit 0436a11
Show file tree
Hide file tree
Showing 30 changed files with 223 additions and 294 deletions.
36 changes: 15 additions & 21 deletions zebra-consensus/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ fn progress_from_tip(
if height >= checkpoint_list.max_height() {
(None, Progress::FinalCheckpoint)
} else {
metrics::gauge!("checkpoint.verified.height", height.0 as f64);
metrics::gauge!("checkpoint.processing.next.height", height.0 as f64);
metrics::gauge!("checkpoint.verified.height").set(height.0 as f64);
metrics::gauge!("checkpoint.processing.next.height").set(height.0 as f64);
(Some(hash), Progress::InitialTip(height))
}
}
Expand Down Expand Up @@ -303,7 +303,7 @@ where
.next_back()
.expect("queued has at least one entry");

metrics::gauge!("checkpoint.queued.max.height", max_queued_height.0 as f64);
metrics::gauge!("checkpoint.queued.max.height").set(max_queued_height.0 as f64);

let is_checkpoint = self.checkpoint_list.contains(height);
tracing::debug!(?height, ?hash, ?is_checkpoint, "queued block");
Expand All @@ -326,12 +326,12 @@ where
return;
};

metrics::gauge!("checkpoint.verified.height", verified_height.0 as f64);
metrics::gauge!("checkpoint.verified.height").set(verified_height.0 as f64);

let checkpoint_index = self.checkpoint_list.prev_checkpoint_index(verified_height);
let checkpoint_count = self.checkpoint_list.len();

metrics::gauge!("checkpoint.verified.count", checkpoint_index as f64);
metrics::gauge!("checkpoint.verified.count").set(checkpoint_index as f64);

tracing::debug!(
?verified_height,
Expand Down Expand Up @@ -409,7 +409,7 @@ where
// Check if we have the genesis block as a special case, to simplify the loop
BeforeGenesis if !self.queued.contains_key(&block::Height(0)) => {
tracing::trace!("Waiting for genesis block");
metrics::counter!("checkpoint.waiting.count", 1);
metrics::counter!("checkpoint.waiting.count").increment(1);
return WaitingForBlocks;
}
BeforeGenesis => block::Height(0),
Expand Down Expand Up @@ -444,10 +444,7 @@ where
break;
}
}
metrics::gauge!(
"checkpoint.queued.continuous.height",
pending_height.0 as f64,
);
metrics::gauge!("checkpoint.queued.continuous.height").set(pending_height.0 as f64);

// Now find the start of the checkpoint range
let start = self.current_start_bound().expect(
Expand All @@ -466,14 +463,11 @@ where
);

if let Some(block::Height(target_checkpoint)) = target_checkpoint {
metrics::gauge!(
"checkpoint.processing.next.height",
target_checkpoint as f64,
);
metrics::gauge!("checkpoint.processing.next.height").set(target_checkpoint as f64);
} else {
// Use the start height if there is no potential next checkpoint
metrics::gauge!("checkpoint.processing.next.height", start_height.0 as f64);
metrics::counter!("checkpoint.waiting.count", 1);
metrics::gauge!("checkpoint.processing.next.height").set(start_height.0 as f64);
metrics::counter!("checkpoint.waiting.count").increment(1);
}

target_checkpoint
Expand Down Expand Up @@ -541,12 +535,12 @@ where
/// Increase the current checkpoint height to `verified_height`,
fn update_progress(&mut self, verified_height: block::Height) {
if let Some(max_height) = self.queued.keys().next_back() {
metrics::gauge!("checkpoint.queued.max.height", max_height.0 as f64);
metrics::gauge!("checkpoint.queued.max.height").set(max_height.0 as f64);
} else {
// use f64::NAN as a sentinel value for "None", because 0 is a valid height
metrics::gauge!("checkpoint.queued.max.height", f64::NAN);
metrics::gauge!("checkpoint.queued.max.height").set(f64::NAN);
}
metrics::gauge!("checkpoint.queued_slots", self.queued.len() as f64);
metrics::gauge!("checkpoint.queued_slots").set(self.queued.len() as f64);

// Ignore blocks that are below the previous checkpoint, or otherwise
// have invalid heights.
Expand Down Expand Up @@ -869,7 +863,7 @@ where

let block_count = rev_valid_blocks.len();
tracing::info!(?block_count, ?current_range, "verified checkpoint range");
metrics::counter!("checkpoint.verified.block.count", block_count as u64);
metrics::counter!("checkpoint.verified.block.count").increment(block_count as u64);

// All the blocks we've kept are valid, so let's verify them
// in height order.
Expand Down Expand Up @@ -1058,7 +1052,7 @@ where

self.process_checkpoint_range();

metrics::gauge!("checkpoint.queued_slots", self.queued.len() as f64);
metrics::gauge!("checkpoint.queued_slots").set(self.queued.len() as f64);

// Because the checkpoint verifier duplicates state from the state
// service (it tracks which checkpoints have been verified), we must
Expand Down
4 changes: 2 additions & 2 deletions zebra-consensus/src/primitives/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ impl Service<BatchControl<Item>> for Verifier {

if result.is_ok() {
tracing::trace!(?result, "validated ed25519 signature");
metrics::counter!("signatures.ed25519.validated", 1);
metrics::counter!("signatures.ed25519.validated").increment(1);
} else {
tracing::trace!(?result, "invalid ed25519 signature");
metrics::counter!("signatures.ed25519.invalid", 1);
metrics::counter!("signatures.ed25519.invalid").increment(1);
}
result.map_err(BoxError::from)
}
Expand Down
4 changes: 2 additions & 2 deletions zebra-consensus/src/primitives/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,10 @@ impl Service<BatchControl<Item>> for Verifier {

if result.is_ok() {
tracing::trace!(?result, "verified groth16 proof");
metrics::counter!("proofs.groth16.verified", 1);
metrics::counter!("proofs.groth16.verified").increment(1);
} else {
tracing::trace!(?result, "invalid groth16 proof");
metrics::counter!("proofs.groth16.invalid", 1);
metrics::counter!("proofs.groth16.invalid").increment(1);
}

result.map_err(BoxError::from)
Expand Down
4 changes: 2 additions & 2 deletions zebra-consensus/src/primitives/halo2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ impl Service<BatchControl<Item>> for Verifier {

if result.is_ok() {
tracing::trace!(?result, "verified halo2 proof");
metrics::counter!("proofs.halo2.verified", 1);
metrics::counter!("proofs.halo2.verified").increment(1);
} else {
tracing::trace!(?result, "invalid halo2 proof");
metrics::counter!("proofs.halo2.invalid", 1);
metrics::counter!("proofs.halo2.invalid").increment(1);
}

result.map_err(BoxError::from)
Expand Down
4 changes: 2 additions & 2 deletions zebra-consensus/src/primitives/redjubjub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ impl Service<BatchControl<Item>> for Verifier {

if result.is_ok() {
tracing::trace!(?result, "validated redjubjub signature");
metrics::counter!("signatures.redjubjub.validated", 1);
metrics::counter!("signatures.redjubjub.validated").increment(1);
} else {
tracing::trace!(?result, "invalid redjubjub signature");
metrics::counter!("signatures.redjubjub.invalid", 1);
metrics::counter!("signatures.redjubjub.invalid").increment(1);
}

result.map_err(BoxError::from)
Expand Down
4 changes: 2 additions & 2 deletions zebra-consensus/src/primitives/redpallas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ impl Service<BatchControl<Item>> for Verifier {

if result.is_ok() {
tracing::trace!(?result, "validated redpallas signature");
metrics::counter!("signatures.redpallas.validated", 1);
metrics::counter!("signatures.redpallas.validated").increment(1);
} else {
tracing::trace!(?result, "invalid redpallas signature");
metrics::counter!("signatures.redpallas.invalid", 1);
metrics::counter!("signatures.redpallas.invalid").increment(1);
}

result.map_err(BoxError::from)
Expand Down
15 changes: 6 additions & 9 deletions zebra-network/src/address_book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,18 +696,15 @@ impl AddressBook {
let _ = self.address_metrics_tx.send(m);

// TODO: rename to address_book.[state_name]
metrics::gauge!("candidate_set.responded", m.responded as f64);
metrics::gauge!("candidate_set.gossiped", m.never_attempted_gossiped as f64);
metrics::gauge!("candidate_set.failed", m.failed as f64);
metrics::gauge!("candidate_set.pending", m.attempt_pending as f64);
metrics::gauge!("candidate_set.responded").set(m.responded as f64);
metrics::gauge!("candidate_set.gossiped").set(m.never_attempted_gossiped as f64);
metrics::gauge!("candidate_set.failed").set(m.failed as f64);
metrics::gauge!("candidate_set.pending").set(m.attempt_pending as f64);

// TODO: rename to address_book.responded.recently_live
metrics::gauge!("candidate_set.recently_live", m.recently_live as f64);
metrics::gauge!("candidate_set.recently_live").set(m.recently_live as f64);
// TODO: rename to address_book.responded.stopped_responding
metrics::gauge!(
"candidate_set.disconnected",
m.recently_stopped_responding as f64,
);
metrics::gauge!("candidate_set.disconnected").set(m.recently_stopped_responding as f64);

std::mem::drop(_guard);
self.log_metrics(&m, instant_now);
Expand Down
12 changes: 6 additions & 6 deletions zebra-network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ impl Config {
// (But we only make one initial connection attempt to each IP.)
metrics::counter!(
"zcash.net.peers.initial",
1,
"seed" => host.to_string(),
"remote_ip" => ip.to_string()
);
)
.increment(1);
}

Ok(ip_addrs.into_iter().collect())
Expand Down Expand Up @@ -440,10 +440,10 @@ impl Config {
// (But we only make one initial connection attempt to each IP.)
metrics::counter!(
"zcash.net.peers.initial",
1,
"cache" => peer_cache_file.display().to_string(),
"remote_ip" => ip.to_string()
);
)
.increment(1);
}

Ok(peer_list)
Expand Down Expand Up @@ -553,10 +553,10 @@ impl Config {
for ip in &peer_list {
metrics::counter!(
"zcash.net.peers.cache",
1,
"cache" => peer_cache_file.display().to_string(),
"remote_ip" => ip.to_string()
);
)
.increment(1);
}

Ok(())
Expand Down
40 changes: 20 additions & 20 deletions zebra-network/src/peer/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,10 @@ where
// Add a metric for inbound responses to outbound requests.
metrics::counter!(
"zebra.net.in.responses",
1,
"command" => response.command(),
"addr" => self.metrics_label.clone(),
);
)
.increment(1);
} else {
debug!(error = ?response, "error in peer response to Zebra request");
}
Expand Down Expand Up @@ -969,15 +969,15 @@ where
let InProgressClientRequest { request, tx, span } = req;

if tx.is_canceled() {
metrics::counter!("peer.canceled", 1);
metrics::counter!("peer.canceled").increment(1);
debug!(state = %self.state, %request, "ignoring canceled request");

metrics::counter!(
"zebra.net.out.requests.canceled",
1,
"command" => request.command(),
"addr" => self.metrics_label.clone(),
);
)
.increment(1);
self.update_state_metrics(format!("Out::Req::Canceled::{}", request.command()));

return;
Expand All @@ -988,10 +988,10 @@ where
// Add a metric for outbound requests.
metrics::counter!(
"zebra.net.out.requests",
1,
"command" => request.command(),
"addr" => self.metrics_label.clone(),
);
)
.increment(1);
self.update_state_metrics(format!("Out::Req::{}", request.command()));

let new_handler = match (&self.state, request) {
Expand Down Expand Up @@ -1360,10 +1360,10 @@ where
// Add a metric for inbound requests
metrics::counter!(
"zebra.net.in.requests",
1,
"command" => req.command(),
"addr" => self.metrics_label.clone(),
);
)
.increment(1);
self.update_state_metrics(format!("In::Req::{}", req.command()));

// Give the inbound service time to clear its queue,
Expand Down Expand Up @@ -1431,10 +1431,10 @@ where
// Add a metric for outbound responses to inbound requests
metrics::counter!(
"zebra.net.out.responses",
1,
"command" => rsp.command(),
"addr" => self.metrics_label.clone(),
);
)
.increment(1);
self.update_state_metrics(format!("In::Rsp::{}", rsp.command()));

// TODO: split response handler into its own method
Expand Down Expand Up @@ -1570,9 +1570,9 @@ where

if thread_rng().gen::<f32>() < drop_connection_probability {
if matches!(error, PeerError::Overloaded) {
metrics::counter!("pool.closed.loadshed", 1);
metrics::counter!("pool.closed.loadshed").increment(1);
} else {
metrics::counter!("pool.closed.inbound.timeout", 1);
metrics::counter!("pool.closed.inbound.timeout").increment(1);
}

tracing::info!(
Expand All @@ -1594,9 +1594,9 @@ where
self.update_state_metrics(format!("In::Req::{}/Rsp::{error}::Ignored", req.command()));

if matches!(error, PeerError::Overloaded) {
metrics::counter!("pool.ignored.loadshed", 1);
metrics::counter!("pool.ignored.loadshed").increment(1);
} else {
metrics::counter!("pool.ignored.inbound.timeout", 1);
metrics::counter!("pool.ignored.inbound.timeout").increment(1);
}
}
}
Expand Down Expand Up @@ -1659,12 +1659,12 @@ where
self.erase_state_metrics();

// Set the new state
metrics::increment_gauge!(
metrics::gauge!(
"zebra.net.connection.state",
1.0,
"command" => current_metrics_state.clone(),
"addr" => self.metrics_label.clone(),
);
)
.set(1.0);

self.last_metrics_state = Some(current_metrics_state);
}
Expand All @@ -1674,10 +1674,10 @@ where
if let Some(last_metrics_state) = self.last_metrics_state.take() {
metrics::gauge!(
"zebra.net.connection.state",
0.0,
"command" => last_metrics_state,
"addr" => self.metrics_label.clone(),
);
)
.set(0.0);
}
}

Expand Down
Loading

0 comments on commit 0436a11

Please sign in to comment.