Skip to content

Commit

Permalink
[Narwhal] improve proposer metrics (#7738)
Browse files Browse the repository at this point in the history
Addressing feedback from #7730
  • Loading branch information
mwtian committed Jan 26, 2023
1 parent a4a0a9c commit c4d95c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
26 changes: 15 additions & 11 deletions narwhal/primary/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use mysten_network::metrics::MetricsCallbackProvider;
use network::metrics::{NetworkConnectionMetrics, NetworkMetrics};
use prometheus::{
core::{AtomicI64, GenericGauge},
default_registry, register_histogram_vec_with_registry, register_histogram_with_registry,
register_int_counter_vec_with_registry, register_int_counter_with_registry,
register_int_gauge_vec_with_registry, register_int_gauge_with_registry, Histogram,
HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Registry,
default_registry, linear_buckets, register_histogram_vec_with_registry,
register_histogram_with_registry, register_int_counter_vec_with_registry,
register_int_counter_with_registry, register_int_gauge_vec_with_registry,
register_int_gauge_with_registry, Histogram, HistogramVec, IntCounter, IntCounterVec, IntGauge,
IntGaugeVec, Registry,
};
use std::time::Duration;
use tonic::Code;
Expand Down Expand Up @@ -272,10 +273,6 @@ impl PrimaryChannelMetrics {
"total received on channel signaling own committed headers.",
registry
).unwrap(),




}
}

Expand Down Expand Up @@ -316,7 +313,7 @@ pub struct PrimaryMetrics {
pub headers_proposed: IntCounterVec,
// total number of parents in all proposed headers, for calculating average number of parents
// per header.
pub header_parents_total: IntCounter,
pub header_parents: Histogram,
/// the current proposed header round
pub proposed_header_round: IntGauge,
/// The number of received votes for the proposed last round
Expand Down Expand Up @@ -362,6 +359,12 @@ pub struct PrimaryMetrics {

impl PrimaryMetrics {
pub fn new(registry: &Registry) -> Self {
let parents_buckets = [
linear_buckets(1.0, 1.0, 20).unwrap().as_slice(),
linear_buckets(21.0, 2.0, 20).unwrap().as_slice(),
linear_buckets(61.0, 3.0, 20).unwrap().as_slice(),
]
.concat();
Self {
headers_proposed: register_int_counter_vec_with_registry!(
"headers_proposed",
Expand All @@ -370,9 +373,10 @@ impl PrimaryMetrics {
registry
)
.unwrap(),
header_parents_total: register_int_counter_with_registry!(
"header_parents_total",
header_parents: register_histogram_with_registry!(
"header_parents",
"Number of parents included in proposed headers",
parents_buckets,
registry
)
.unwrap(),
Expand Down
19 changes: 11 additions & 8 deletions narwhal/primary/src/proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,23 +228,26 @@ impl Proposer {
)
.await;

let leader_support = if this_round % 2 == 0 {
"even_round"
let leader_and_support = if this_round % 2 == 0 {
let leader_name = self.committee.leader(this_round);
if self.name == leader_name {
"even_round_is_leader"
} else {
"even_round_not_leader"
}
} else {
let leader_name = self.committee.leader(this_round - 1);
if parents.iter().any(|c| c.origin() == leader_name) {
"has_support"
"odd_round_gives_support"
} else {
"no_support"
"odd_round_no_support"
}
};
self.metrics
.headers_proposed
.with_label_values(&[leader_support])
.with_label_values(&[leader_and_support])
.inc();
self.metrics
.header_parents_total
.inc_by(parents.len() as u64);
self.metrics.header_parents.observe(parents.len() as f64);

if enabled!(tracing::Level::DEBUG) {
let mut msg = format!("Created header {header:?} with parent certificates:\n");
Expand Down

0 comments on commit c4d95c7

Please sign in to comment.