[release-1.19] [controller] fix depth metrics (#3254)

* fix depth metric calculation by decrementing when we have something in the queue

* fix var name to reflect it's true purpose

---------

Co-authored-by: Dave Protasowski <dprotaso@gmail.com>
This commit is contained in:
Knative Prow Robot 2025-09-09 02:12:31 +01:00 committed by GitHub
parent 9aa11443ba
commit 077dcf0d00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -88,13 +88,15 @@ func (m *queueMetrics) get(item any) {
m.mu.Lock()
defer m.mu.Unlock()
m.depth.Dec()
m.processingStartTimes[item] = m.clock.Now()
if startTime, exists := m.addTimes[item]; exists {
m.depth.Dec()
m.latency.Observe(m.sinceInSeconds(startTime))
delete(m.addTimes, item)
}
if _, exists := m.processingStartTimes[item]; !exists {
m.processingStartTimes[item] = m.clock.Now()
}
}
func (m *queueMetrics) done(item any) {

View File

@ -223,9 +223,9 @@ func (q *twoLaneRateLimitingQueue) slowLane() workqueue.TypedInterface[any] {
// It gets the item from fast lane if it has anything, alternatively
// the slow lane.
func (tlq *twoLaneQueue) Get() (any, bool) {
item, ok := tlq.consumerQueue.Get()
item, shutdown := tlq.consumerQueue.Get()
tlq.metrics.get(item)
return item, ok
return item, shutdown
}
// Len returns the sum of lengths.