Skip to content

feat(cluster): add Agent.Leader() accessor#160

Merged
wind-c merged 1 commit into
wind-c:mainfrom
debsahu:feat/agent-leader-accessor
May 13, 2026
Merged

feat(cluster): add Agent.Leader() accessor#160
wind-c merged 1 commit into
wind-c:mainfrom
debsahu:feat/agent-leader-accessor

Conversation

@debsahu
Copy link
Copy Markdown
Contributor

@debsahu debsahu commented May 13, 2026

Summary

Adds a small read-only accessor to *cluster.Agent:

func (a *Agent) Leader() string {
    _, id := a.raftPeer.GetLeader()
    return id
}

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(), but raftPeer is unexported, so there is no in-tree way for callers outside the cluster package 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

  • 12 lines (4 of code, 8 of doc comment).
  • No behavior change inside the cluster runtime.
  • No new dependencies.
  • Public API addition only. No rename or break.
  • Returns "" when no leader is elected (mid-election, pre-bootstrap), which is the sentinel raftPeer.GetLeader() already returns in those cases.

Context

Needed by the debsahu/comqtt-dashboard add-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.

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.
@wind-c wind-c merged commit 9785339 into wind-c:main May 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants