Skip to content

Commit 0436a11

Browse files
committed
update all metric macros
1 parent 113235a commit 0436a11

File tree

30 files changed

+223
-294
lines changed

30 files changed

+223
-294
lines changed

zebra-consensus/src/checkpoint.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ fn progress_from_tip(
103103
if height >= checkpoint_list.max_height() {
104104
(None, Progress::FinalCheckpoint)
105105
} else {
106-
metrics::gauge!("checkpoint.verified.height", height.0 as f64);
107-
metrics::gauge!("checkpoint.processing.next.height", height.0 as f64);
106+
metrics::gauge!("checkpoint.verified.height").set(height.0 as f64);
107+
metrics::gauge!("checkpoint.processing.next.height").set(height.0 as f64);
108108
(Some(hash), Progress::InitialTip(height))
109109
}
110110
}
@@ -303,7 +303,7 @@ where
303303
.next_back()
304304
.expect("queued has at least one entry");
305305

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

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

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

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

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

336336
tracing::debug!(
337337
?verified_height,
@@ -409,7 +409,7 @@ where
409409
// Check if we have the genesis block as a special case, to simplify the loop
410410
BeforeGenesis if !self.queued.contains_key(&block::Height(0)) => {
411411
tracing::trace!("Waiting for genesis block");
412-
metrics::counter!("checkpoint.waiting.count", 1);
412+
metrics::counter!("checkpoint.waiting.count").increment(1);
413413
return WaitingForBlocks;
414414
}
415415
BeforeGenesis => block::Height(0),
@@ -444,10 +444,7 @@ where
444444
break;
445445
}
446446
}
447-
metrics::gauge!(
448-
"checkpoint.queued.continuous.height",
449-
pending_height.0 as f64,
450-
);
447+
metrics::gauge!("checkpoint.queued.continuous.height").set(pending_height.0 as f64);
451448

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

468465
if let Some(block::Height(target_checkpoint)) = target_checkpoint {
469-
metrics::gauge!(
470-
"checkpoint.processing.next.height",
471-
target_checkpoint as f64,
472-
);
466+
metrics::gauge!("checkpoint.processing.next.height").set(target_checkpoint as f64);
473467
} else {
474468
// Use the start height if there is no potential next checkpoint
475-
metrics::gauge!("checkpoint.processing.next.height", start_height.0 as f64);
476-
metrics::counter!("checkpoint.waiting.count", 1);
469+
metrics::gauge!("checkpoint.processing.next.height").set(start_height.0 as f64);
470+
metrics::counter!("checkpoint.waiting.count").increment(1);
477471
}
478472

479473
target_checkpoint
@@ -541,12 +535,12 @@ where
541535
/// Increase the current checkpoint height to `verified_height`,
542536
fn update_progress(&mut self, verified_height: block::Height) {
543537
if let Some(max_height) = self.queued.keys().next_back() {
544-
metrics::gauge!("checkpoint.queued.max.height", max_height.0 as f64);
538+
metrics::gauge!("checkpoint.queued.max.height").set(max_height.0 as f64);
545539
} else {
546540
// use f64::NAN as a sentinel value for "None", because 0 is a valid height
547-
metrics::gauge!("checkpoint.queued.max.height", f64::NAN);
541+
metrics::gauge!("checkpoint.queued.max.height").set(f64::NAN);
548542
}
549-
metrics::gauge!("checkpoint.queued_slots", self.queued.len() as f64);
543+
metrics::gauge!("checkpoint.queued_slots").set(self.queued.len() as f64);
550544

551545
// Ignore blocks that are below the previous checkpoint, or otherwise
552546
// have invalid heights.
@@ -869,7 +863,7 @@ where
869863

870864
let block_count = rev_valid_blocks.len();
871865
tracing::info!(?block_count, ?current_range, "verified checkpoint range");
872-
metrics::counter!("checkpoint.verified.block.count", block_count as u64);
866+
metrics::counter!("checkpoint.verified.block.count").increment(block_count as u64);
873867

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

10591053
self.process_checkpoint_range();
10601054

1061-
metrics::gauge!("checkpoint.queued_slots", self.queued.len() as f64);
1055+
metrics::gauge!("checkpoint.queued_slots").set(self.queued.len() as f64);
10621056

10631057
// Because the checkpoint verifier duplicates state from the state
10641058
// service (it tracks which checkpoints have been verified), we must

zebra-consensus/src/primitives/ed25519.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ impl Service<BatchControl<Item>> for Verifier {
164164

165165
if result.is_ok() {
166166
tracing::trace!(?result, "validated ed25519 signature");
167-
metrics::counter!("signatures.ed25519.validated", 1);
167+
metrics::counter!("signatures.ed25519.validated").increment(1);
168168
} else {
169169
tracing::trace!(?result, "invalid ed25519 signature");
170-
metrics::counter!("signatures.ed25519.invalid", 1);
170+
metrics::counter!("signatures.ed25519.invalid").increment(1);
171171
}
172172
result.map_err(BoxError::from)
173173
}

zebra-consensus/src/primitives/groth16.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ impl Service<BatchControl<Item>> for Verifier {
485485

486486
if result.is_ok() {
487487
tracing::trace!(?result, "verified groth16 proof");
488-
metrics::counter!("proofs.groth16.verified", 1);
488+
metrics::counter!("proofs.groth16.verified").increment(1);
489489
} else {
490490
tracing::trace!(?result, "invalid groth16 proof");
491-
metrics::counter!("proofs.groth16.invalid", 1);
491+
metrics::counter!("proofs.groth16.invalid").increment(1);
492492
}
493493

494494
result.map_err(BoxError::from)

zebra-consensus/src/primitives/halo2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ impl Service<BatchControl<Item>> for Verifier {
348348

349349
if result.is_ok() {
350350
tracing::trace!(?result, "verified halo2 proof");
351-
metrics::counter!("proofs.halo2.verified", 1);
351+
metrics::counter!("proofs.halo2.verified").increment(1);
352352
} else {
353353
tracing::trace!(?result, "invalid halo2 proof");
354-
metrics::counter!("proofs.halo2.invalid", 1);
354+
metrics::counter!("proofs.halo2.invalid").increment(1);
355355
}
356356

357357
result.map_err(BoxError::from)

zebra-consensus/src/primitives/redjubjub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ impl Service<BatchControl<Item>> for Verifier {
165165

166166
if result.is_ok() {
167167
tracing::trace!(?result, "validated redjubjub signature");
168-
metrics::counter!("signatures.redjubjub.validated", 1);
168+
metrics::counter!("signatures.redjubjub.validated").increment(1);
169169
} else {
170170
tracing::trace!(?result, "invalid redjubjub signature");
171-
metrics::counter!("signatures.redjubjub.invalid", 1);
171+
metrics::counter!("signatures.redjubjub.invalid").increment(1);
172172
}
173173

174174
result.map_err(BoxError::from)

zebra-consensus/src/primitives/redpallas.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ impl Service<BatchControl<Item>> for Verifier {
164164

165165
if result.is_ok() {
166166
tracing::trace!(?result, "validated redpallas signature");
167-
metrics::counter!("signatures.redpallas.validated", 1);
167+
metrics::counter!("signatures.redpallas.validated").increment(1);
168168
} else {
169169
tracing::trace!(?result, "invalid redpallas signature");
170-
metrics::counter!("signatures.redpallas.invalid", 1);
170+
metrics::counter!("signatures.redpallas.invalid").increment(1);
171171
}
172172

173173
result.map_err(BoxError::from)

zebra-network/src/address_book.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -696,18 +696,15 @@ impl AddressBook {
696696
let _ = self.address_metrics_tx.send(m);
697697

698698
// TODO: rename to address_book.[state_name]
699-
metrics::gauge!("candidate_set.responded", m.responded as f64);
700-
metrics::gauge!("candidate_set.gossiped", m.never_attempted_gossiped as f64);
701-
metrics::gauge!("candidate_set.failed", m.failed as f64);
702-
metrics::gauge!("candidate_set.pending", m.attempt_pending as f64);
699+
metrics::gauge!("candidate_set.responded").set(m.responded as f64);
700+
metrics::gauge!("candidate_set.gossiped").set(m.never_attempted_gossiped as f64);
701+
metrics::gauge!("candidate_set.failed").set(m.failed as f64);
702+
metrics::gauge!("candidate_set.pending").set(m.attempt_pending as f64);
703703

704704
// TODO: rename to address_book.responded.recently_live
705-
metrics::gauge!("candidate_set.recently_live", m.recently_live as f64);
705+
metrics::gauge!("candidate_set.recently_live").set(m.recently_live as f64);
706706
// TODO: rename to address_book.responded.stopped_responding
707-
metrics::gauge!(
708-
"candidate_set.disconnected",
709-
m.recently_stopped_responding as f64,
710-
);
707+
metrics::gauge!("candidate_set.disconnected").set(m.recently_stopped_responding as f64);
711708

712709
std::mem::drop(_guard);
713710
self.log_metrics(&m, instant_now);

zebra-network/src/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,10 @@ impl Config {
353353
// (But we only make one initial connection attempt to each IP.)
354354
metrics::counter!(
355355
"zcash.net.peers.initial",
356-
1,
357356
"seed" => host.to_string(),
358357
"remote_ip" => ip.to_string()
359-
);
358+
)
359+
.increment(1);
360360
}
361361

362362
Ok(ip_addrs.into_iter().collect())
@@ -440,10 +440,10 @@ impl Config {
440440
// (But we only make one initial connection attempt to each IP.)
441441
metrics::counter!(
442442
"zcash.net.peers.initial",
443-
1,
444443
"cache" => peer_cache_file.display().to_string(),
445444
"remote_ip" => ip.to_string()
446-
);
445+
)
446+
.increment(1);
447447
}
448448

449449
Ok(peer_list)
@@ -553,10 +553,10 @@ impl Config {
553553
for ip in &peer_list {
554554
metrics::counter!(
555555
"zcash.net.peers.cache",
556-
1,
557556
"cache" => peer_cache_file.display().to_string(),
558557
"remote_ip" => ip.to_string()
559-
);
558+
)
559+
.increment(1);
560560
}
561561

562562
Ok(())

zebra-network/src/peer/connection.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -790,10 +790,10 @@ where
790790
// Add a metric for inbound responses to outbound requests.
791791
metrics::counter!(
792792
"zebra.net.in.responses",
793-
1,
794793
"command" => response.command(),
795794
"addr" => self.metrics_label.clone(),
796-
);
795+
)
796+
.increment(1);
797797
} else {
798798
debug!(error = ?response, "error in peer response to Zebra request");
799799
}
@@ -969,15 +969,15 @@ where
969969
let InProgressClientRequest { request, tx, span } = req;
970970

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

975975
metrics::counter!(
976976
"zebra.net.out.requests.canceled",
977-
1,
978977
"command" => request.command(),
979978
"addr" => self.metrics_label.clone(),
980-
);
979+
)
980+
.increment(1);
981981
self.update_state_metrics(format!("Out::Req::Canceled::{}", request.command()));
982982

983983
return;
@@ -988,10 +988,10 @@ where
988988
// Add a metric for outbound requests.
989989
metrics::counter!(
990990
"zebra.net.out.requests",
991-
1,
992991
"command" => request.command(),
993992
"addr" => self.metrics_label.clone(),
994-
);
993+
)
994+
.increment(1);
995995
self.update_state_metrics(format!("Out::Req::{}", request.command()));
996996

997997
let new_handler = match (&self.state, request) {
@@ -1360,10 +1360,10 @@ where
13601360
// Add a metric for inbound requests
13611361
metrics::counter!(
13621362
"zebra.net.in.requests",
1363-
1,
13641363
"command" => req.command(),
13651364
"addr" => self.metrics_label.clone(),
1366-
);
1365+
)
1366+
.increment(1);
13671367
self.update_state_metrics(format!("In::Req::{}", req.command()));
13681368

13691369
// Give the inbound service time to clear its queue,
@@ -1431,10 +1431,10 @@ where
14311431
// Add a metric for outbound responses to inbound requests
14321432
metrics::counter!(
14331433
"zebra.net.out.responses",
1434-
1,
14351434
"command" => rsp.command(),
14361435
"addr" => self.metrics_label.clone(),
1437-
);
1436+
)
1437+
.increment(1);
14381438
self.update_state_metrics(format!("In::Rsp::{}", rsp.command()));
14391439

14401440
// TODO: split response handler into its own method
@@ -1570,9 +1570,9 @@ where
15701570

15711571
if thread_rng().gen::<f32>() < drop_connection_probability {
15721572
if matches!(error, PeerError::Overloaded) {
1573-
metrics::counter!("pool.closed.loadshed", 1);
1573+
metrics::counter!("pool.closed.loadshed").increment(1);
15741574
} else {
1575-
metrics::counter!("pool.closed.inbound.timeout", 1);
1575+
metrics::counter!("pool.closed.inbound.timeout").increment(1);
15761576
}
15771577

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

15961596
if matches!(error, PeerError::Overloaded) {
1597-
metrics::counter!("pool.ignored.loadshed", 1);
1597+
metrics::counter!("pool.ignored.loadshed").increment(1);
15981598
} else {
1599-
metrics::counter!("pool.ignored.inbound.timeout", 1);
1599+
metrics::counter!("pool.ignored.inbound.timeout").increment(1);
16001600
}
16011601
}
16021602
}
@@ -1659,12 +1659,12 @@ where
16591659
self.erase_state_metrics();
16601660

16611661
// Set the new state
1662-
metrics::increment_gauge!(
1662+
metrics::gauge!(
16631663
"zebra.net.connection.state",
1664-
1.0,
16651664
"command" => current_metrics_state.clone(),
16661665
"addr" => self.metrics_label.clone(),
1667-
);
1666+
)
1667+
.set(1.0);
16681668

16691669
self.last_metrics_state = Some(current_metrics_state);
16701670
}
@@ -1674,10 +1674,10 @@ where
16741674
if let Some(last_metrics_state) = self.last_metrics_state.take() {
16751675
metrics::gauge!(
16761676
"zebra.net.connection.state",
1677-
0.0,
16781677
"command" => last_metrics_state,
16791678
"addr" => self.metrics_label.clone(),
1680-
);
1679+
)
1680+
.set(0.0);
16811681
}
16821682
}
16831683

0 commit comments

Comments
 (0)