Include IDs with events, ignore blank votes

This commit is contained in:
Ian Gulliver
2023-06-18 08:18:33 -07:00
parent e45d1931cf
commit 8318e90401
2 changed files with 12 additions and 1 deletions

View File

@@ -250,9 +250,18 @@ func (c *Candidate) elect(ctx context.Context, ec *event.Client, v *vote) {
continue
}
if vote.LastSeenCandidateID != c.resp.CandidateID {
if vote.LastSeenCandidateID != "" && vote.LastSeenCandidateID != c.resp.CandidateID {
// Hard no; voted for someone else
no++
if c.state == StateLeader {
c.log(ctx, ec,
"event", "noVoteWhileLeader",
"voterID", vote.VoterID,
"otherCandidateID", vote.LastSeenCandidateID,
"numPollsSincechange", vote.NumPollsSinceChange,
)
}
}
if vote.NumPollsSinceChange < 10 {
@@ -316,6 +325,7 @@ func (c *Candidate) log(ctx context.Context, ec *event.Client, vals ...any) {
ec.Log(ctx, append([]any{
"library", "elect",
"subsystem", "candidate",
"candidateID", c.resp.CandidateID,
}, vals...)...)
}

View File

@@ -198,5 +198,6 @@ func (v *Voter) log(ctx context.Context, ec *event.Client, vals ...any) {
ec.Log(ctx, append([]any{
"library", "elect",
"subsystem", "voter",
"voterID", v.vote.VoterID,
}, vals...)...)
}