Skip to content

Commit

Permalink
Log warnings when too many leases are active (#3957)
Browse files Browse the repository at this point in the history
  • Loading branch information
gobins authored and jefferai committed Feb 14, 2018
1 parent 4ae1310 commit 632a5f3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions vault/expiration.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (

// defaultLeaseDuration is the default lease duration used when no lease is specified
defaultLeaseTTL = maxLeaseTTL

//maxLeaseThreshold is the maximum lease count before generating log warning
maxLeaseThreshold = 256000
)

// ExpirationManager is used by the Core to manage leases. Secrets
Expand All @@ -70,8 +73,9 @@ type ExpirationManager struct {
restoreLoaded sync.Map
quitCh chan struct{}

coreStateLock *sync.RWMutex
quitContext context.Context
coreStateLock *sync.RWMutex
quitContext context.Context
leaseCheckCounter uint32
}

// NewExpirationManager creates a new ExpirationManager that is backed
Expand All @@ -91,8 +95,9 @@ func NewExpirationManager(c *Core, view *BarrierView) *ExpirationManager {
restoreLocks: locksutil.CreateLocks(),
quitCh: make(chan struct{}),

coreStateLock: &c.stateLock,
quitContext: c.activeContext,
coreStateLock: &c.stateLock,
quitContext: c.activeContext,
leaseCheckCounter: 0,
}

if exp.logger == nil {
Expand Down Expand Up @@ -1269,6 +1274,15 @@ func (m *ExpirationManager) emitMetrics() {
num := len(m.pending)
m.pendingLock.RUnlock()
metrics.SetGauge([]string{"expire", "num_leases"}, float32(num))
// Check if lease count is greater than the threshold
if num > maxLeaseThreshold {
if atomic.LoadUint32(&m.leaseCheckCounter) > 59 {
m.logger.Warn("expiration: lease count exceeds warning lease threshold")
atomic.StoreUint32(&m.leaseCheckCounter, 0)
} else {
atomic.AddUint32(&m.leaseCheckCounter, 1)
}
}
}

// leaseEntry is used to structure the values the expiration
Expand Down

0 comments on commit 632a5f3

Please sign in to comment.