code: 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:
  			m.mu.Lock()
  			if m.stopped {
  				m.mu.Unlock()
  				return
  			}
  			newState := leadershipEvent.(raft.LeadershipState)
  
  			if newState == raft.IsLeader {
  				m.becomeLeader(ctx)
  				leaderMetric.Set(1)
  			} else if newState == raft.IsFollower {
  				m.becomeFollower()
  				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
  		}
  	}
  }
docs: // handleLeadershipEvents handles the is leader event or is follower event.