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 3 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
24 changes: 20 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,17 @@ 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 maximum lease threshold")
Copy link
Member

Choose a reason for hiding this comment

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

I think "...exceeds warning lease threshold" is nicer or people might think that they have hit a hard max and might hit issues immediately.

atomic.StoreUint32(&m.leaseCheckCounter, 0)
} else {
atomic.AddUint32(&m.leaseCheckCounter, 1)
}
} else {
atomic.StoreUint32(&m.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.

This else clause is not necessary.

Copy link
Contributor Author

@gobins gobins Feb 14, 2018

Choose a reason for hiding this comment

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

There was an edge case where the counter will not get reset if the value was flapping over the threshold. But, thinking about it now, it is insignificant to warrant the else loop running all the time. I will remove it.

Copy link
Member

Choose a reason for hiding this comment

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

It won't get reset, but I think that's totally fine. It won't display more often than once every 60 seconds, it just may display less if it's flapping.

}
}

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