mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-30 19:11:09 +02:00
Add metrics around leadership
This can be helpful for detecting flapping. Fixes #1544
This commit is contained in:
parent
328c63b01f
commit
2017f6aaa7
@ -1061,10 +1061,15 @@ func (c *Core) runStandby(doneCh, stopCh, manualStepDownCh chan struct{}) {
|
|||||||
}
|
}
|
||||||
c.logger.Printf("[INFO] core: acquired lock, enabling active operation")
|
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
|
// Advertise ourself as leader
|
||||||
if err := c.advertiseLeader(uuid, leaderLostCh); err != nil {
|
if err := c.advertiseLeader(uuid, leaderLostCh); err != nil {
|
||||||
c.logger.Printf("[ERR] core: leader advertisement setup failed: %v", err)
|
c.logger.Printf("[ERR] core: leader advertisement setup failed: %v", err)
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
|
metrics.MeasureSince([]string{"core", "leadership_setup_failed"}, activeTime)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1080,6 +1085,7 @@ func (c *Core) runStandby(doneCh, stopCh, manualStepDownCh chan struct{}) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Printf("[ERR] core: post-unseal setup failed: %v", err)
|
c.logger.Printf("[ERR] core: post-unseal setup failed: %v", err)
|
||||||
lock.Unlock()
|
lock.Unlock()
|
||||||
|
metrics.MeasureSince([]string{"core", "leadership_setup_failed"}, activeTime)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1095,6 +1101,8 @@ func (c *Core) runStandby(doneCh, stopCh, manualStepDownCh chan struct{}) {
|
|||||||
manualStepDown = true
|
manualStepDown = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metrics.MeasureSince([]string{"core", "leadership_lost"}, activeTime)
|
||||||
|
|
||||||
// Clear ourself as leader
|
// Clear ourself as leader
|
||||||
if err := c.clearLeader(uuid); err != nil {
|
if err := c.clearLeader(uuid); err != nil {
|
||||||
c.logger.Printf("[ERR] core: clearing leader advertisement failed: %v", err)
|
c.logger.Printf("[ERR] core: clearing leader advertisement failed: %v", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user