Skip to content

Commit 7b1d466

Browse files
committed
Change: rename RaftMetrics.leader_metrics to replication
- part of #229
1 parent cccddcc commit 7b1d466

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

openraft/src/core/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -398,24 +398,29 @@ impl<C: RaftTypeConfig, N: RaftNetworkFactory<C>, S: RaftStorage<C>> RaftCore<C,
398398

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

407407
let m = RaftMetrics {
408408
running_state: Ok(()),
409-
410409
id: self.id,
411-
state: self.target_state,
410+
411+
// --- data ---
412412
current_term: self.vote.term,
413413
last_log_index: self.last_log_id.map(|id| id.index),
414414
last_applied: self.last_applied,
415+
snapshot: self.snapshot_last_log_id,
416+
417+
// --- cluster ---
418+
state: self.target_state,
415419
current_leader: self.current_leader(),
416420
membership_config: self.effective_membership.clone(),
417-
snapshot: self.snapshot_last_log_id,
418-
leader_metrics,
421+
422+
// --- replication ---
423+
replication,
419424
};
420425

421426
{

openraft/src/metrics/raft_metrics.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ pub struct RaftMetrics<C: RaftTypeConfig> {
4949
// --- replication ---
5050
// ---
5151
/// The metrics about the leader. It is Some() only when this node is leader.
52-
pub leader_metrics: Option<Versioned<ReplicationMetrics<C::NodeId>>>,
52+
pub replication: Option<Versioned<ReplicationMetrics<C::NodeId>>>,
5353
}
5454

5555
impl<C: RaftTypeConfig> MessageSummary for RaftMetrics<C> {
5656
fn summary(&self) -> String {
5757
format!("Metrics{{id:{},{:?}, term:{}, last_log:{:?}, last_applied:{:?}, leader:{:?}, membership:{}, snapshot:{:?}, replication:{}",
58-
self.id,
59-
self.state,
60-
self.current_term,
61-
self.last_log_index,
62-
self.last_applied,
63-
self.current_leader,
64-
self.membership_config.summary(),
65-
self.snapshot,
66-
self.leader_metrics.as_ref().map(|x| x.summary()).unwrap_or_default(),
58+
self.id,
59+
self.state,
60+
self.current_term,
61+
self.last_log_index,
62+
self.last_applied,
63+
self.current_leader,
64+
self.membership_config.summary(),
65+
self.snapshot,
66+
self.replication.as_ref().map(|x| x.summary()).unwrap_or_default(),
6767
)
6868
}
6969
}
@@ -80,7 +80,7 @@ impl<C: RaftTypeConfig> RaftMetrics<C> {
8080
current_leader: None,
8181
membership_config: Arc::new(EffectiveMembership::default()),
8282
snapshot: None,
83-
leader_metrics: None,
83+
replication: None,
8484
}
8585
}
8686
}

openraft/src/metrics/wait_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn init_wait_test<C: RaftTypeConfig>() -> (RaftMetrics<C>, Wait<C>, watch::Sende
209209
)),
210210

211211
snapshot: None,
212-
leader_metrics: None,
212+
replication: None,
213213
};
214214
let (tx, rx) = watch::channel(init.clone());
215215
let w = Wait {

openraft/tests/metrics/t30_leader_metrics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async fn leader_metrics() -> Result<()> {
6565
.wait_for_metrics(
6666
&0,
6767
|x| {
68-
if let Some(ref q) = x.leader_metrics {
68+
if let Some(ref q) = x.replication {
6969
q.data().replication.is_empty()
7070
} else {
7171
false
@@ -113,7 +113,7 @@ async fn leader_metrics() -> Result<()> {
113113
.wait_for_metrics(
114114
&0,
115115
|x| {
116-
if let Some(ref q) = x.leader_metrics {
116+
if let Some(ref q) = x.replication {
117117
q.data().replication == want_repl
118118
} else {
119119
false
@@ -162,7 +162,7 @@ async fn leader_metrics() -> Result<()> {
162162
.wait_for_metrics(
163163
&0,
164164
|x| {
165-
if let Some(ref q) = x.leader_metrics {
165+
if let Some(ref q) = x.replication {
166166
q.data().replication == want_repl
167167
} else {
168168
false
@@ -190,7 +190,7 @@ async fn leader_metrics() -> Result<()> {
190190
router
191191
.wait_for_metrics(
192192
&leader,
193-
|x| x.leader_metrics.is_none(),
193+
|x| x.replication.is_none(),
194194
timeout(),
195195
"node 0 should close all replication",
196196
)
@@ -220,7 +220,7 @@ async fn leader_metrics() -> Result<()> {
220220
router
221221
.wait_for_metrics(
222222
&leader,
223-
|x| x.leader_metrics.is_some(),
223+
|x| x.replication.is_some(),
224224
timeout(),
225225
"new leader spawns replication",
226226
)

0 commit comments

Comments
 (0)