-
Notifications
You must be signed in to change notification settings - Fork 656
Log leadership changes at manager level #2542
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -875,8 +875,39 @@ func (m *Manager) rotateRootCAKEK(ctx context.Context, clusterID string) error { | |
| }) | ||
| } | ||
|
|
||
| // getLeaderNodeID is a small helper function returning a string with the | ||
| // leader's node ID. it is only used for logging, and should not be relied on | ||
| // to give a node ID for actual operational purposes (because it returns errors | ||
| // as nicely decorated strings) | ||
| func (m *Manager) getLeaderNodeID() string { | ||
| // get the current leader ID. this variable tracks the leader *only* for | ||
| // the purposes of logging leadership changes, and should not be relied on | ||
| // for other purposes | ||
| leader, leaderErr := m.raftNode.Leader() | ||
| switch leaderErr { | ||
| case raft.ErrNoRaftMember: | ||
| // this is an unlikely case, but we have to handle it. this means this | ||
| // node is not a member of the raft quorum. this won't look very pretty | ||
| // in logs ("leadership changed from aslkdjfa to ErrNoRaftMember") but | ||
| // it also won't be very common | ||
| return "not yet part of a raft cluster" | ||
| case raft.ErrNoClusterLeader: | ||
| return "no cluster leader" | ||
| default: | ||
| id, err := m.raftNode.GetNodeIDByRaftID(leader) | ||
| // the only possible error here is "ErrMemberUnknown" | ||
| if err != nil { | ||
| return "an unknown node" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not very useful in the logs either. Any way to make this somewhat less confusing ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably not. it's an unlikely case that this happens, and if it does happen, you'll need to look at the logs output by the raft library.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me clarify: my suggestion is to find out what is the scenario when we can get a ErrMemberUnknown and try to return a string that explains that scenario. @dperny |
||
| } | ||
| return id | ||
| } | ||
| } | ||
|
|
||
| // handleLeadershipEvents handles the is leader event or is follower event. | ||
| func (m *Manager) handleLeadershipEvents(ctx context.Context, leadershipCh chan events.Event) { | ||
| // get the current leader and save it for logging leadership changes in | ||
| // this loop | ||
| oldLeader := m.getLeaderNodeID() | ||
| for { | ||
| select { | ||
| case leadershipEvent := <-leadershipCh: | ||
|
|
@@ -895,6 +926,12 @@ func (m *Manager) handleLeadershipEvents(ctx context.Context, leadershipCh chan | |
| leaderMetric.Set(0) | ||
| } | ||
| m.mu.Unlock() | ||
|
|
||
| newLeader := m.getLeaderNodeID() | ||
| // maybe we should use logrus fields for old and new leader, so | ||
| // that users are better able to ingest leadership changes into log | ||
| // aggregators? | ||
| log.G(ctx).Infof("leadership changed from %v to %v", oldLeader, newLeader) | ||
| case <-ctx.Done(): | ||
| return | ||
| } | ||
|
|
||
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.
Change to err != ErrMemberUnknown ?
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.
not worth fixing.
Uh oh!
There was an error while loading. Please reload this page.
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.
care to elaborate ? @dperny