1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! Raft metrics for observability.
//!
//! Applications may use this data in whatever way is needed. The obvious use cases are to expose
//! these metrics to a metrics collection system like Prometheus. Applications may also
//! use this data to trigger events within higher levels of the parent application.
//!
//! [`Raft::metrics()`] returns a watch receiver of the latest [`RaftMetrics`] snapshot that the
//! Raft node published. The runtime configured as [`RaftTypeConfig::AsyncRuntime`] provides the
//! receiver type, and the [`WatchReceiver`] trait provides the methods that read the snapshot and
//! wait for a newer one. [`Raft::wait()`] returns a [`Wait`] that waits until a snapshot satisfies
//! a condition.
//!
//!
//! ## [`RaftMetrics`]
//!
//! [`RaftMetrics`] contains useful information such as:
//!
//! - Server state(leader/follower/learner/candidate) of this raft node,
//! - The current leader,
//! - Last log and applied log.
//! - Replication state, if this node is a Leader,
//! - Snapshot state,
//! - etc.
//!
//! Each snapshot that the Raft node publishes replaces the previous one, so a reader observes the
//! latest state but can miss intermediate changes. Application events are therefore reactions to
//! observed snapshots. To act on a change, such as this node becoming the leader, compare each
//! observed snapshot with the last one the application acted on, because a notification of a new
//! snapshot says neither which field changed nor whether any did.
//!
//! [`Raft::metrics()`]: crate::Raft::metrics
//! [`Raft::wait()`]: crate::Raft::wait
//! [`RaftTypeConfig::AsyncRuntime`]: crate::RaftTypeConfig::AsyncRuntime
//! [`WatchReceiver`]: crate::async_runtime::WatchReceiver
use BTreeMap;
pub use Metric;
pub use RaftDataMetrics;
pub use RaftMetrics;
pub use RaftServerMetrics;
pub use MetricsRecorder;
pub use forward_metrics;
pub use ReplicationWaitError;
pub use SerdeInstant;
pub use Wait;
pub use WaitError;
pub use Condition;
use crateLogIdOf;
use crateNodeIdOf;
use crateSerdeInstantOf;
pub type ReplicationMetrics<C> = ;
/// Heartbeat metrics, a mapping between a node's ID and the time of the last
/// acknowledged heartbeat or replication to this node.
pub type HeartbeatMetrics<C> = ;