Skip to content

Commit

Permalink
Merge pull request hashicorp#71 from hashicorp/f-metrics
Browse files Browse the repository at this point in the history
Adding more metrics for state transitions
  • Loading branch information
armon committed Nov 17, 2015
2 parents 1f23009 + e8e7f5c commit d136cd1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ func (r *Raft) run() {
func (r *Raft) runFollower() {
didWarn := false
r.logger.Printf("[INFO] raft: %v entering Follower state", r)
metrics.IncrCounter([]string{"raft", "state", "follower"}, 1)
heartbeatTimer := randomTimeout(r.conf.HeartbeatTimeout)
for {
select {
Expand Down Expand Up @@ -646,6 +647,8 @@ func (r *Raft) runFollower() {
}
} else {
r.logger.Printf("[WARN] raft: Heartbeat timeout reached, starting election")

metrics.IncrCounter([]string{"raft", "transition", "heartbeat_timout"}, 1)
r.setState(Candidate)
return
}
Expand All @@ -659,6 +662,7 @@ func (r *Raft) runFollower() {
// runCandidate runs the FSM for a candidate.
func (r *Raft) runCandidate() {
r.logger.Printf("[INFO] raft: %v entering Candidate state", r)
metrics.IncrCounter([]string{"raft", "state", "candidate"}, 1)

// Start vote for us, and set a timeout
voteCh := r.electSelf()
Expand Down Expand Up @@ -729,6 +733,7 @@ func (r *Raft) runCandidate() {
// the leaderLoop for the hot loop.
func (r *Raft) runLeader() {
r.logger.Printf("[INFO] raft: %v entering Leader state", r)
metrics.IncrCounter([]string{"raft", "state", "leader"}, 1)

// Notify that we are the leader
asyncNotifyBool(r.leaderCh, true)
Expand Down Expand Up @@ -1010,6 +1015,7 @@ func (r *Raft) checkLeaderLease() time.Duration {
if contacted < quorum {
r.logger.Printf("[WARN] raft: Failed to contact quorum of nodes, stepping down")
r.setState(Follower)
metrics.IncrCounter([]string{"raft", "transition", "leader_lease_timeout"}, 1)
}
return maxDiff
}
Expand Down

0 comments on commit d136cd1

Please sign in to comment.