feat(cluster): add Agent.Leader() accessor#160
Merged
Conversation
External monitoring tools and the dashboard's cluster topology view need to know which node currently holds the Raft leadership. raftPeer.GetLeader() exists but raftPeer is unexported, so the only way to read leader state today is to reach into unexported fields. Adds a trivial wrapper that returns the leader node id, or "" when no leader is elected. No behavior change inside the cluster runtime; this is a read-only accessor over state the package already tracks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a small read-only accessor to
*cluster.Agent:Rationale
External monitoring tools and observability dashboards need to render which cluster node currently holds the Raft leadership. The information is already tracked by
a.raftPeer.GetLeader(), butraftPeeris unexported, so there is no in-tree way for callers outside theclusterpackage to read leader state without unsafe access to unexported fields.The accessor follows the same pattern as the
Server.Hooks()accessor merged in #158: a small wrapper that exposes existing state to observers, with no behavior change inside the package.Scope
""when no leader is elected (mid-election, pre-bootstrap), which is the sentinelraftPeer.GetLeader()already returns in those cases.Context
Needed by the
debsahu/comqtt-dashboardadd-on, which renders cluster topology and a leader badge on its Cluster page. The add-on was split out of #151 per maintainer feedback that the original PR was too large to evaluate; it now lives as a separate Go module so comqtt itself stays focused on the broker. This accessor is the only upstream change the dashboard's cluster-mode binary needs beyond #158.