-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 3 commits
dd89c47
0b56bda
aa948a2
a7daba1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 { | ||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!