Skip to content

Commit

Permalink
Enable metrics only behind a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ra-grover committed Jul 20, 2023
1 parent aeb7e34 commit d4f2ca7
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions pkg/queue/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package queue

import (
"istio.io/istio/pilot/pkg/features"
"sync"
"time"

Expand Down Expand Up @@ -52,9 +53,10 @@ type queueImpl struct {
closed chan struct{}
closeOnce *sync.Once
// initialSync indicates the queue has initially "synced".
initialSync *atomic.Bool
id string
metrics *queueMetrics
initialSync *atomic.Bool
id string
metrics *queueMetrics
enableMetrics bool
}

// NewQueue instantiates a queue with a processing function
Expand All @@ -64,15 +66,16 @@ func NewQueue(errorDelay time.Duration) Instance {

func NewQueueWithID(errorDelay time.Duration, name string) Instance {
return &queueImpl{
delay: errorDelay,
tasks: make([]*Task, 0),
closing: false,
closed: make(chan struct{}),
closeOnce: &sync.Once{},
initialSync: atomic.NewBool(false),
cond: sync.NewCond(&sync.Mutex{}),
id: name,
metrics: NewQueueMetrics(name),
delay: errorDelay,
tasks: make([]*Task, 0),
closing: false,
closed: make(chan struct{}),
closeOnce: &sync.Once{},
initialSync: atomic.NewBool(false),
cond: sync.NewCond(&sync.Mutex{}),
id: name,
metrics: NewQueueMetrics(name),
enableMetrics: features.EnableControllerQueueMetrics.Get(),
}
}

Expand All @@ -81,7 +84,10 @@ func (q *queueImpl) Push(item Task) {
defer q.cond.L.Unlock()
if !q.closing {
q.tasks = append(q.tasks, &item)
q.metrics.add(&item)
if q.enableMetrics == true {
q.metrics.add(&item)
}

}
q.cond.Signal()
}
Expand All @@ -108,7 +114,10 @@ func (q *queueImpl) get() (task *Task, shutdown bool) {
// Slicing will not free the underlying elements of the array, so explicitly clear them out here
q.tasks[0] = nil
q.tasks = q.tasks[1:]
q.metrics.get(task)
if q.enableMetrics {
q.metrics.get(task)
}

return task, false
}

Expand All @@ -128,7 +137,10 @@ func (q *queueImpl) processNextItem() bool {
q.Push(callback)
})
}
q.metrics.done(task)
if q.enableMetrics {
q.metrics.done(task)
}

return true
}

Expand Down

0 comments on commit d4f2ca7

Please sign in to comment.