diff --git a/vault/core.go b/vault/core.go index 9dcc2fcf31..55aa63ba0c 100644 --- a/vault/core.go +++ b/vault/core.go @@ -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)