Skip to content

Commit

Permalink
Change: rename RaftMetrics.leader_metrics to replication
Browse files Browse the repository at this point in the history
- part of #229
  • Loading branch information
drmingdrmer committed Apr 9, 2022
1 parent cccddcc commit 7b1d466
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
19 changes: 12 additions & 7 deletions openraft/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,24 +398,29 @@ impl<C: RaftTypeConfig, N: RaftNetworkFactory<C>, S: RaftStorage<C>> RaftCore<C,

/// Report a metrics payload on the current state of the Raft node.
#[tracing::instrument(level = "trace", skip(self))]
fn report_metrics(&self, leader_metrics: Update<Option<Versioned<ReplicationMetrics<C::NodeId>>>>) {
let leader_metrics = match leader_metrics {
fn report_metrics(&self, replication: Update<Option<Versioned<ReplicationMetrics<C::NodeId>>>>) {
let replication = match replication {
Update::Update(v) => v,
Update::AsIs => self.tx_metrics.borrow().leader_metrics.clone(),
Update::AsIs => self.tx_metrics.borrow().replication.clone(),
};

let m = RaftMetrics {
running_state: Ok(()),

id: self.id,
state: self.target_state,

// --- data ---
current_term: self.vote.term,
last_log_index: self.last_log_id.map(|id| id.index),
last_applied: self.last_applied,
snapshot: self.snapshot_last_log_id,

// --- cluster ---
state: self.target_state,
current_leader: self.current_leader(),
membership_config: self.effective_membership.clone(),
snapshot: self.snapshot_last_log_id,
leader_metrics,

// --- replication ---
replication,
};

{
Expand Down
22 changes: 11 additions & 11 deletions openraft/src/metrics/raft_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ pub struct RaftMetrics<C: RaftTypeConfig> {
// --- replication ---
// ---
/// The metrics about the leader. It is Some() only when this node is leader.
pub leader_metrics: Option<Versioned<ReplicationMetrics<C::NodeId>>>,
pub replication: Option<Versioned<ReplicationMetrics<C::NodeId>>>,
}

impl<C: RaftTypeConfig> MessageSummary for RaftMetrics<C> {
fn summary(&self) -> String {
format!("Metrics{{id:{},{:?}, term:{}, last_log:{:?}, last_applied:{:?}, leader:{:?}, membership:{}, snapshot:{:?}, replication:{}",
self.id,
self.state,
self.current_term,
self.last_log_index,
self.last_applied,
self.current_leader,
self.membership_config.summary(),
self.snapshot,
self.leader_metrics.as_ref().map(|x| x.summary()).unwrap_or_default(),
self.id,
self.state,
self.current_term,
self.last_log_index,
self.last_applied,
self.current_leader,
self.membership_config.summary(),
self.snapshot,
self.replication.as_ref().map(|x| x.summary()).unwrap_or_default(),
)
}
}
Expand All @@ -80,7 +80,7 @@ impl<C: RaftTypeConfig> RaftMetrics<C> {
current_leader: None,
membership_config: Arc::new(EffectiveMembership::default()),
snapshot: None,
leader_metrics: None,
replication: None,
}
}
}
2 changes: 1 addition & 1 deletion openraft/src/metrics/wait_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn init_wait_test<C: RaftTypeConfig>() -> (RaftMetrics<C>, Wait<C>, watch::Sende
)),

snapshot: None,
leader_metrics: None,
replication: None,
};
let (tx, rx) = watch::channel(init.clone());
let w = Wait {
Expand Down
10 changes: 5 additions & 5 deletions openraft/tests/metrics/t30_leader_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn leader_metrics() -> Result<()> {
.wait_for_metrics(
&0,
|x| {
if let Some(ref q) = x.leader_metrics {
if let Some(ref q) = x.replication {
q.data().replication.is_empty()
} else {
false
Expand Down Expand Up @@ -113,7 +113,7 @@ async fn leader_metrics() -> Result<()> {
.wait_for_metrics(
&0,
|x| {
if let Some(ref q) = x.leader_metrics {
if let Some(ref q) = x.replication {
q.data().replication == want_repl
} else {
false
Expand Down Expand Up @@ -162,7 +162,7 @@ async fn leader_metrics() -> Result<()> {
.wait_for_metrics(
&0,
|x| {
if let Some(ref q) = x.leader_metrics {
if let Some(ref q) = x.replication {
q.data().replication == want_repl
} else {
false
Expand Down Expand Up @@ -190,7 +190,7 @@ async fn leader_metrics() -> Result<()> {
router
.wait_for_metrics(
&leader,
|x| x.leader_metrics.is_none(),
|x| x.replication.is_none(),
timeout(),
"node 0 should close all replication",
)
Expand Down Expand Up @@ -220,7 +220,7 @@ async fn leader_metrics() -> Result<()> {
router
.wait_for_metrics(
&leader,
|x| x.leader_metrics.is_some(),
|x| x.replication.is_some(),
timeout(),
"new leader spawns replication",
)
Expand Down

0 comments on commit 7b1d466

Please sign in to comment.