From 2017f6aaa7232dc9d9fdb735b5de35066eb2da40 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 18 Jul 2016 13:38:44 -0400 Subject: [PATCH] Add metrics around leadership This can be helpful for detecting flapping. Fixes #1544 --- vault/core.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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)