Add metrics around leadership

This can be helpful for detecting flapping.

Fixes #1544
This commit is contained in:
Jeff Mitchell 2016-07-18 13:38:44 -04:00
parent 328c63b01f
commit 2017f6aaa7

View File

@ -1061,10 +1061,15 @@ func (c *Core) runStandby(doneCh, stopCh, manualStepDownCh chan struct{}) {
}
c.logger.Printf("[INFO] core: acquired lock, enabling active operation")
// This is used later to log a metrics event; this can be helpful to
// detect flapping
activeTime := time.Now()
// Advertise ourself as leader
if err := c.advertiseLeader(uuid, leaderLostCh); err != nil {
c.logger.Printf("[ERR] core: leader advertisement setup failed: %v", err)
lock.Unlock()
metrics.MeasureSince([]string{"core", "leadership_setup_failed"}, activeTime)
continue
}
@ -1080,6 +1085,7 @@ func (c *Core) runStandby(doneCh, stopCh, manualStepDownCh chan struct{}) {
if err != nil {
c.logger.Printf("[ERR] core: post-unseal setup failed: %v", err)
lock.Unlock()
metrics.MeasureSince([]string{"core", "leadership_setup_failed"}, activeTime)
continue
}
@ -1095,6 +1101,8 @@ func (c *Core) runStandby(doneCh, stopCh, manualStepDownCh chan struct{}) {
manualStepDown = true
}
metrics.MeasureSince([]string{"core", "leadership_lost"}, activeTime)
// Clear ourself as leader
if err := c.clearLeader(uuid); err != nil {
c.logger.Printf("[ERR] core: clearing leader advertisement failed: %v", err)