diff --git a/zebra-consensus/src/checkpoint.rs b/zebra-consensus/src/checkpoint.rs index bcd49187764..6541c502f9a 100644 --- a/zebra-consensus/src/checkpoint.rs +++ b/zebra-consensus/src/checkpoint.rs @@ -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)) } } @@ -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"); @@ -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, @@ -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), @@ -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( @@ -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 @@ -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. @@ -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. @@ -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 diff --git a/zebra-consensus/src/primitives/ed25519.rs b/zebra-consensus/src/primitives/ed25519.rs index 7a17ac9e14a..d51113276dd 100644 --- a/zebra-consensus/src/primitives/ed25519.rs +++ b/zebra-consensus/src/primitives/ed25519.rs @@ -164,10 +164,10 @@ impl Service> 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) } diff --git a/zebra-consensus/src/primitives/groth16.rs b/zebra-consensus/src/primitives/groth16.rs index e6d7ad17a35..e2ec64144fb 100644 --- a/zebra-consensus/src/primitives/groth16.rs +++ b/zebra-consensus/src/primitives/groth16.rs @@ -485,10 +485,10 @@ impl Service> 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) diff --git a/zebra-consensus/src/primitives/halo2.rs b/zebra-consensus/src/primitives/halo2.rs index e9cbc4262e6..ffc58a5feb8 100644 --- a/zebra-consensus/src/primitives/halo2.rs +++ b/zebra-consensus/src/primitives/halo2.rs @@ -348,10 +348,10 @@ impl Service> 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) diff --git a/zebra-consensus/src/primitives/redjubjub.rs b/zebra-consensus/src/primitives/redjubjub.rs index 94be0cdb5f8..31641a9f722 100644 --- a/zebra-consensus/src/primitives/redjubjub.rs +++ b/zebra-consensus/src/primitives/redjubjub.rs @@ -165,10 +165,10 @@ impl Service> 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) diff --git a/zebra-consensus/src/primitives/redpallas.rs b/zebra-consensus/src/primitives/redpallas.rs index 5064fa817fb..d848682aaa4 100644 --- a/zebra-consensus/src/primitives/redpallas.rs +++ b/zebra-consensus/src/primitives/redpallas.rs @@ -164,10 +164,10 @@ impl Service> 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) diff --git a/zebra-network/src/address_book.rs b/zebra-network/src/address_book.rs index c9d4d1ee57d..2f2142b6e0e 100644 --- a/zebra-network/src/address_book.rs +++ b/zebra-network/src/address_book.rs @@ -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); diff --git a/zebra-network/src/config.rs b/zebra-network/src/config.rs index 1f7cc2d804d..2c7a9b416ff 100644 --- a/zebra-network/src/config.rs +++ b/zebra-network/src/config.rs @@ -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()) @@ -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) @@ -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(()) diff --git a/zebra-network/src/peer/connection.rs b/zebra-network/src/peer/connection.rs index b8eddcb235e..6662fd79eb7 100644 --- a/zebra-network/src/peer/connection.rs +++ b/zebra-network/src/peer/connection.rs @@ -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"); } @@ -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; @@ -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) { @@ -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, @@ -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 @@ -1570,9 +1570,9 @@ where if thread_rng().gen::() < 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!( @@ -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); } } } @@ -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); } @@ -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); } } diff --git a/zebra-network/src/peer/handshake.rs b/zebra-network/src/peer/handshake.rs index 898b0a14b16..161c25f0ac5 100644 --- a/zebra-network/src/peer/handshake.rs +++ b/zebra-network/src/peer/handshake.rs @@ -743,19 +743,19 @@ where // the value is the number of rejected handshakes, by peer IP and protocol version metrics::counter!( "zcash.net.peers.obsolete", - 1, "remote_ip" => their_addr.to_string(), "remote_version" => remote.version.to_string(), "min_version" => min_version.to_string(), "user_agent" => remote.user_agent.clone(), - ); + ) + .increment(1); // the value is the remote version of the most recent rejected handshake from each peer metrics::gauge!( "zcash.net.peers.version.obsolete", - remote.version.0 as f64, "remote_ip" => their_addr.to_string(), - ); + ) + .set(remote.version.0 as f64); // Disconnect if peer is using an obsolete version. return Err(HandshakeError::ObsoleteVersion(remote.version)); @@ -782,20 +782,20 @@ where // the value is the number of connected handshakes, by peer IP and protocol version metrics::counter!( "zcash.net.peers.connected", - 1, "remote_ip" => their_addr.to_string(), "remote_version" => connection_info.remote.version.to_string(), "negotiated_version" => negotiated_version.to_string(), "min_version" => min_version.to_string(), "user_agent" => connection_info.remote.user_agent.clone(), - ); + ) + .increment(1); // the value is the remote version of the most recent connected handshake from each peer metrics::gauge!( "zcash.net.peers.version.connected", - connection_info.remote.version.0 as f64, "remote_ip" => their_addr.to_string(), - ); + ) + .set(connection_info.remote.version.0 as f64); peer_conn.send(Message::Verack).await?; @@ -954,10 +954,10 @@ where // Add a metric for outbound messages. metrics::counter!( "zcash.net.out.messages", - 1, "command" => msg.command(), "addr" => connected_addr.get_transient_addr_label(), - ); + ) + .increment(1); // We need to use future::ready rather than an async block here, // because we need the sink to be Unpin, and the With // returned by .with is Unpin only if Fut is Unpin, and the @@ -991,10 +991,10 @@ where Ok(msg) => { metrics::counter!( "zcash.net.in.messages", - 1, "command" => msg.command(), "addr" => connected_addr.get_transient_addr_label(), - ); + ) + .increment(1); // # Security // @@ -1004,10 +1004,10 @@ where Err(err) => { metrics::counter!( "zebra.net.in.errors", - 1, "error" => err.to_string(), "addr" => connected_addr.get_transient_addr_label(), - ); + ) + .increment(1); // # Security // diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index fc07a38374d..e9ba3d38085 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -813,8 +813,7 @@ where // To avoid hangs and starvation, the crawler must spawn a separate task for each crawl // and handshake, so they can make progress independently (and avoid deadlocking each other). loop { - metrics::gauge!( - "crawler.in_flight_handshakes", + metrics::gauge!("crawler.in_flight_handshakes").set( handshakes .len() .checked_sub(1) diff --git a/zebra-network/src/peer_set/inventory_registry.rs b/zebra-network/src/peer_set/inventory_registry.rs index b43915822e9..0b4e01cea14 100644 --- a/zebra-network/src/peer_set/inventory_registry.rs +++ b/zebra-network/src/peer_set/inventory_registry.rs @@ -342,8 +342,8 @@ impl InventoryRegistry { Poll::Ready(Some(Err(BroadcastStreamRecvError::Lagged(count)))) => { // This isn't a fatal inventory error, it's expected behaviour when Zebra is // under load from peers. - metrics::counter!("pool.inventory.dropped", 1); - metrics::counter!("pool.inventory.dropped.messages", count); + metrics::counter!("pool.inventory.dropped").increment(1); + metrics::counter!("pool.inventory.dropped.messages").increment(count); // If this message happens a lot, we should improve inventory registry // performance, or poll the registry or peer set in a separate task. diff --git a/zebra-network/src/peer_set/set.rs b/zebra-network/src/peer_set/set.rs index fdec72fded8..722e09b6ec1 100644 --- a/zebra-network/src/peer_set/set.rs +++ b/zebra-network/src/peer_set/set.rs @@ -1080,9 +1080,9 @@ where let num_ready = self.ready_services.len(); let num_unready = self.unready_services.len(); let num_peers = num_ready + num_unready; - metrics::gauge!("pool.num_ready", num_ready as f64); - metrics::gauge!("pool.num_unready", num_unready as f64); - metrics::gauge!("zcash.net.peers", num_peers as f64); + metrics::gauge!("pool.num_ready").set(num_ready as f64); + metrics::gauge!("pool.num_unready").set(num_unready as f64); + metrics::gauge!("zcash.net.peers").set(num_peers as f64); // Security: make sure we haven't exceeded the connection limit if num_peers > self.peerset_total_connection_limit { diff --git a/zebra-network/src/protocol/external/codec.rs b/zebra-network/src/protocol/external/codec.rs index 6a4ae0585eb..88f54c6b242 100644 --- a/zebra-network/src/protocol/external/codec.rs +++ b/zebra-network/src/protocol/external/codec.rs @@ -126,8 +126,8 @@ impl Encoder for Codec { if let Some(addr_label) = self.builder.metrics_addr_label.clone() { metrics::counter!("zcash.net.out.bytes.total", - (body_length + HEADER_LEN) as u64, - "addr" => addr_label); + "addr" => addr_label) + .increment((body_length + HEADER_LEN) as u64); } use Message::*; @@ -397,7 +397,8 @@ impl Decoder for Codec { } if let Some(label) = self.builder.metrics_addr_label.clone() { - metrics::counter!("zcash.net.in.bytes.total", (body_len + HEADER_LEN) as u64, "addr" => label); + metrics::counter!("zcash.net.in.bytes.total", "addr" => label) + .increment((body_len + HEADER_LEN) as u64); } // Reserve buffer space for the expected body and the following header. diff --git a/zebra-state/src/request.rs b/zebra-state/src/request.rs index 0db06735ca7..2a6b3b1a5b8 100644 --- a/zebra-state/src/request.rs +++ b/zebra-state/src/request.rs @@ -742,10 +742,10 @@ impl Request { pub fn count_metric(&self) { metrics::counter!( "state.requests", - 1, "service" => "state", "type" => self.variant_name() - ); + ) + .increment(1); } } @@ -1031,10 +1031,10 @@ impl ReadRequest { pub fn count_metric(&self) { metrics::counter!( "state.requests", - 1, "service" => "read_state", "type" => self.variant_name() - ); + ) + .increment(1); } } diff --git a/zebra-state/src/service.rs b/zebra-state/src/service.rs index 69b800bf1f5..64c1936475f 100644 --- a/zebra-state/src/service.rs +++ b/zebra-state/src/service.rs @@ -520,14 +520,9 @@ impl StateService { self.max_finalized_queue_height = queued_height.0 as f64; } - metrics::gauge!( - "state.checkpoint.queued.max.height", - self.max_finalized_queue_height, - ); - metrics::gauge!( - "state.checkpoint.queued.block.count", - self.finalized_state_queued_blocks.len() as f64, - ); + metrics::gauge!("state.checkpoint.queued.max.height").set(self.max_finalized_queue_height); + metrics::gauge!("state.checkpoint.queued.block.count") + .set(self.finalized_state_queued_blocks.len() as f64); rsp_rx } @@ -583,10 +578,8 @@ impl StateService { "block commit task exited. Is Zebra shutting down?", ); } else { - metrics::gauge!( - "state.checkpoint.sent.block.height", - last_sent_finalized_block_height.0 as f64, - ); + metrics::gauge!("state.checkpoint.sent.block.height") + .set(last_sent_finalized_block_height.0 as f64); }; } } diff --git a/zebra-state/src/service/finalized_state.rs b/zebra-state/src/service/finalized_state.rs index 0fc76b8a364..17fdf3b40d5 100644 --- a/zebra-state/src/service/finalized_state.rs +++ b/zebra-state/src/service/finalized_state.rs @@ -255,26 +255,20 @@ impl FinalizedState { ); if result.is_ok() { - metrics::counter!("state.checkpoint.finalized.block.count", 1); - metrics::gauge!( - "state.checkpoint.finalized.block.height", - checkpoint_verified.height.0 as f64, - ); + metrics::counter!("state.checkpoint.finalized.block.count").increment(1); + metrics::gauge!("state.checkpoint.finalized.block.height") + .set(checkpoint_verified.height.0 as f64); // This height gauge is updated for both fully verified and checkpoint blocks. // These updates can't conflict, because the state makes sure that blocks // are committed in order. - metrics::gauge!( - "zcash.chain.verified.block.height", - checkpoint_verified.height.0 as f64, - ); - metrics::counter!("zcash.chain.verified.block.total", 1); + metrics::gauge!("zcash.chain.verified.block.height") + .set(checkpoint_verified.height.0 as f64); + metrics::counter!("zcash.chain.verified.block.total").increment(1); } else { - metrics::counter!("state.checkpoint.error.block.count", 1); - metrics::gauge!( - "state.checkpoint.error.block.height", - checkpoint_verified.height.0 as f64, - ); + metrics::counter!("state.checkpoint.error.block.count").increment(1); + metrics::gauge!("state.checkpoint.error.block.height") + .set(checkpoint_verified.height.0 as f64); }; // Make the error cloneable, so we can send it to the block verify future, diff --git a/zebra-state/src/service/finalized_state/zebra_db/metrics.rs b/zebra-state/src/service/finalized_state/zebra_db/metrics.rs index 75b342e2cdc..9a5b5aef50f 100644 --- a/zebra-state/src/service/finalized_state/zebra_db/metrics.rs +++ b/zebra-state/src/service/finalized_state/zebra_db/metrics.rs @@ -38,36 +38,24 @@ pub(crate) fn block_precommit_metrics(block: &Block, hash: block::Hash, height: if height.is_min() { "genesis " } else { "" } ); - metrics::counter!("state.finalized.block.count", 1); - metrics::gauge!("state.finalized.block.height", height.0 as f64); + metrics::counter!("state.finalized.block.count").increment(1); + metrics::gauge!("state.finalized.block.height").set(height.0 as f64); - metrics::counter!( - "state.finalized.cumulative.transactions", - transaction_count as u64 - ); + metrics::counter!("state.finalized.cumulative.transactions") + .increment(transaction_count as u64); - metrics::counter!( - "state.finalized.cumulative.sprout_nullifiers", - sprout_nullifier_count as u64 - ); - metrics::counter!( - "state.finalized.cumulative.sapling_nullifiers", - sapling_nullifier_count as u64 - ); - metrics::counter!( - "state.finalized.cumulative.orchard_nullifiers", - orchard_nullifier_count as u64 - ); + metrics::counter!("state.finalized.cumulative.sprout_nullifiers") + .increment(sprout_nullifier_count as u64); + metrics::counter!("state.finalized.cumulative.sapling_nullifiers") + .increment(sapling_nullifier_count as u64); + metrics::counter!("state.finalized.cumulative.orchard_nullifiers") + .increment(orchard_nullifier_count as u64); // The outputs from the genesis block can't be spent, so we skip them here. if !height.is_min() { - metrics::counter!( - "state.finalized.cumulative.transparent_prevouts", - transparent_prevout_count as u64 - ); - metrics::counter!( - "state.finalized.cumulative.transparent_newouts", - transparent_newout_count as u64 - ); + metrics::counter!("state.finalized.cumulative.transparent_prevouts") + .increment(transparent_prevout_count as u64); + metrics::counter!("state.finalized.cumulative.transparent_newouts") + .increment(transparent_newout_count as u64); } } diff --git a/zebra-state/src/service/non_finalized_state.rs b/zebra-state/src/service/non_finalized_state.rs index c01c16767d9..9460ac27afa 100644 --- a/zebra-state/src/service/non_finalized_state.rs +++ b/zebra-state/src/service/non_finalized_state.rs @@ -418,12 +418,10 @@ impl NonFinalizedState { chain_push_result.expect("scope has finished") } - /// Returns the length of the non-finalized portion of the current best chain. - pub fn best_chain_len(&self) -> u32 { - self.best_chain() - .expect("only called after inserting a block") - .blocks - .len() as u32 + /// Returns the length of the non-finalized portion of the current best chain + /// or `None` if the best chain has no blocks. + pub fn best_chain_len(&self) -> Option { + self.best_chain().map(|chain| chain.blocks.len() as u32) } /// Returns `true` if `hash` is contained in the non-finalized portion of any @@ -619,8 +617,8 @@ impl NonFinalizedState { return; } - metrics::counter!("state.memory.committed.block.count", 1); - metrics::gauge!("state.memory.committed.block.height", height.0 as f64); + metrics::counter!("state.memory.committed.block.count").increment(1); + metrics::gauge!("state.memory.committed.block.height").set(height.0 as f64); if self .best_chain() @@ -628,8 +626,8 @@ impl NonFinalizedState { .non_finalized_tip_hash() == hash { - metrics::counter!("state.memory.best.committed.block.count", 1); - metrics::gauge!("state.memory.best.committed.block.height", height.0 as f64); + metrics::counter!("state.memory.best.committed.block.count").increment(1); + metrics::gauge!("state.memory.best.committed.block.height").set(height.0 as f64); } self.update_metrics_for_chains(); @@ -641,11 +639,9 @@ impl NonFinalizedState { return; } - metrics::gauge!("state.memory.chain.count", self.chain_set.len() as f64); - metrics::gauge!( - "state.memory.best.chain.length", - self.best_chain_len() as f64, - ); + metrics::gauge!("state.memory.chain.count").set(self.chain_set.len() as f64); + metrics::gauge!("state.memory.best.chain.length",) + .set(self.best_chain_len().unwrap_or_default() as f64); } /// Update the progress bars after any chain is modified. diff --git a/zebra-state/src/service/non_finalized_state/tests/vectors.rs b/zebra-state/src/service/non_finalized_state/tests/vectors.rs index 78c5de9d84a..eae0235ea01 100644 --- a/zebra-state/src/service/non_finalized_state/tests/vectors.rs +++ b/zebra-state/src/service/non_finalized_state/tests/vectors.rs @@ -327,7 +327,7 @@ fn shorter_chain_can_be_best_chain_for_network(network: Network) -> Result<()> { state.commit_block(short_chain_block.prepare(), &finalized_state)?; assert_eq!(2, state.chain_set.len()); - assert_eq!(2, state.best_chain_len()); + assert_eq!(Some(2), state.best_chain_len()); Ok(()) } @@ -381,7 +381,7 @@ fn longer_chain_with_more_work_wins_for_network(network: Network) -> Result<()> state.commit_block(short_chain_block.prepare(), &finalized_state)?; assert_eq!(2, state.chain_set.len()); - assert_eq!(5, state.best_chain_len()); + assert_eq!(Some(5), state.best_chain_len()); Ok(()) } diff --git a/zebra-state/src/service/queued_blocks.rs b/zebra-state/src/service/queued_blocks.rs index e383984987b..52424d2aa8a 100644 --- a/zebra-state/src/service/queued_blocks.rs +++ b/zebra-state/src/service/queued_blocks.rs @@ -186,19 +186,19 @@ impl QueuedBlocks { /// Update metrics after the queue is modified fn update_metrics(&self) { if let Some(min_height) = self.by_height.keys().next() { - metrics::gauge!("state.memory.queued.min.height", min_height.0 as f64); + metrics::gauge!("state.memory.queued.min.height").set(min_height.0 as f64); } else { // use f64::NAN as a sentinel value for "None", because 0 is a valid height - metrics::gauge!("state.memory.queued.min.height", f64::NAN); + metrics::gauge!("state.memory.queued.min.height").set(f64::NAN); } if let Some(max_height) = self.by_height.keys().next_back() { - metrics::gauge!("state.memory.queued.max.height", max_height.0 as f64); + metrics::gauge!("state.memory.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!("state.memory.queued.max.height", f64::NAN); + metrics::gauge!("state.memory.queued.max.height").set(f64::NAN); } - metrics::gauge!("state.memory.queued.block.count", self.blocks.len() as f64); + metrics::gauge!("state.memory.queued.block.count").set(self.blocks.len() as f64); } /// Try to look up this UTXO in any queued block. @@ -357,8 +357,8 @@ impl SentHashes { /// Update sent block metrics after a block is sent. fn update_metrics_for_block(&self, height: block::Height) { - metrics::counter!("state.memory.sent.block.count", 1); - metrics::gauge!("state.memory.sent.block.height", height.0 as f64); + metrics::counter!("state.memory.sent.block.count").increment(1); + metrics::gauge!("state.memory.sent.block.height").set(height.0 as f64); self.update_metrics_for_cache(); } @@ -371,30 +371,25 @@ impl SentHashes { .flat_map(|batch| batch.front().map(|(_hash, height)| height)) .min() { - metrics::gauge!("state.memory.sent.cache.min.height", min_height.0 as f64); + metrics::gauge!("state.memory.sent.cache.min.height").set(min_height.0 as f64); } else { // use f64::NAN as a sentinel value for "None", because 0 is a valid height - metrics::gauge!("state.memory.sent.cache.min.height", f64::NAN); + metrics::gauge!("state.memory.sent.cache.min.height").set(f64::NAN); } if let Some(max_height) = batch_iter() .flat_map(|batch| batch.back().map(|(_hash, height)| height)) .max() { - metrics::gauge!("state.memory.sent.cache.max.height", max_height.0 as f64); + metrics::gauge!("state.memory.sent.cache.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!("state.memory.sent.cache.max.height", f64::NAN); + metrics::gauge!("state.memory.sent.cache.max.height").set(f64::NAN); } - metrics::gauge!( - "state.memory.sent.cache.block.count", - batch_iter().flatten().count() as f64, - ); + metrics::gauge!("state.memory.sent.cache.block.count") + .set(batch_iter().flatten().count() as f64); - metrics::gauge!( - "state.memory.sent.cache.batch.count", - batch_iter().count() as f64, - ); + metrics::gauge!("state.memory.sent.cache.batch.count").set(batch_iter().count() as f64); } } diff --git a/zebra-state/src/service/write.rs b/zebra-state/src/service/write.rs index cb36b6a2ba5..4858b5d79cd 100644 --- a/zebra-state/src/service/write.rs +++ b/zebra-state/src/service/write.rs @@ -290,7 +290,11 @@ pub fn write_blocks_from_channels( // Update the caller with the result. let _ = rsp_tx.send(result.clone().map(|()| child_hash).map_err(BoxError::from)); - while non_finalized_state.best_chain_len() > MAX_BLOCK_REORG_HEIGHT { + while non_finalized_state + .best_chain_len() + .expect("only called after inserting a block") + > MAX_BLOCK_REORG_HEIGHT + { tracing::trace!("finalizing block past the reorg limit"); let contextually_verified_with_trees = non_finalized_state.finalize(); prev_finalized_note_commitment_trees = finalized_state @@ -303,21 +307,16 @@ pub fn write_blocks_from_channels( // Update the metrics if semantic and contextual validation passes // // TODO: split this out into a function? - metrics::counter!("state.full_verifier.committed.block.count", 1); - metrics::counter!("zcash.chain.verified.block.total", 1); + metrics::counter!("state.full_verifier.committed.block.count").increment(1); + metrics::counter!("zcash.chain.verified.block.total").increment(1); - metrics::gauge!( - "state.full_verifier.committed.block.height", - tip_block_height.0 as f64, - ); + metrics::gauge!("state.full_verifier.committed.block.height") + .set(tip_block_height.0 as f64); // This height gauge is updated for both fully verified and checkpoint blocks. // These updates can't conflict, because this block write task makes sure that blocks // are committed in order. - metrics::gauge!( - "zcash.chain.verified.block.height", - tip_block_height.0 as f64, - ); + metrics::gauge!("zcash.chain.verified.block.height").set(tip_block_height.0 as f64); tracing::trace!("finished processing queued block"); } diff --git a/zebrad/src/components/inbound/downloads.rs b/zebrad/src/components/inbound/downloads.rs index 11200e66435..a1a36ed26d5 100644 --- a/zebrad/src/components/inbound/downloads.rs +++ b/zebrad/src/components/inbound/downloads.rs @@ -213,8 +213,8 @@ where "block hash already queued for inbound download: ignored block", ); - metrics::gauge!("gossip.queued.block.count", self.pending.len() as f64); - metrics::counter!("gossip.already.queued.dropped.block.hash.count", 1); + metrics::gauge!("gossip.queued.block.count").set(self.pending.len() as f64); + metrics::counter!("gossip.already.queued.dropped.block.hash.count").increment(1); return DownloadAction::AlreadyQueued; } @@ -227,8 +227,8 @@ where "too many blocks queued for inbound download: ignored block", ); - metrics::gauge!("gossip.queued.block.count", self.pending.len() as f64); - metrics::counter!("gossip.full.queue.dropped.block.hash.count", 1); + metrics::gauge!("gossip.queued.block.count").set(self.pending.len() as f64); + metrics::counter!("gossip.full.queue.dropped.block.hash.count").increment(1); return DownloadAction::FullQueue; } @@ -271,7 +271,7 @@ where } else { unreachable!("wrong response to block request"); }; - metrics::counter!("gossip.downloaded.block.count", 1); + metrics::counter!("gossip.downloaded.block.count").increment(1); // # Security & Performance // @@ -312,7 +312,7 @@ where ?hash, "gossiped block with no height: dropped downloaded block" ); - metrics::counter!("gossip.no.height.dropped.block.count", 1); + metrics::counter!("gossip.no.height.dropped.block.count").increment(1); BoxError::from("gossiped block with no height") })?; @@ -326,7 +326,7 @@ where lookahead_limit = full_verify_concurrency_limit, "gossiped block height too far ahead of the tip: dropped downloaded block", ); - metrics::counter!("gossip.max.height.limit.dropped.block.count", 1); + metrics::counter!("gossip.max.height.limit.dropped.block.count").increment(1); Err("gossiped block height too far ahead")?; } else if block_height < min_accepted_height { @@ -338,7 +338,7 @@ where behind_tip_limit = ?zs::MAX_BLOCK_REORG_HEIGHT, "gossiped block height behind the finalized tip: dropped downloaded block", ); - metrics::counter!("gossip.min.height.limit.dropped.block.count", 1); + metrics::counter!("gossip.min.height.limit.dropped.block.count").increment(1); Err("gossiped block height behind the finalized tip")?; } @@ -350,7 +350,7 @@ where } .map_ok(|(hash, height)| { info!(?height, "downloaded and verified gossiped block"); - metrics::counter!("gossip.verified.block.count", 1); + metrics::counter!("gossip.verified.block.count").increment(1); hash }) // Tack the hash onto the error so we can remove the cancel handle @@ -364,7 +364,7 @@ where biased; _ = &mut cancel_rx => { trace!("task cancelled prior to completion"); - metrics::counter!("gossip.cancelled.count", 1); + metrics::counter!("gossip.cancelled.count").increment(1); Err(("canceled".into(), hash)) } verification = fut => verification, @@ -383,7 +383,7 @@ where concurrency_limit = self.full_verify_concurrency_limit, "queued hash for download", ); - metrics::gauge!("gossip.queued.block.count", self.pending.len() as f64); + metrics::gauge!("gossip.queued.block.count").set(self.pending.len() as f64); DownloadAction::AddedToQueue } diff --git a/zebrad/src/components/mempool.rs b/zebrad/src/components/mempool.rs index 0e9aa2d382d..2d9b2b3e0c5 100644 --- a/zebrad/src/components/mempool.rs +++ b/zebrad/src/components/mempool.rs @@ -615,7 +615,7 @@ impl Service for Mempool { Ok(Err((txid, error))) => { tracing::debug!(?txid, ?error, "mempool transaction failed to verify"); - metrics::counter!("mempool.failed.verify.tasks.total", 1, "reason" => error.to_string()); + metrics::counter!("mempool.failed.verify.tasks.total", "reason" => error.to_string()).increment(1); storage.reject_if_needed(txid, error); } Err(_elapsed) => { @@ -624,7 +624,7 @@ impl Service for Mempool { tracing::info!("mempool transaction failed to verify due to timeout"); - metrics::counter!("mempool.failed.verify.tasks.total", 1, "reason" => "timeout"); + metrics::counter!("mempool.failed.verify.tasks.total", "reason" => "timeout").increment(1); } }; } diff --git a/zebrad/src/components/mempool/downloads.rs b/zebrad/src/components/mempool/downloads.rs index 33e5d975d90..d3f62b4087b 100644 --- a/zebrad/src/components/mempool/downloads.rs +++ b/zebrad/src/components/mempool/downloads.rs @@ -253,10 +253,8 @@ where ?MAX_INBOUND_CONCURRENCY, "transaction id already queued for inbound download: ignored transaction" ); - metrics::gauge!( - "mempool.currently.queued.transactions", - self.pending.len() as f64, - ); + metrics::gauge!("mempool.currently.queued.transactions",) + .set(self.pending.len() as f64); return Err(MempoolError::AlreadyQueued); } @@ -268,10 +266,8 @@ where ?MAX_INBOUND_CONCURRENCY, "too many transactions queued for inbound download: ignored transaction" ); - metrics::gauge!( - "mempool.currently.queued.transactions", - self.pending.len() as f64, - ); + metrics::gauge!("mempool.currently.queued.transactions",) + .set(self.pending.len() as f64); return Err(MempoolError::FullQueue); } @@ -327,17 +323,15 @@ where metrics::counter!( "mempool.downloaded.transactions.total", - 1, "version" => format!("{}",tx.transaction.version()), - ); + ).increment(1); tx } Gossip::Tx(tx) => { metrics::counter!( "mempool.pushed.transactions.total", - 1, "version" => format!("{}",tx.transaction.version()), - ); + ).increment(1); tx } }; @@ -363,9 +357,8 @@ where .map_ok(|(tx, tip_height)| { metrics::counter!( "mempool.verified.transactions.total", - 1, "version" => format!("{}", tx.transaction.transaction.version()), - ); + ).increment(1); (tx, tip_height) }) // Tack the hash onto the error so we can remove the cancel handle @@ -384,7 +377,7 @@ where biased; _ = &mut cancel_rx => { trace!("task cancelled prior to completion"); - metrics::counter!("mempool.cancelled.verify.tasks.total", 1); + metrics::counter!("mempool.cancelled.verify.tasks.total").increment(1); Err((TransactionDownloadVerifyError::Cancelled, txid)) } verification = fut => verification, @@ -405,11 +398,8 @@ where ?MAX_INBOUND_CONCURRENCY, "queued transaction hash for download" ); - metrics::gauge!( - "mempool.currently.queued.transactions", - self.pending.len() as f64, - ); - metrics::counter!("mempool.queued.transactions.total", 1); + metrics::gauge!("mempool.currently.queued.transactions",).set(self.pending.len() as f64); + metrics::counter!("mempool.queued.transactions.total").increment(1); Ok(()) } @@ -446,10 +436,7 @@ where } assert!(self.pending.is_empty()); assert!(self.cancel_handles.is_empty()); - metrics::gauge!( - "mempool.currently.queued.transactions", - self.pending.len() as f64, - ); + metrics::gauge!("mempool.currently.queued.transactions",).set(self.pending.len() as f64); } /// Get the number of currently in-flight download tasks. @@ -498,6 +485,6 @@ where fn drop(mut self: Pin<&mut Self>) { self.cancel_all(); - metrics::gauge!("mempool.currently.queued.transactions", 0 as f64); + metrics::gauge!("mempool.currently.queued.transactions").set(0 as f64); } } diff --git a/zebrad/src/components/mempool/gossip.rs b/zebrad/src/components/mempool/gossip.rs index 6d3b2b638bf..4fee90d85a9 100644 --- a/zebrad/src/components/mempool/gossip.rs +++ b/zebrad/src/components/mempool/gossip.rs @@ -93,7 +93,7 @@ where // broadcast requests don't return errors, and we'd just want to ignore them anyway let _ = broadcast_network.ready().await?.call(request).await; - metrics::counter!("mempool.gossiped.transactions.total", txs_len as u64); + metrics::counter!("mempool.gossiped.transactions.total").increment(txs_len as u64); // wait for at least the network timeout between gossips // diff --git a/zebrad/src/components/mempool/storage.rs b/zebrad/src/components/mempool/storage.rs index bed0f9aabd2..90b114fffe1 100644 --- a/zebrad/src/components/mempool/storage.rs +++ b/zebrad/src/components/mempool/storage.rs @@ -651,16 +651,12 @@ impl Storage { /// /// Must be called every time the rejected lists change. fn update_rejected_metrics(&mut self) { - metrics::gauge!( - "mempool.rejected.transaction.ids", - self.rejected_transaction_count() as f64, - ); + metrics::gauge!("mempool.rejected.transaction.ids",) + .set(self.rejected_transaction_count() as f64); // This is just an approximation. // TODO: make it more accurate #2869 let item_size = size_of::<(transaction::Hash, SameEffectsTipRejectionError)>(); - metrics::gauge!( - "mempool.rejected.transaction.ids.bytes", - (self.rejected_transaction_count() * item_size) as f64, - ); + metrics::gauge!("mempool.rejected.transaction.ids.bytes",) + .set((self.rejected_transaction_count() * item_size) as f64); } } diff --git a/zebrad/src/components/mempool/storage/verified_set.rs b/zebrad/src/components/mempool/storage/verified_set.rs index 1d1f835fb36..a9c850b4ef8 100644 --- a/zebrad/src/components/mempool/storage/verified_set.rs +++ b/zebrad/src/components/mempool/storage/verified_set.rs @@ -337,63 +337,57 @@ impl VerifiedSet { metrics::gauge!( "zcash.mempool.actions.unpaid", - unpaid_actions_with_weight_lt20pct as f64, "bk" => "< 0.2", - ); + ) + .set(unpaid_actions_with_weight_lt20pct as f64); metrics::gauge!( "zcash.mempool.actions.unpaid", - unpaid_actions_with_weight_lt40pct as f64, "bk" => "< 0.4", - ); + ) + .set(unpaid_actions_with_weight_lt40pct as f64); metrics::gauge!( "zcash.mempool.actions.unpaid", - unpaid_actions_with_weight_lt60pct as f64, "bk" => "< 0.6", - ); + ) + .set(unpaid_actions_with_weight_lt60pct as f64); metrics::gauge!( "zcash.mempool.actions.unpaid", - unpaid_actions_with_weight_lt80pct as f64, "bk" => "< 0.8", - ); + ) + .set(unpaid_actions_with_weight_lt80pct as f64); metrics::gauge!( "zcash.mempool.actions.unpaid", - unpaid_actions_with_weight_lt1 as f64, "bk" => "< 1", - ); - metrics::gauge!("zcash.mempool.actions.paid", paid_actions as f64); - metrics::gauge!( - "zcash.mempool.size.transactions", - self.transaction_count() as f64, - ); + ) + .set(unpaid_actions_with_weight_lt1 as f64); + metrics::gauge!("zcash.mempool.actions.paid").set(paid_actions as f64); + metrics::gauge!("zcash.mempool.size.transactions",).set(self.transaction_count() as f64); metrics::gauge!( "zcash.mempool.size.weighted", - size_with_weight_lt1 as f64, "bk" => "< 1", - ); + ) + .set(size_with_weight_lt1 as f64); metrics::gauge!( "zcash.mempool.size.weighted", - size_with_weight_eq1 as f64, "bk" => "1", - ); + ) + .set(size_with_weight_eq1 as f64); metrics::gauge!( "zcash.mempool.size.weighted", - size_with_weight_gt1 as f64, "bk" => "> 1", - ); + ) + .set(size_with_weight_gt1 as f64); metrics::gauge!( "zcash.mempool.size.weighted", - size_with_weight_gt2 as f64, "bk" => "> 2", - ); + ) + .set(size_with_weight_gt2 as f64); metrics::gauge!( "zcash.mempool.size.weighted", - size_with_weight_gt3 as f64, "bk" => "> 3", - ); - metrics::gauge!( - "zcash.mempool.size.bytes", - self.transactions_serialized_size as f64, - ); - metrics::gauge!("zcash.mempool.cost.bytes", self.total_cost as f64); + ) + .set(size_with_weight_gt3 as f64); + metrics::gauge!("zcash.mempool.size.bytes",).set(self.transactions_serialized_size as f64); + metrics::gauge!("zcash.mempool.cost.bytes").set(self.total_cost as f64); } } diff --git a/zebrad/src/components/sync.rs b/zebrad/src/components/sync.rs index b3a05484f9c..160e27777f3 100644 --- a/zebrad/src/components/sync.rs +++ b/zebrad/src/components/sync.rs @@ -789,7 +789,8 @@ where let new_download_len = download_set.len(); let new_hashes = new_download_len - prev_download_len; debug!(new_hashes, "added hashes to download set"); - metrics::histogram!("sync.obtain.response.hash.count", new_hashes as f64); + metrics::histogram!("sync.obtain.response.hash.count") + .record(new_hashes as f64); } Ok(_) => unreachable!("network returned wrong response"), // We ignore this error because we made multiple fanout requests. @@ -809,7 +810,7 @@ where let new_downloads = download_set.len(); debug!(new_downloads, "queueing new downloads"); - metrics::gauge!("sync.obtain.queued.hash.count", new_downloads as f64); + metrics::gauge!("sync.obtain.queued.hash.count").set(new_downloads as f64); // security: use the actual number of new downloads from all peers, // so the last peer to respond can't toggle our mempool @@ -935,7 +936,8 @@ where let new_download_len = download_set.len(); let new_hashes = new_download_len - prev_download_len; debug!(new_hashes, "added hashes to download set"); - metrics::histogram!("sync.extend.response.hash.count", new_hashes as f64); + metrics::histogram!("sync.extend.response.hash.count") + .record(new_hashes as f64); } Ok(_) => unreachable!("network returned wrong response"), // We ignore this error because we made multiple fanout requests. @@ -946,7 +948,7 @@ where let new_downloads = download_set.len(); debug!(new_downloads, "queueing new downloads"); - metrics::gauge!("sync.extend.queued.hash.count", new_downloads as f64); + metrics::gauge!("sync.extend.queued.hash.count").set(new_downloads as f64); // security: use the actual number of new downloads from all peers, // so the last peer to respond can't toggle our mempool @@ -1149,14 +1151,8 @@ where } fn update_metrics(&mut self) { - metrics::gauge!( - "sync.prospective_tips.len", - self.prospective_tips.len() as f64, - ); - metrics::gauge!( - "sync.downloads.in_flight", - self.downloads.in_flight() as f64, - ); + metrics::gauge!("sync.prospective_tips.len",).set(self.prospective_tips.len() as f64); + metrics::gauge!("sync.downloads.in_flight",).set(self.downloads.in_flight() as f64); } /// Return if the sync should be restarted based on the given error diff --git a/zebrad/src/components/sync/downloads.rs b/zebrad/src/components/sync/downloads.rs index c3322d0890c..67f6ee4844f 100644 --- a/zebrad/src/components/sync/downloads.rs +++ b/zebrad/src/components/sync/downloads.rs @@ -330,7 +330,7 @@ where hash: block::Hash, ) -> Result<(), BlockDownloadVerifyError> { if self.cancel_handles.contains_key(&hash) { - metrics::counter!("sync.already.queued.dropped.block.hash.count", 1); + metrics::counter!("sync.already.queued.dropped.block.hash.count").increment(1); return Err(BlockDownloadVerifyError::DuplicateBlockQueuedForDownload { hash }); } @@ -368,7 +368,7 @@ where biased; _ = &mut cancel_rx => { trace!("task cancelled prior to download completion"); - metrics::counter!("sync.cancelled.download.count", 1); + metrics::counter!("sync.cancelled.download.count").increment(1); return Err(BlockDownloadVerifyError::CancelledDuringDownload { hash }) } rsp = block_req => rsp.map_err(|error| BlockDownloadVerifyError::DownloadFailed { error, hash})?, @@ -389,7 +389,7 @@ where } else { unreachable!("wrong response to block request"); }; - metrics::counter!("sync.downloaded.block.count", 1); + metrics::counter!("sync.downloaded.block.count").increment(1); // Security & Performance: reject blocks that are too far ahead of our tip. // Avoids denial of service attacks, and reduces wasted work on high blocks @@ -440,7 +440,7 @@ where ?hash, "synced block with no height: dropped downloaded block" ); - metrics::counter!("sync.no.height.dropped.block.count", 1); + metrics::counter!("sync.no.height.dropped.block.count").increment(1); return Err(BlockDownloadVerifyError::InvalidHeight { hash }); }; @@ -480,16 +480,16 @@ where ); } - metrics::counter!("sync.max.height.limit.paused.count", 1); + metrics::counter!("sync.max.height.limit.paused.count").increment(1); } else if block_height <= lookahead_reset_height && past_lookahead_limit_receiver.cloned_watch_data() { // Reset the watched value to false, since we're well under the limit. // We need to block here, because if we don't the syncer can hang. // But if Zebra is shutting down, ignore the send error. let _ = past_lookahead_limit_sender.lock().expect("thread panicked while holding the past_lookahead_limit_sender mutex guard").send(false); - metrics::counter!("sync.max.height.limit.reset.count", 1); + metrics::counter!("sync.max.height.limit.reset.count").increment(1); - metrics::counter!("sync.max.height.limit.reset.attempt.count", 1); + metrics::counter!("sync.max.height.limit.reset.attempt.count").increment(1); } if block_height < min_accepted_height { @@ -501,7 +501,7 @@ where behind_tip_limit = ?zs::MAX_BLOCK_REORG_HEIGHT, "synced block height behind the finalized tip: dropped downloaded block" ); - metrics::counter!("gossip.min.height.limit.dropped.block.count", 1); + metrics::counter!("gossip.min.height.limit.dropped.block.count").increment(1); Err(BlockDownloadVerifyError::BehindTipHeightLimit { height: block_height, hash })?; } @@ -513,7 +513,7 @@ where biased; _ = &mut cancel_rx => { trace!("task cancelled waiting for verifier service readiness"); - metrics::counter!("sync.cancelled.verify.ready.count", 1); + metrics::counter!("sync.cancelled.verify.ready.count").increment(1); return Err(BlockDownloadVerifyError::CancelledAwaitingVerifierReadiness { height: block_height, hash }) } verifier = readiness => verifier, @@ -536,14 +536,14 @@ where biased; _ = &mut cancel_rx => { trace!("task cancelled prior to verification"); - metrics::counter!("sync.cancelled.verify.count", 1); + metrics::counter!("sync.cancelled.verify.count").increment(1); return Err(BlockDownloadVerifyError::CancelledDuringVerification { height: block_height, hash }) } verification = rsp => verification, }; if verification.is_ok() { - metrics::counter!("sync.verified.block.count", 1); + metrics::counter!("sync.verified.block.count").increment(1); } verification