-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add API and command to fetch information of about a Raft node #3544
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I left one comment about the leadership check.
switch m.raft.State() { | ||
case raft.Leader: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably does not make a big difference here based on the context of how we use it, but this check can return stale information (a non-leader could "think" they are the leader when they are not).
There is a VerifyLeader()
method that we can call which will run a sequence of commands through the raft log that will make it a stronger guarantee.
We use it in
if err := m.raft.VerifyLeader().Error(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In 270171c I incorporated this check. It's reflected in the IsLeaderVerified
field of the response. Here's an example output:
ID: pyroscope-metastore-0.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
State: Follower
State verified: true
Leader ID: pyroscope-metastore-1.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
Last leader contact: 2024-09-06T17:15:32-07:00
Term: 8
Suffrage: Voter
Log:
Commit index: 988
Applied index: 988
Last index: 988
FSM pending length: 0
Snapshot:
Last index: 0
Last term: 0
Protocol:
Version: 3
Min version: 0
Max version: 0
Min snapshot version: 1
Max snapshot version: 0
Peers:
ID: pyroscope-metastore-1.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
Address: pyroscope-metastore-1.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
Suffrage: Voter
ID: pyroscope-metastore-2.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
Address: pyroscope-metastore-2.pyroscope-metastore-headless.pyroscope-test.svc.cluster.local.:9099
Suffrage: Voter
I have observed this change causes a noticeable increase in latency of the command. I'm not sure if that's an artifact of my local setup or a more systemic one. Probably nothing to worry about now though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The State verified
field will be true if the state reported by the node matches the state the cluster thinks the node is. I.e. if the node thinks it's a leader and the cluster agrees, then it is set to true
. If the node thinks it's not a leader, and the cluster agress, then it is set to true
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the latency increase is expected as the call should result in network requests between peers but I am not sure what is the expected order of magnitude for this latency. Probably fine for a command line tool for now.
closes https://github.com/grafana/pyroscope-squad/issues/230
Adds a CLI command (and corresponding API) to fetch info about a raft node. The command provides a variety of information regarding the node's role, log state, peers, election state, and leader. It has two output modes, the default mode is to provide the data in JSON format, which is a direct copy from what the underlying API returns. The other mode (
-H
) prints the information in a slightly more tabular, human-readable format.Sample output:
Sample output with
-H
: