Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log warnings when too many leases are active #3957

Merged
merged 4 commits into from
Feb 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this to be initialized?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but doesn't hurt, going to merge!

}

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