Open drmingdrmer opened 9 months ago
61ec7617ff
)[!TIP] I'll email you at drdr.xp@gmail.com when I complete this pull request!
Install Sweep Configs: Pull Request
Here are the GitHub Actions logs prior to making any changes:
ab7f309
Checking openraft/src/metrics/raft_metrics.rs for syntax errors... ✅ openraft/src/metrics/raft_metrics.rs has no syntax errors!
1/1 ✓Checking openraft/src/metrics/raft_metrics.rs for syntax errors... ✅ openraft/src/metrics/raft_metrics.rs has no syntax errors!
Sandbox passed on the latest main
, so sandbox checks will be enabled for this issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
openraft/src/metrics/raft_metrics.rs
✓ https://github.com/drmingdrmer/openraft/commit/98ef2e355a70fdc24178115c9cc265598c665ff9 Edit
Modify openraft/src/metrics/raft_metrics.rs with contents:
• Split the `RaftMetrics` struct into two separate structs: `RaftDataMetrics` and `RaftServerMetrics`.
• The `RaftDataMetrics` struct should contain the following fields: `last_log_index`, `last_applied`, `snapshot`, and `purged`.
• The `RaftServerMetrics` struct should contain the following fields: `running_state`, `id`, `current_term`, `vote`, `state`, `current_leader`, `membership_config`, and `replication`.
• Ensure that both new structs derive the necessary traits for serialization and deserialization.
--- +++ @@ -12,28 +12,14 @@ use crate::StoredMembership; use crate::Vote; -/// A set of metrics describing the current state of a Raft node. +/// A set of data-related metrics describing the current state of a Raft node. #[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize), serde(bound = ""))] -pub struct RaftMetrics+pub struct RaftDataMetrics where NID: NodeId, N: Node, { - pub running_state: Result<(), Fatal >, - - /// The ID of the Raft node. - pub id: NID, - - // --- - // --- data --- - // --- - /// The current term of the Raft node. - pub current_term: u64, - - /// The last accepted vote. - pub vote: Vote , - /// The last log index has been appended to this Raft node's log. pub last_log_index: Option , @@ -45,7 +31,38 @@ pub snapshot: Option >, /// The last log id that has purged from storage, inclusive. - /// + pub purged: Option >, +/// A set of server-related metrics describing the current state of a Raft node. +#[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize), serde(bound = ""))] +pub struct RaftServerMetrics +where + NID: NodeId, + N: Node, +{ + pub running_state: Result<(), Fatal >, + + /// The ID of the Raft node. + pub id: NID, + + /// The current term of the Raft node. + pub current_term: u64, + + /// The last accepted vote. + pub vote: Vote , + + /// The state of the Raft node. + pub state: ServerState, + + /// The current cluster leader. + pub current_leader: Option , + + /// The current membership config of the cluster. + pub membership_config: Arc >, + + /// The replication states. It is Some() only when this node is leader. + pub replication: Option >, +} /// `purged` is also the first log id Openraft knows, although the corresponding log entry has /// already been deleted. pub purged: Option >,
openraft/src/metrics/raft_metrics.rs
⋯ Edit
Check openraft/src/metrics/raft_metrics.rs with contents:
Ran GitHub Actions for 98ef2e355a70fdc24178115c9cc265598c665ff9:
• tests-feature-test (nightly, loosen-follower-log-revert): ⋯
• tests-feature-test (nightly, single-term-leader): ⋯
• openraft-test (nightly, 0, single-term-leader): ⋯
• tests-feature-test (nightly): ⋯
• openraft-feature-test (nightly, single-term-leader,serde,singlethreaded): ⋯
• openraft-feature-test (nightly, single-term-leader): ⋯
• openraft-test (nightly, 30): ⋯
• openraft-feature-test (nightly, serde): ⋯
• Build (nightly, bench,serde,bt,singlethreaded): ⋯
• openraft-test (stable, 0): ⋯
• openraft-feature-test (nightly): ⋯
• lint: ⋯
• examples (nightly, raft-kv-rocksdb): ⋯
• stores (sledstore): ⋯
• examples (nightly, raft-kv-memstore): ⋯
• external-stores (stores/rocksstore-v2): ⋯
• examples (stable, raft-kv-rocksdb): ⋯
• stores (rocksstore-compat07): ⋯
• examples (stable, raft-kv-memstore): ⋯
• stores (rocksstore): ⋯
• cluster-benchmark (cluster_benchmark): ⋯
• stores (memstore): ⋯
• openraft-test-bench (nightly): ⋯
• check-subject: ⋯
openraft/src/core/raft_core.rs
▶ Edit
Modify openraft/src/core/raft_core.rs with contents:
• Modify the `report_metrics` function to create instances of the `RaftDataMetrics` and `RaftServerMetrics` structs instead of the `RaftMetrics` struct.
• Send the `RaftDataMetrics` and `RaftServerMetrics` instances via their respective channels.
• Handle any errors that may occur when sending the metrics.
openraft/src/core/raft_core.rs
▶ Edit
Check openraft/src/core/raft_core.rs with contents:
openraft/src/core/raft_core.rs
▶ Edit
Modify openraft/src/core/raft_core.rs with contents:
• Add two new methods to the `Raft` struct: `data_metrics` and `server_metrics`.
• The `data_metrics` method should return a `watch::Receiver`.
• The `server_metrics` method should return a `watch::Receiver`.
• Both methods should be public and take no arguments.
openraft/src/core/raft_core.rs
▶ Edit
Check openraft/src/core/raft_core.rs with contents:
Working on it...
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord
This is an automated message generated by Sweep AI.
👋 Thanks for opening this issue!
Get help or engage by:
/help
: to print help messages./assignme
: to assign this issue to you.
RaftMetrics encapsulates a range of information about the internal states of a Raft node, including the server state (e.g., Leader, Follower), and data-related states such as the last log index and the last applied log index.
Applications interested in monitoring these details can subscribe to RaftMetrics to receive updates when these metrics change, with
Raft::metrics()
.However, some metrics, like
last_log_index
, are frequently updated, while others, such ascurrent_term
andstate
, change less often.For applications solely concerned with server state transitions (like switching from Leader to Follower), being notified of changes to
last_log_index
can result in unnecessary wake-ups.To optimize this, it would be beneficial to add two subsets of the metrics:
current_term
,vote
, andstate
.last_log_index
andlast_applied
.By segregating these metrics, applications can subscribe to the relevant subset and reduce the overhead of processing frequent updates that are not pertinent to their needs.
TODO:
[ ] add
Raft::data_metrics()
to return awatch::Receiver<RaftDataMetrics>
that contains only metrics about log, state machine and snapshot.[ ] add
Raft::server_metrics()
to return awatch::Receiver<RaftServerMetrics>
that contains only server related metrics, such asvote
,leader
,id
,running_state
,membership
Checklist
- [X] Modify `openraft/src/metrics/raft_metrics.rs` ✓ https://github.com/drmingdrmer/openraft/commit/98ef2e355a70fdc24178115c9cc265598c665ff9 [Edit](https://github.com/drmingdrmer/openraft/edit/sweep/split_metrics_into_data_metrics_and_serv/openraft/src/metrics/raft_metrics.rs#L18-L69) - [ ] Running GitHub Actions for `openraft/src/metrics/raft_metrics.rs` ⋯ [Edit](https://github.com/drmingdrmer/openraft/edit/sweep/split_metrics_into_data_metrics_and_serv/openraft/src/metrics/raft_metrics.rs#L18-L69) - [ ] Modify `openraft/src/core/raft_core.rs` ▶ [Edit](https://github.com/drmingdrmer/openraft/edit/sweep/split_metrics_into_data_metrics_and_serv/openraft/src/core/raft_core.rs#L521-L551) - [ ] Running GitHub Actions for `openraft/src/core/raft_core.rs` ▶ [Edit](https://github.com/drmingdrmer/openraft/edit/sweep/split_metrics_into_data_metrics_and_serv/openraft/src/core/raft_core.rs#L521-L551) - [ ] Modify `openraft/src/core/raft_core.rs` ▶ [Edit](https://github.com/drmingdrmer/openraft/edit/sweep/split_metrics_into_data_metrics_and_serv/openraft/src/core/raft_core.rs#L1-L10) - [ ] Running GitHub Actions for `openraft/src/core/raft_core.rs` ▶ [Edit](https://github.com/drmingdrmer/openraft/edit/sweep/split_metrics_into_data_metrics_and_serv/openraft/src/core/raft_core.rs#L1-L10)